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.server; 16 : 17 : import com.google.gerrit.extensions.events.LifecycleListener; 18 : import com.google.gerrit.extensions.registration.DynamicSet; 19 : import com.google.gerrit.lifecycle.LifecycleModule; 20 : import com.google.gerrit.server.account.UniversalGroupBackend; 21 : import com.google.gerrit.server.group.SystemGroupBackend; 22 : import com.google.gerrit.server.plugincontext.PluginSetContext; 23 : import com.google.inject.Inject; 24 : import com.google.inject.Singleton; 25 : 26 : @Singleton 27 : public class StartupChecks implements LifecycleListener { 28 138 : public static class StartupChecksModule extends LifecycleModule { 29 : @Override 30 : protected void configure() { 31 138 : DynamicSet.setOf(binder(), StartupCheck.class); 32 138 : listener().to(StartupChecks.class); 33 138 : DynamicSet.bind(binder(), StartupCheck.class).to(UniversalGroupBackend.ConfigCheck.class); 34 138 : DynamicSet.bind(binder(), StartupCheck.class).to(SystemGroupBackend.NameCheck.class); 35 138 : } 36 : } 37 : 38 : private final PluginSetContext<StartupCheck> startupChecks; 39 : 40 : @Inject 41 138 : StartupChecks(PluginSetContext<StartupCheck> startupChecks) { 42 138 : this.startupChecks = startupChecks; 43 138 : } 44 : 45 : @Override 46 : public void start() throws StartupException { 47 138 : startupChecks.runEach(StartupCheck::check, StartupException.class); 48 138 : } 49 : 50 : @Override 51 138 : public void stop() {} 52 : }