You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2011/11/25 10:14:08 UTC
svn commit: r1206086 - in
/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management:
JMXManagedObjectRegistry.java MBeanInvocationHandlerImpl.java
Author: kwall
Date: Fri Nov 25 09:14:07 2011
New Revision: 1206086
URL: http://svn.apache.org/viewvc?rev=1206086&view=rev
Log:
QPID-3474: Maintain connectionid/username Map from only JMXManagedObjectRegistry (Improved separation of concerns).
Modified:
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java?rev=1206086&r1=1206085&r2=1206086&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java Fri Nov 25 09:14:07 2011
@@ -44,6 +44,7 @@ import java.util.concurrent.ConcurrentHa
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
+import javax.management.Notification;
import javax.management.NotificationFilterSupport;
import javax.management.NotificationListener;
import javax.management.ObjectName;
@@ -235,9 +236,8 @@ public class JMXManagedObjectRegistry im
/**
* Override makeClient so we can cache the username of the client in a Map keyed by connectionId.
* ConnectionId is guaranteed to be unique per client connection, according to the JMS spec.
- *
- * MBeanInvocationHandlerImpl#handleNotification is responsible for removing the map entry on receipt
- * of CLOSE or FAIL notifications.
+ * An instance of NotificationListener (mapCleanupListener) will be responsible for removing these Map
+ * entries.
*
* @see javax.management.remote.rmi.RMIJRMPServerImpl#makeClient(java.lang.String, javax.security.auth.Subject)
*/
@@ -250,6 +250,19 @@ public class JMXManagedObjectRegistry im
return makeClient;
}
};
+
+ // Create a Listener responsible for removing the map entries add by the #makeClient entry above.
+ final NotificationListener mapCleanupListener = new NotificationListener()
+ {
+
+ @Override
+ public void handleNotification(Notification notification, Object handback)
+ {
+ final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
+ connectionIdUsernameMap.remove(connectionId);
+ }
+ };
+
String localHost;
try
{
@@ -326,13 +339,21 @@ public class JMXManagedObjectRegistry im
// which is the MBeanInvocationHandlerImpl and so also a NotificationListener.
final NotificationListener invocationHandler = (NotificationListener) Proxy.getInvocationHandler(mbsf);
- // Install a notification listener on OPENED, CLOSED, and FAIL,
+ // Install a notification listener on OPENED, CLOSED, and FAILED,
// passing the map of connection-ids to usernames as hand-back data.
- NotificationFilterSupport filter = new NotificationFilterSupport();
- filter.enableType(JMXConnectionNotification.OPENED);
- filter.enableType(JMXConnectionNotification.CLOSED);
- filter.enableType(JMXConnectionNotification.FAILED);
- _cs.addNotificationListener(invocationHandler, filter, connectionIdUsernameMap);
+ final NotificationFilterSupport invocationHandlerFilter = new NotificationFilterSupport();
+ invocationHandlerFilter.enableType(JMXConnectionNotification.OPENED);
+ invocationHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
+ invocationHandlerFilter.enableType(JMXConnectionNotification.FAILED);
+ _cs.addNotificationListener(invocationHandler, invocationHandlerFilter, connectionIdUsernameMap);
+
+ // Install a second notification listener on CLOSED AND FAILED only to remove the entry from the
+ // Map. Here we rely on the fact that JMX will call the listeners in the order in which they are
+ // installed.
+ final NotificationFilterSupport mapCleanupHandlerFilter = new NotificationFilterSupport();
+ mapCleanupHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
+ mapCleanupHandlerFilter.enableType(JMXConnectionNotification.FAILED);
+ _cs.addNotificationListener(mapCleanupListener, mapCleanupHandlerFilter, null);
_cs.start();
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java?rev=1206086&r1=1206085&r2=1206086&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java Fri Nov 25 09:14:07 2011
@@ -338,11 +338,10 @@ public class MBeanInvocationHandlerImpl
// Normally JMXManagedObjectRegistry provides a Map as handback data containing a map
// between connection id and username.
- Map<String, String> connectionIdUsernameMap = null;
String user = null;
if (handback != null && handback instanceof Map)
{
- connectionIdUsernameMap = (Map<String, String>) handback;
+ final Map<String, String> connectionIdUsernameMap = (Map<String, String>) handback;
user = connectionIdUsernameMap.get(connectionId);
}
@@ -361,11 +360,6 @@ public class MBeanInvocationHandlerImpl
JMXConnectionNotification.FAILED.equals(type))
{
_logActor.message(ManagementConsoleMessages.CLOSE(user));
- // We are responsible for removing the entry from the map
- if (connectionIdUsernameMap != null)
- {
- connectionIdUsernameMap.remove(connectionId);
- }
}
}
}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org