From b16bd3f6e83152eace352a47e78424db8df4171e Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Fri, 27 Aug 2010 20:25:28 +0000 Subject: QPID-2788: synchronize the concurrently accessed arraylists. Return new instances of the lists to prevent extended synchronized iterations during view updates from delaying the notification threads git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@990253 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/management/ui/ServerRegistry.java | 47 +++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'java/management/eclipse-plugin/src') diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java index 027a555360..fc17538cf9 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java @@ -32,6 +32,8 @@ import org.apache.qpid.management.ui.model.ManagedAttributeModel; import org.apache.qpid.management.ui.model.NotificationObject; import org.apache.qpid.management.ui.model.OperationDataModel; +import java.util.Collections; + public abstract class ServerRegistry { private ManagedServer _managedServer = null; @@ -95,22 +97,34 @@ public abstract class ServerRegistry protected void addConnectionMBean(ManagedBean mbean) { String vHost = mbean.getVirtualHostName(); - _connections.putIfAbsent(vHost, new ArrayList()); - _connections.get(vHost).add(mbean); + List vhostConnections = getVhostSubList(vHost, _connections); + vhostConnections.add(mbean); } protected void addExchangeMBean(ManagedBean mbean) { String vHost = mbean.getVirtualHostName(); - _exchanges.putIfAbsent(vHost, new ArrayList()); - _exchanges.get(vHost).add(mbean); + List vhostExchanges = getVhostSubList(vHost, _exchanges); + vhostExchanges.add(mbean); } protected void addQueueMBean(ManagedBean mbean) { String vHost = mbean.getVirtualHostName(); - _queues.putIfAbsent(vHost, new ArrayList()); - _queues.get(vHost).add(mbean); + List vhostQueues = getVhostSubList(vHost, _queues); + vhostQueues.add(mbean); + } + + private List getVhostSubList(String vHost, ConcurrentMap> parentList) + { + //add an empty sublist for the vhost if required + if (!parentList.containsKey(vHost)) + { + List subList = Collections.synchronizedList(new ArrayList()); + parentList.putIfAbsent(vHost, subList); + } + + return parentList.get(vHost); } protected void addVirtualHostManagerMBean(ManagedBean mbean) @@ -146,17 +160,32 @@ public abstract class ServerRegistry public List getConnections(String virtualHost) { - return _connections.get(virtualHost); + return getVhostObjects(virtualHost, _connections); } public List getExchanges(String virtualHost) { - return _exchanges.get(virtualHost); + return getVhostObjects(virtualHost, _exchanges); } public List getQueues(String virtualHost) { - return _queues.get(virtualHost); + return getVhostObjects(virtualHost, _queues); + } + + public List getVhostObjects(String virtualHost, ConcurrentMap> parentList) + { + List objects = parentList.get(virtualHost); + + if(objects == null) + { + return new ArrayList(); + } + + synchronized (objects) + { + return new ArrayList(objects); + } } //returns the requested ManagedBean, or null if it cant be found -- cgit v1.2.1