modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java | 17 ++++++---- 1 file changed, 11 insertions(+), 6 deletions(-)
New commits: commit 3850db08f742740deb9cf6a2c1ef18315a5cfcf3 Author: John Sanda jsanda@redhat.com Date: Mon Feb 14 09:23:23 2011 -0500
[BZ 677349] Do not obtain PC read lock prematurely
EventContextImpl was previously obtaining a PluginContainer read lock prematurely so that it could obtain a reference to EventManager. I say it was premature because there is no need to obtain the reference to EventManager in the constructor. Its not needed until the different instance methods are called and that is when the lock should be obtained.
With this change when a plugin component tries to register event pollers in thread T2, T2 will wind up blocking until the PC running in thread T1 has finished initializing and the PC in T1 releases its write lock.
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 dcafd66..943ed40 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 @@ -39,11 +39,16 @@ import java.util.Set; */ public class EventContextImpl implements EventContext { private Resource resource; - private EventManager eventManager;
public EventContextImpl(@NotNull Resource resource) { this.resource = resource; - this.eventManager = PluginContainer.getInstance().getEventManager(); + } + + // A reference to EventManager was previously stored in a member variable named eventManager. That should *not* + // be done because of possible concurrency issues. See https://bugzilla.redhat.com/show_bug.cgi?id=677349 for + // details. + private EventManager getEventManager() { + return PluginContainer.getInstance().getEventManager(); }
public void publishEvent(@NotNull Event event) { @@ -55,7 +60,7 @@ public class EventContextImpl implements EventContext { throw new IllegalArgumentException("Event has unknown event type - no EventDefinition exists with name '" + event.getType() + "'."); Set<Event> events = new HashSet<Event>(); events.add(event); - this.eventManager.publishEvents(events, this.resource); + getEventManager().publishEvents(events, this.resource); }
public void registerEventPoller(@NotNull EventPoller poller, int pollingInterval) { @@ -96,7 +101,7 @@ public class EventContextImpl implements EventContext {
@NotNull public SigarProxy getSigar() { - return this.eventManager.getSigar(); + return getEventManager().getSigar(); }
private void registerEventPollerInternal(EventPoller poller, int pollingInterval, String sourceLocation) { @@ -104,13 +109,13 @@ public class EventContextImpl implements EventContext { if (eventDefinition == null) throw new IllegalArgumentException("Poller has unknown event type - no EventDefinition exists with name '" + poller.getEventType() + "'."); int adjustedPollingInterval = Math.max(EventContext.MINIMUM_POLLING_INTERVAL, pollingInterval); - this.eventManager.registerEventPoller(poller, adjustedPollingInterval, this.resource, sourceLocation); + getEventManager().registerEventPoller(poller, adjustedPollingInterval, this.resource, sourceLocation); }
private void unregisterEventPollerInternal(String eventType, String sourceLocation) { EventDefinition eventDefinition = EventUtility.getEventDefinition(eventType, this.resource.getResourceType()); if (eventDefinition == null) throw new IllegalArgumentException("Unknown event type - no EventDefinition exists with name '" + eventType + "'."); - this.eventManager.unregisterEventPoller(this.resource, eventType, sourceLocation); + getEventManager().unregisterEventPoller(this.resource, eventType, sourceLocation); } }
rhq-commits@lists.fedorahosted.org