Line data Source code
1 : // Copyright (C) 2018 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.server.config; 16 : 17 : import com.google.common.collect.ArrayListMultimap; 18 : import com.google.common.collect.Multimap; 19 : import com.google.common.flogger.FluentLogger; 20 : import com.google.gerrit.server.config.ConfigUpdatedEvent.ConfigUpdateEntry; 21 : import com.google.gerrit.server.config.ConfigUpdatedEvent.UpdateResult; 22 : import com.google.gerrit.server.plugincontext.PluginSetContext; 23 : import com.google.inject.Inject; 24 : import com.google.inject.Singleton; 25 : 26 : /** Issues a configuration reload from the GerritServerConfigProvider and notify all listeners. */ 27 : @Singleton 28 : public class GerritServerConfigReloader { 29 138 : private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 30 : 31 : private final GerritServerConfigProvider configProvider; 32 : private final PluginSetContext<GerritConfigListener> configListeners; 33 : 34 : @Inject 35 : GerritServerConfigReloader( 36 : GerritServerConfigProvider configProvider, 37 138 : PluginSetContext<GerritConfigListener> configListeners) { 38 138 : this.configProvider = configProvider; 39 138 : this.configListeners = configListeners; 40 138 : } 41 : 42 : /** 43 : * Reloads the Gerrit Server Configuration from disk. Synchronized to ensure that one issued 44 : * reload is fully completed before a new one starts. 45 : */ 46 : public Multimap<UpdateResult, ConfigUpdateEntry> reloadConfig() { 47 1 : logger.atInfo().log("Starting server configuration reload"); 48 1 : Multimap<UpdateResult, ConfigUpdateEntry> updates = 49 1 : fireUpdatedConfigEvent(configProvider.updateConfig()); 50 1 : logger.atInfo().log("Server configuration reload completed succesfully"); 51 1 : return updates; 52 : } 53 : 54 : public Multimap<UpdateResult, ConfigUpdateEntry> fireUpdatedConfigEvent( 55 : ConfigUpdatedEvent event) { 56 1 : Multimap<UpdateResult, ConfigUpdateEntry> updates = ArrayListMultimap.create(); 57 1 : configListeners.runEach(l -> updates.putAll(l.configUpdated(event))); 58 1 : return updates; 59 : } 60 : }