gt:                     stats.indexing = new IndexingStats();
context: /*
   * Licensed to ElasticSearch and Shay Banon under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership. ElasticSearch licenses this
   * file to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  package org.elasticsearch.indices;
  
  import com.google.common.collect.ImmutableMap;
  import com.google.common.collect.ImmutableSet;
  import com.google.common.collect.UnmodifiableIterator;
  import org.elasticsearch.ElasticSearchException;
  import org.elasticsearch.ElasticSearchIllegalStateException;
  import org.elasticsearch.action.admin.indices.stats.CommonStats;
  import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
  import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag;
  import org.elasticsearch.common.Nullable;
  import org.elasticsearch.common.component.AbstractLifecycleComponent;
  import org.elasticsearch.common.inject.*;
  import org.elasticsearch.common.settings.Settings;
  import org.elasticsearch.common.util.concurrent.EsExecutors;
  import org.elasticsearch.gateway.Gateway;
  import org.elasticsearch.index.*;
  import org.elasticsearch.index.aliases.IndexAliasesServiceModule;
  import org.elasticsearch.index.analysis.AnalysisModule;
  import org.elasticsearch.index.analysis.AnalysisService;
  import org.elasticsearch.index.cache.IndexCache;
  import org.elasticsearch.index.cache.IndexCacheModule;
  import org.elasticsearch.index.cache.filter.FilterCacheStats;
  import org.elasticsearch.index.cache.id.IdCacheStats;
  import org.elasticsearch.index.codec.CodecModule;
  import org.elasticsearch.index.engine.IndexEngine;
  import org.elasticsearch.index.engine.IndexEngineModule;
  import org.elasticsearch.index.fielddata.FieldDataStats;
  import org.elasticsearch.index.fielddata.IndexFieldDataModule;
  import org.elasticsearch.index.fielddata.IndexFieldDataService;
  import org.elasticsearch.index.flush.FlushStats;
  import org.elasticsearch.index.gateway.IndexGateway;
  import org.elasticsearch.index.gateway.IndexGatewayModule;
  import org.elasticsearch.index.get.GetStats;
  import org.elasticsearch.index.indexing.IndexingStats;
  import org.elasticsearch.index.mapper.MapperService;
  import org.elasticsearch.index.mapper.MapperServiceModule;
  import org.elasticsearch.index.merge.MergeStats;
  import org.elasticsearch.index.percolator.stats.PercolateStats;
  import org.elasticsearch.index.query.IndexQueryParserModule;
  import org.elasticsearch.index.query.IndexQueryParserService;
  import org.elasticsearch.index.refresh.RefreshStats;
  import org.elasticsearch.index.search.stats.SearchStats;
  import org.elasticsearch.index.service.IndexService;
  import org.elasticsearch.index.service.InternalIndexService;
  import org.elasticsearch.index.settings.IndexSettingsModule;
  import org.elasticsearch.index.shard.DocsStats;
  import org.elasticsearch.index.shard.ShardId;
  import org.elasticsearch.index.shard.service.IndexShard;
  import org.elasticsearch.index.similarity.SimilarityModule;
  import org.elasticsearch.index.store.IndexStore;
  import org.elasticsearch.index.store.IndexStoreModule;
  import org.elasticsearch.index.store.StoreStats;
  import org.elasticsearch.index.warmer.WarmerStats;
  import org.elasticsearch.indices.analysis.IndicesAnalysisService;
  import org.elasticsearch.indices.recovery.RecoverySettings;
  import org.elasticsearch.indices.store.IndicesStore;
  import org.elasticsearch.plugins.IndexPluginsModule;
  import org.elasticsearch.plugins.PluginsService;
  import org.elasticsearch.search.suggest.completion.CompletionStats;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  import java.util.concurrent.CountDownLatch;
  import java.util.concurrent.Executor;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  
  import static com.google.common.collect.Maps.newHashMap;
  import static com.google.common.collect.Sets.newHashSet;
  import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
  import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
  import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
  import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
  
  /**
   *
   */
  public class InternalIndicesService extends AbstractLifecycleComponent<IndicesService> implements IndicesService {
  
      private final InternalIndicesLifecycle indicesLifecycle;
  
      private final IndicesAnalysisService indicesAnalysisService;
  
      private final IndicesStore indicesStore;
  
      private final Injector injector;
  
      private final PluginsService pluginsService;
  
      private final Map<String, Injector> indicesInjectors = new HashMap<String, Injector>();
  
      private volatile ImmutableMap<String, IndexService> indices = ImmutableMap.of();
  
      private final OldShardsStats oldShardsStats = new OldShardsStats();
  
      @Inject
      public InternalIndicesService(Settings settings, IndicesLifecycle indicesLifecycle, IndicesAnalysisService indicesAnalysisService, IndicesStore indicesStore, Injector injector) {
          super(settings);
          this.indicesLifecycle = (InternalIndicesLifecycle) indicesLifecycle;
          this.indicesAnalysisService = indicesAnalysisService;
          this.indicesStore = indicesStore;
          this.injector = injector;
  
          this.pluginsService = injector.getInstance(PluginsService.class);
  
          this.indicesLifecycle.addListener(oldShardsStats);
      }
  
      @Override
      protected void doStart() throws ElasticSearchException {
      }
  
      @Override
      protected void doStop() throws ElasticSearchException {
          ImmutableSet<String> indices = ImmutableSet.copyOf(this.indices.keySet());
          final CountDownLatch latch = new CountDownLatch(indices.size());
  
          final ExecutorService indicesStopExecutor = Executors.newFixedThreadPool(5, EsExecutors.daemonThreadFactory("indices_shutdown"));
          final ExecutorService shardsStopExecutor = Executors.newFixedThreadPool(5, EsExecutors.daemonThreadFactory("shards_shutdown"));
  
          for (final String index : indices) {
              indicesStopExecutor.execute(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          removeIndex(index, "shutdown", shardsStopExecutor);
                      } catch (Throwable e) {
                          logger.warn("failed to delete index on stop [" + index + "]", e);
                      } finally {
                          latch.countDown();
                      }
                  }
              });
          }
          try {
              latch.await();
          } catch (InterruptedException e) {
              // ignore
          } finally {
              shardsStopExecutor.shutdown();
              indicesStopExecutor.shutdown();
          }
      }
  
      @Override
      protected void doClose() throws ElasticSearchException {
          injector.getInstance(RecoverySettings.class).close();
          indicesStore.close();
          indicesAnalysisService.close();
      }
  
      @Override
      public IndicesLifecycle indicesLifecycle() {
          return this.indicesLifecycle;
      }
  
      @Override
      public NodeIndicesStats stats(boolean includePrevious) {
          return stats(true, new CommonStatsFlags().all());
      }
  
      @Override
      public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) {
          CommonStats stats = new CommonStats();
          Flag[] setFlags = flags.getFlags();
          for (Flag flag : setFlags) {
              switch (flag) {
                  case Docs:
                      stats.docs = new DocsStats();
                      break;
                  case Store:
                      stats.store = new StoreStats();
                      break;
                  case Warmer:
                      stats.warmer = new WarmerStats();
                      break;
                  case Get:
                      stats.get = new GetStats();
                      if (includePrevious) {
                          stats.get.add(oldShardsStats.getStats);
                      }
                      break;
                  case Indexing:
  