[jboss-remoting-commits] JBoss Remoting SVN: r4382 - remoting2/branches/2.2/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Jul 18 01:21:39 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-07-18 01:21:38 -0400 (Fri, 18 Jul 2008)
New Revision: 4382

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

Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java	2008-07-18 01:48:26 UTC (rev 4381)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java	2008-07-18 05:21:38 UTC (rev 4382)
@@ -54,8 +54,6 @@
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.net.InetAddress;
-import java.net.MalformedURLException;
-import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -213,6 +211,8 @@
    public static final String REGISTER_CALLBACK_LISTENER = "registerCallbackListener";
    
    public static final String INVOKER_SESSION_ID = "invokerSessionId";
+   
+   public static final String CONNECTION_LISTENER = "connectionListener";
 
 
    // Static ---------------------------------------------------------------------------------------
@@ -340,7 +340,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)
@@ -1120,6 +1177,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