[jboss-remoting-commits] JBoss Remoting SVN: r4449 - remoting2/branches/2.x/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jul 31 20:48:01 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-07-31 20:48:00 -0400 (Thu, 31 Jul 2008)
New Revision: 4449

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1012: Enable injection of ConnectionListener.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2008-08-01 00:46:58 UTC (rev 4448)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2008-08-01 00:48:00 UTC (rev 4449)
@@ -218,6 +218,8 @@
    public static final String ECHO = "$ECHO$";
    
    public static final String INVOKER_SESSION_ID = "invokerSessionId";
+   
+   public static final String CONNECTION_LISTENER = "connectionListener";
 
 
    // Static ---------------------------------------------------------------------------------------
@@ -349,7 +351,64 @@
          throw new IllegalArgumentException("Can not add null ConnectionListener.");
       }
    }
+   
+   public void setConnectionListener(Object listener)
+   {
+      if (listener == null)
+      {
+         log.error("ConnectionListener is null");
+         return;
+      }
+      
+      if (listener instanceof ConnectionListener)
+      {
+         addConnectionListener((ConnectionListener) listener);
+         return;
+      }
 
+      if (!(listener instanceof String))
+      {
+         log.error("Object supplied as ConnectionListener is neither String nor ConnectionListener");
+         return;
+      }
+
+      ConnectionListener connectionListener = null;
+      try
+      {
+         MBeanServer server = getMBeanServer();
+         ObjectName objName = new ObjectName((String) listener);
+         Class c = ConnectionListener.class;
+         Object o = MBeanServerInvocationHandler.newProxyInstance(server, objName, c, false);
+         connectionListener = (ConnectionListener) o;
+      }
+      catch (MalformedObjectNameException e)
+      {
+         log.debug("Object supplied as ConnectionListener is not an object name.");
+      }
+
+      if (connectionListener == null)
+      {
+         try
+         {
+            Class listenerClass = ClassLoaderUtility.loadClass((String) listener, ServerInvoker.class);
+            connectionListener = (ConnectionListener) listenerClass.newInstance();
+         }
+         catch (Exception e)
+         {
+            log.error("Unable to instantiate " + listener + ": " + e.getMessage());
+            return;
+         }
+      }
+
+      if (connectionListener == null)
+      {
+         log.error("Unable to create ConnectionListener from " + listener);
+         return;
+      }
+      
+      addConnectionListener(connectionListener);
+   }
+
    public void removeConnectionListener(ConnectionListener listener)
    {
       if(connectionNotifier != null)
@@ -1086,6 +1145,13 @@
          }
       }
       
+      // Inject ConnectionListener
+      String connectionListener = (String)config.get(CONNECTION_LISTENER);
+      if (connectionListener != null)
+      {
+         setConnectionListener(connectionListener);
+      }
+      
       String registerCallbackListenersString = (String)config.get(REGISTER_CALLBACK_LISTENER);
       if(registerCallbackListenersString != null)
       {




More information about the jboss-remoting-commits mailing list