Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.pgm.init.index; 16 : 17 : import com.google.gerrit.extensions.events.LifecycleListener; 18 : import com.google.gerrit.index.IndexDefinition; 19 : import com.google.inject.Inject; 20 : import com.google.inject.name.Named; 21 : import java.util.Collection; 22 : 23 : /** 24 : * This class starts/stops the indexes from the init program so that init can write updates the 25 : * indexes. 26 : */ 27 : public class IndexManagerOnInit { 28 : private final LifecycleListener indexManager; 29 : private final Collection<IndexDefinition<?, ?, ?>> defs; 30 : 31 : @Inject 32 : IndexManagerOnInit( 33 : @Named(IndexModuleOnInit.INDEX_MANAGER) LifecycleListener indexManager, 34 15 : Collection<IndexDefinition<?, ?, ?>> defs) { 35 15 : this.indexManager = indexManager; 36 15 : this.defs = defs; 37 15 : } 38 : 39 : public void start() { 40 15 : indexManager.start(); 41 : 42 15 : for (IndexDefinition<?, ?, ?> def : defs) { 43 15 : def.getIndexCollection().start(); 44 15 : } 45 15 : } 46 : 47 : public void stop() { 48 15 : indexManager.stop(); 49 : 50 15 : for (IndexDefinition<?, ?, ?> def : defs) { 51 15 : def.getIndexCollection().stop(); 52 15 : } 53 15 : } 54 : }