Add listener for unloading of plugins

Change-Id: Ib5d65f15c6bda9ec3bee8f43dd20a7e9f40f5013
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2014-05-26 10:49:48 +02:00
parent c646a8c5ed
commit dd52c72af9
3 changed files with 36 additions and 0 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}