Use Provider to obtain LifecycleListeners

Instead of holding onto a singleton for a LifecycleListener, allow the
listener to be created on demand using a Provider.

Use explicit support of the HandlerRegistration type, enabling these
to always be cleared before any LifecycleListener is stopped. This way
registrations from plugins can always be cleared even if the list of
listeners to start didn't finish running to the end.

During stop only run those listeners that attempted to start. We
assume a listener is prepared to run its stop method as soon as its
start method begins execution. This means a start method that can fail
must use guards in its stop method to handle stopping after a partial
start failure.

Change-Id: I86ae39a51e3b7fad5c5af445bf7c70133222c31a
This commit is contained in:
Shawn O. Pearce
2012-05-16 09:51:45 -07:00
parent dc5ef8f266
commit e051cb8fd6
2 changed files with 48 additions and 49 deletions

View File

@@ -20,7 +20,6 @@ import com.google.gerrit.extensions.annotations.PluginData;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.extensions.registration.ReloadableRegistrationHandle;
import com.google.gerrit.lifecycle.LifecycleListener;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
@@ -233,28 +232,14 @@ public class Plugin {
return httpInjector;
}
public void add(final RegistrationHandle handle) {
public void add(RegistrationHandle handle) {
if (handle instanceof ReloadableRegistrationHandle) {
if (reloadableHandles == null) {
reloadableHandles = Lists.newArrayList();
}
reloadableHandles.add((ReloadableRegistrationHandle<?>) handle);
}
add(new LifecycleListener() {
@Override
public void start() {
}
@Override
public void stop() {
handle.remove();
}
});
}
public void add(LifecycleListener listener) {
manager.add(listener);
manager.add(handle);
}
List<ReloadableRegistrationHandle<?>> getReloadableHandles() {