[jboss-cvs] JBossAS SVN: r65310 - trunk/cluster/src/main/org/jboss/ha/framework/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 11 18:03:06 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-09-11 18:03:06 -0400 (Tue, 11 Sep 2007)
New Revision: 65310

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
Ensure we always restore the TCCL
Extract RspList handling into a method
[JBAS-4702] Don't support null 'types' param to HAPartition cluster RPC invocation methods

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-09-11 22:02:30 UTC (rev 65309)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2007-09-11 22:03:06 UTC (rev 65310)
@@ -799,16 +799,11 @@
    public ArrayList callMethodOnCluster(String objName, String methodName,
        Object[] args, Class[] types, boolean excludeSelf, long methodTimeout) throws Exception
    {
-      ArrayList rtn = new ArrayList();
-      MethodCall m=null;
       RspList rsp = null;
       boolean trace = log.isTraceEnabled();
 
-      if(types != null)
-         m=new MethodCall(objName + "." + methodName, args, types);
-      else
-         m=new MethodCall(objName + "." + methodName, args);
-
+      MethodCall m = new MethodCall(objName + "." + methodName, args, types);
+      
       if (excludeSelf)
       {
          if( trace )
@@ -828,36 +823,7 @@
          rsp = dispatcher.callRemoteMethods(null, m, GroupRequest.GET_ALL, methodTimeout);
       }
 
-      if (rsp != null)
-      {
-         for (int i = 0; i < rsp.size(); i++)
-         {
-            Object item = rsp.elementAt(i);
-            if (item instanceof Rsp)
-            {
-               Rsp response = (Rsp) item;
-               // Only include received responses
-               boolean wasReceived = response.wasReceived();
-               if( wasReceived == true )
-               {
-                  item = response.getValue();
-                  if (!(item instanceof NoHandlerForRPC))
-                     rtn.add(item);
-               }
-               else if( trace )
-                  log.trace("Ignoring non-received response: "+response);
-            }
-            else
-            {
-               if (!(item instanceof NoHandlerForRPC))
-                  rtn.add(item);
-               else if( trace )
-                  log.trace("Ignoring NoHandlerForRPC");
-            }
-         }
-      }
-
-      return rtn;
+      return processResponseList(rsp, trace);
     }
 
    /**
@@ -894,16 +860,10 @@
    public ArrayList callMethodOnCoordinatorNode(String objName, String methodName,
           Object[] args, Class[] types,boolean excludeSelf, long methodTimeout) throws Exception
    {
-      ArrayList rtn = new ArrayList();
-      MethodCall m=null;
-      RspList rsp = null;
       boolean trace = log.isTraceEnabled();
 
-      if(types != null)
-         m=new MethodCall(objName + "." + methodName, args, types);
-      else
-         m=new MethodCall(objName + "." + methodName, args);
-
+      MethodCall m = new MethodCall(objName + "." + methodName, args, types);
+      
       if( trace )
       {
          log.trace("callMethodOnCoordinatorNode(false), objName="+objName
@@ -915,15 +875,22 @@
       // If we are the coordinator, only call ourself if 'excludeSelf' is false
       if (false == isCurrentNodeCoordinator () ||
           false == excludeSelf)
+      {
          coordinatorOnly.addElement(this.jgmembers.elementAt (0));
+      }
+      
+      RspList rsp = dispatcher.callRemoteMethods(coordinatorOnly, m, GroupRequest.GET_ALL, methodTimeout);
 
-      rsp = dispatcher.callRemoteMethods(coordinatorOnly, m, GroupRequest.GET_ALL, methodTimeout);
-
+      return processResponseList(rsp, trace);
+   }
+   
+   private ArrayList processResponseList(RspList rsp, boolean trace)
+   {
+      ArrayList rtn = new ArrayList();
       if (rsp != null)
       {
-         for (int i = 0; i < rsp.size(); i++)
+         for (Object item : rsp.values())
          {
-            Object item = rsp.elementAt(i);
             if (item instanceof Rsp)
             {
                Rsp response = (Rsp) item;
@@ -946,8 +913,8 @@
                   log.trace("Ignoring NoHandlerForRPC");
             }
          }
+         
       }
-
       return rtn;
    }
 
@@ -957,13 +924,9 @@
    public void callAsynchMethodOnCluster(String objName, String methodName,
       Object[] args, Class[] types, boolean excludeSelf) throws Exception
    {
-      MethodCall m = null;
       boolean trace = log.isTraceEnabled();
 
-      if(types != null)
-         m=new MethodCall(objName + "." + methodName, args, types);
-      else
-         m=new MethodCall(objName + "." + methodName, args);
+      MethodCall m = new MethodCall(objName + "." + methodName, args, types);
 
       if (excludeSelf)
       {
@@ -1653,23 +1616,30 @@
 
          ClassLoader previousCL = null;
          boolean overrideCL = false;
-         WeakReference<ClassLoader> weak = clmap.get(serviceName);
-         if (weak != null) // this should always be true since we only use HAServiceResponse when classloader is specified
+         try
          {
-            previousCL = Thread.currentThread().getContextClassLoader();
-            ClassLoader loader = weak.get();
-            if( trace )
-               log.trace("overriding response Thread ContextClassLoader for service " + serviceName);
-            Thread.currentThread().setContextClassLoader(loader);            
-            overrideCL = true;
+            WeakReference<ClassLoader> weak = clmap.get(serviceName);
+            if (weak != null) // this should always be true since we only use HAServiceResponse when classloader is specified
+            {
+               previousCL = Thread.currentThread().getContextClassLoader();
+               ClassLoader loader = weak.get();
+               if( trace )
+                  log.trace("overriding response Thread ContextClassLoader for service " + serviceName);            
+               overrideCL = true;
+               Thread.currentThread().setContextClassLoader(loader);
+            }
+            retval = objectFromByteBufferResponseInternal(payload);
+   
+            return retval;
          }
-         retval = objectFromByteBufferResponseInternal(payload);
-         if (overrideCL == true)
+         finally
          {
-            log.trace("resetting response classloader");
-            Thread.currentThread().setContextClassLoader(previousCL);
+            if (overrideCL == true)
+            {
+               log.trace("resetting response classloader");
+               Thread.currentThread().setContextClassLoader(previousCL);
+            }
          }
-         return retval;
       }
 
       public byte[] objectToByteBuffer(Object obj) throws Exception
@@ -1707,6 +1677,7 @@
          boolean trace = log.isTraceEnabled();
          boolean overrideCL = false;
          ClassLoader previousCL = null;
+         String service = null;
          byte[] request_bytes = null;
          
          if( trace )
@@ -1728,7 +1699,7 @@
 
             // wrapper should be Object[]{service_name, byte[]}
             Object[] temp = (Object[])wrapper;
-            String service = (String)temp[0];
+            service = (String)temp[0];
             request_bytes = (byte[])temp[1];
 
             // see if this node has registered to handle this service
@@ -1739,7 +1710,15 @@
                   log.trace("Partition " + getPartitionName() + " no rpc handler registered under service " + service);
                return new NoHandlerForRPC();
             }
-            
+         }
+         catch(Exception e)
+         {
+            log.warn("Partition " + getPartitionName() + " failed unserializing message buffer (msg=" + req + ")", e);
+            return null;
+         }
+         
+         try
+         {            
             // If client registered the service with a classloader, override the thread classloader here
             WeakReference<ClassLoader> weak = clmap.get(service);
             if (weak != null)
@@ -1748,18 +1727,9 @@
                   log.trace("overriding Thread ContextClassLoader for RPC service " + service);
                previousCL = Thread.currentThread().getContextClassLoader();
                ClassLoader loader = weak.get();
-               Thread.currentThread().setContextClassLoader(loader);
                overrideCL = true;
+               Thread.currentThread().setContextClassLoader(loader);
             }
-         }
-         catch(Exception e)
-         {
-            log.warn("Partition " + getPartitionName() + " failed unserializing message buffer (msg=" + req + ")", e);
-            return null;
-         }
-         
-         try
-         {
             body = objectFromByteBufferInternal(request_bytes);
          }
          catch (Exception e)




More information about the jboss-cvs-commits mailing list