@Subscribe
    @AllowConcurrentEvents
    public void handleIndexReopening(IndicesReopenedEvent event) {
        for (final String index : event.indices()) {
            if (!indexSetRegistry.isManagedIndex(index)) {
                LOG.debug("Not handling reopened index <{}> because it's not managed by any index set.", index);
                continue;
            }
            LOG.debug("Index \"{}\" has been reopened. Calculating index range.", index);

            checkIfHealthy(indices.waitForRecovery(index), (status) -> new RuntimeException("Not handling reopened index <" + index + ">, index is unhealthy: " + status));

            final IndexRange indexRange;
            try {
                indexRange = calculateRange(index);
                auditEventSender.success(AuditActor.system(nodeId), ES_INDEX_RANGE_CREATE, ImmutableMap.of("index_name", index));
            } catch (Exception e) {
                final String message = "Couldn't calculate index range for index \"" + index + "\"";
                LOG.error(message, e);
                auditEventSender.failure(AuditActor.system(nodeId), ES_INDEX_RANGE_CREATE, ImmutableMap.of("index_name", index));
                throw new RuntimeException(message, e);
            }

            save(indexRange);
        }
    }
@Test
    @MongoDBFixtures("MongoIndexRangeServiceTest.json")
    public void testHandleIndexReopening() throws Exception {
        final DateTime begin = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
        final DateTime end = new DateTime(2016, 1, 15, 0, 0, DateTimeZone.UTC);
        when(indices.indexRangeStatsOfIndex("graylog_3")).thenReturn(IndexRangeStats.create(begin, end));
        when(indexSetRegistry.isManagedIndex("graylog_3")).thenReturn(true);
        when(indices.waitForRecovery("graylog_3")).thenReturn(HealthStatus.Green);

        localEventBus.post(IndicesReopenedEvent.create(Collections.singleton("graylog_3")));

        final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
        assertThat(indexRanges).hasSize(1);
        assertThat(indexRanges.first().indexName()).isEqualTo("graylog_3");
        assertThat(indexRanges.first().begin()).isEqualTo(begin);
        assertThat(indexRanges.first().end()).isEqualTo(end);
    }