modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java | 20 ++++------ modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java | 13 +++--- 2 files changed, 15 insertions(+), 18 deletions(-)
New commits: commit e3aa1e003b6d61bb42c4e6d48222c3d5d11ab5b6 Merge: a87c72d 3843704 Author: John Sanda jsanda@redhat.com Date: Thu Sep 19 09:56:47 2013 -0400
Merge branch 'bug/1009666'
commit 3843704e61a48c6162dca42861fb0c44a70b3f47 Author: John Sanda jsanda@redhat.com Date: Wed Sep 18 20:37:47 2013 -0400
[BZ 1009666] Store plugin container init listeners in a list
The PC initialization listeners were introduced to work around a deadlock issue with registering event pollers. The listeners are stored in a map in which entries are keyed off of the class name. The only class that adds listeners is EventContextImpl. This results in only every having one event poller registered after PC initialization regardless of the number of event pollers. Storing the listeners in a list resolves the issue.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java index 4f6a9a1..d88ce53 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java @@ -24,10 +24,10 @@ package org.rhq.core.pc;
import java.beans.Introspector; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.LinkedHashSet; -import java.util.Map; +import java.util.List; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; @@ -146,8 +146,8 @@ public class PluginContainer { // this is to prevent race conditions on startup between components from all the different managers private ReadWriteLock rwLock = new ReentrantReadWriteLock();
- private Map<String, InitializationListener> initListeners = new HashMap<String, InitializationListener>(); - private Map<String, ShutdownListener> shutdownListeners = new HashMap<String, ShutdownListener>(); + private List<InitializationListener> initListeners = new ArrayList<InitializationListener>(); + private List<ShutdownListener> shutdownListeners = new ArrayList<ShutdownListener>(); private Object initListenersLock = new Object(); private Object shutdownListenersLock = new Object(); private boolean shuttingDown; @@ -344,7 +344,7 @@ public class PluginContainer {
synchronized (initListenersLock) { if (started) { - for (InitializationListener listener : initListeners.values()) { + for (InitializationListener listener : initListeners) { listener.initialized(); } } @@ -454,7 +454,7 @@ public class PluginContainer {
synchronized (shutdownListenersLock) { if (!started) { - for (ShutdownListener listener : shutdownListeners.values()) { + for (ShutdownListener listener : shutdownListeners) { listener.shutdown(); } } @@ -741,13 +741,12 @@ public class PluginContainer { * Add the callback listener to notify when the plugin container is initialized. If this method is invoked and * the PC is already initialized, then <code>listener</code> will be invoked immediately. * - * @param name associated with the listener * @param listener The callback object to notify. If a listener with the supplied name is registered, it * will be replaced with the newly supplied listner. */ - public void addInitializationListener(String name, InitializationListener listener) { + public void addInitializationListener(InitializationListener listener) { synchronized (initListenersLock) { - initListeners.put(name, listener); + initListeners.add(listener);
if (started) { listener.initialized(); @@ -760,13 +759,12 @@ public class PluginContainer { * {@link #addInitializationListener(String, InitializationListener)} the <code>listener</code> will * not be invoked immediately if the PC is already shutdown. It will only be invoked on future shutdowns. * - * @param name associated with the listener * @param listener The callback object to notify. If a listener with the supplied name is registered, it * will be replaced with the newly supplied listener. */ public void addShutdownListener(String name, ShutdownListener listener) { synchronized (shutdownListenersLock) { - shutdownListeners.put(name, listener); + shutdownListeners.add(listener); } }
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java index fd360cf..52f270b 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java @@ -124,13 +124,12 @@ public class EventContextImpl implements EventContext { final int adjustedPollingInterval = Math.max(EventContext.MINIMUM_POLLING_INTERVAL, pollingInterval); // Registering the event poller has to be done in a callback listener to avoid a potential deadlock. // See https://bugzilla.redhat.com/show_bug.cgi?id=677349 for a detailed explaination. - PluginContainer.getInstance().addInitializationListener(this.getClass().getName(), - new PluginContainer.InitializationListener() { - @Override - public void initialized() { - getEventManager().registerEventPoller(poller, adjustedPollingInterval, resource, sourceLocation); - } - }); + PluginContainer.getInstance().addInitializationListener(new PluginContainer.InitializationListener() { + @Override + public void initialized() { + getEventManager().registerEventPoller(poller, adjustedPollingInterval, resource, sourceLocation); + } + }); }
private void unregisterEventPollerInternal(String eventType, String sourceLocation) {
rhq-commits@lists.fedorahosted.org