Add listener for unloading of plugins
Change-Id: Ib5d65f15c6bda9ec3bee8f43dd20a7e9f40f5013 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -75,6 +75,7 @@ public class PluginGuiceEnvironment {
|
||||
private final CopyConfigModule copyConfigModule;
|
||||
private final Set<Key<?>> copyConfigKeys;
|
||||
private final List<StartPluginListener> onStart;
|
||||
private final List<StopPluginListener> onStop;
|
||||
private final List<ReloadPluginListener> onReload;
|
||||
|
||||
private Module sysModule;
|
||||
@@ -111,6 +112,9 @@ public class PluginGuiceEnvironment {
|
||||
onStart = new CopyOnWriteArrayList<>();
|
||||
onStart.addAll(listeners(sysInjector, StartPluginListener.class));
|
||||
|
||||
onStop = new CopyOnWriteArrayList<>();
|
||||
onStop.addAll(listeners(sysInjector, StopPluginListener.class));
|
||||
|
||||
onReload = new CopyOnWriteArrayList<>();
|
||||
onReload.addAll(listeners(sysInjector, ReloadPluginListener.class));
|
||||
|
||||
@@ -165,6 +169,7 @@ public class PluginGuiceEnvironment {
|
||||
sshSets = dynamicSetsOf(injector);
|
||||
sshMaps = dynamicMapsOf(injector);
|
||||
onStart.addAll(listeners(injector, StartPluginListener.class));
|
||||
onStop.addAll(listeners(injector, StopPluginListener.class));
|
||||
onReload.addAll(listeners(injector, ReloadPluginListener.class));
|
||||
}
|
||||
|
||||
@@ -187,6 +192,7 @@ public class PluginGuiceEnvironment {
|
||||
httpSets = dynamicSetsOf(injector);
|
||||
httpMaps = dynamicMapsOf(injector);
|
||||
onStart.addAll(listeners(injector, StartPluginListener.class));
|
||||
onStop.addAll(listeners(injector, StopPluginListener.class));
|
||||
onReload.addAll(listeners(injector, ReloadPluginListener.class));
|
||||
}
|
||||
|
||||
@@ -233,6 +239,12 @@ public class PluginGuiceEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
void onStopPlugin(Plugin plugin) {
|
||||
for (StopPluginListener l : onStop) {
|
||||
l.onStopPlugin(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private void attachItem(Map<TypeLiteral<?>, DynamicItem<?>> items,
|
||||
@Nullable Injector src,
|
||||
Plugin plugin) {
|
||||
@@ -545,6 +557,9 @@ public class PluginGuiceEnvironment {
|
||||
if (StartPluginListener.class.isAssignableFrom(type)) {
|
||||
return false;
|
||||
}
|
||||
if (StopPluginListener.class.isAssignableFrom(type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type.getName().startsWith("com.google.inject.")) {
|
||||
return false;
|
||||
|
||||
@@ -240,6 +240,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
String name = plugin.getName();
|
||||
log.info(String.format("Unloading plugin %s", name));
|
||||
plugin.stop(env);
|
||||
env.onStopPlugin(plugin);
|
||||
running.remove(name);
|
||||
disabled.remove(name);
|
||||
toCleanup.add(plugin);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed 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 com.google.gerrit.server.plugins;
|
||||
|
||||
/** Broadcasts event indicating a plugin was unloaded. */
|
||||
public interface StopPluginListener {
|
||||
public void onStopPlugin(Plugin plugin);
|
||||
}
|
||||
Reference in New Issue
Block a user