[jboss-cvs] JBossAS SVN: r57806 - in branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss: ha/framework/interfaces invocation/jrmp/interfaces

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 24 16:20:13 EDT 2006


Author: fnasser at redhat.com
Date: 2006-10-24 16:20:11 -0400 (Tue, 24 Oct 2006)
New Revision: 57806

Modified:
   branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
   branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
   branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
Log:
ASPATCH-44: JBAS-2303: Patch for ConcurrentModificationException in JRMPInvokerProxyHA serialization

Modified: branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java
===================================================================
--- branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java	2006-10-24 18:55:14 UTC (rev 57805)
+++ branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/FamilyClusterInfoImpl.java	2006-10-24 20:20:11 UTC (rev 57806)
@@ -21,85 +21,87 @@
  */
 public class FamilyClusterInfoImpl implements FamilyClusterInfo
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    public String familyName = null;
    ArrayList targets = null;
    long currentViewId = 0;
    boolean isViewMembersInSyncWithViewId = false;
-   
+
    int cursor = FamilyClusterInfo.UNINITIALIZED_CURSOR;
    Object arbitraryObject = null;
-      
+
    // Static --------------------------------------------------------
-    
+
    // Constructors --------------------------------------------------
-   
+
    private FamilyClusterInfoImpl (){ }
-   
+
    protected FamilyClusterInfoImpl (String familyName, ArrayList targets, long viewId)
    {
       this.familyName = familyName;
-      this.targets = targets;
+      this.targets = (ArrayList) targets.clone();
       this.currentViewId = viewId;
-      
+
       this.isViewMembersInSyncWithViewId = false;
    }
 
    // Public --------------------------------------------------------
-   
+
    // FamilyClusterInfo implementation ----------------------------------------------
-   
-   public String getFamilyName () { return this.familyName; }      
-   public ArrayList getTargets () { return this.targets; }
+
+   public String getFamilyName () { return this.familyName; }
+   public synchronized ArrayList getTargets () { return this.targets; }
    public long getCurrentViewId () { return this.currentViewId; }
    public int getCursor () { return this.cursor; }
    public int setCursor (int cursor) { return (this.cursor = cursor);}
    public Object getObject () { return this.arbitraryObject; }
    public Object setObject (Object whatever) { this.arbitraryObject = whatever; return this.arbitraryObject; }
-   
+
    public ArrayList removeDeadTarget(Object target)
    {
       synchronized (this)
       {
-         this.targets.remove (target);
-         this.isViewMembersInSyncWithViewId = false;         
+         ArrayList tmp = (ArrayList) targets.clone();
+         tmp.remove (target);
+         this.targets = tmp;
+         this.isViewMembersInSyncWithViewId = false;
       }
       return this.targets;
    }
-   
+
    public ArrayList updateClusterInfo (ArrayList targets, long viewId)
    {
       synchronized (this)
       {
-         this.targets = targets;
+         this.targets = (ArrayList) targets.clone();
          this.currentViewId = viewId;
          this.isViewMembersInSyncWithViewId = true;
       }
       return this.targets;
    }
-      
+
    public boolean currentMembershipInSyncWithViewId ()
    {
       return this.isViewMembersInSyncWithViewId;
    }
-   
+
    public void resetView ()
    {
       this.currentViewId = -1;
       this.isViewMembersInSyncWithViewId = false;
    }
-      
+
    // Object overrides ---------------------------------------------------
-   
+
    public int hashCode()
    {
       return this.familyName.hashCode ();
    }
-   
+
    public boolean equals (Object o)
    {
       if (o instanceof FamilyClusterInfoImpl)
@@ -108,7 +110,7 @@
          return fr.familyName == this.familyName;
       }
       else
-         return false;         
+         return false;
    }
 
    public String toString()
@@ -130,11 +132,11 @@
       return tmp.toString();
    }
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
-}
+
+}
\ No newline at end of file

Modified: branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
===================================================================
--- branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java	2006-10-24 18:55:14 UTC (rev 57805)
+++ branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java	2006-10-24 20:20:11 UTC (rev 57806)
@@ -23,41 +23,41 @@
  *   @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
  *   @version $Revision$
  */
-public class HARMIClient 
+public class HARMIClient
    implements HARMIProxy, java.lang.reflect.InvocationHandler, java.io.Serializable
 {
    // Constants -----------------------------------------------------
    /** The serialVersionUID
-    * @since 
-    */ 
+    * @since
+    */
    private static final long serialVersionUID = -1227816478666532463L;
 
    // Attributes ----------------------------------------------------
-   
+
    protected String key = null;
    //protected ArrayList targets = null;
    protected LoadBalancePolicy loadBalancePolicy;
    //protected transient long currentViewId = 0;
    protected transient Object local = null;
-   
+
    FamilyClusterInfo familyClusterInfo = null;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    public HARMIClient() {}
-   
+
    public HARMIClient(ArrayList targets, LoadBalancePolicy policy, String key)
    {
       this.familyClusterInfo = ClusteringTargetsRepository.initTarget (key, targets, 0L);
-      
+
       //this.targets = targets;
       this.loadBalancePolicy = policy;
-      this.loadBalancePolicy.init(this);      
+      this.loadBalancePolicy.init(this);
       this.key = key;
    }
-   
+
    public HARMIClient(ArrayList targets,
                        long initViewId,
                        LoadBalancePolicy policy,
@@ -65,21 +65,21 @@
                        Object local)
    {
       this.familyClusterInfo = ClusteringTargetsRepository.initTarget (key, targets, initViewId);
-      
+
       //this.targets = targets;
       this.loadBalancePolicy = policy;
-      this.loadBalancePolicy.init(this);      
+      this.loadBalancePolicy.init(this);
       this.key = key;
       this.local = local;
    }
-   
+
    // Public --------------------------------------------------------
    /*
    public ArrayList getTargets()
    {
       return targets;
    }
-   
+
    public void setTargets(ArrayList newTargets)
    {
       synchronized(targets)
@@ -100,7 +100,7 @@
       //      System.out.println("number of targets: " + targets.size());
       return loadBalancePolicy.chooseTarget(this.familyClusterInfo, null); // legacy, no Invocation object in raw HA-RMI
    }
-   
+
    public void remoteTargetHasFailed(Object target)
    {
       removeDeadTarget(target);
@@ -111,11 +111,11 @@
    {
       return method;
    }
-   
-   
+
+
    public Object invokeRemote(Object proxy, Method method, Object[] args) throws Throwable
    {
-      HARMIServer target = (HARMIServer)getRemoteTarget();      
+      HARMIServer target = (HARMIServer)getRemoteTarget();
       while (target != null)
       {
          try
@@ -127,12 +127,12 @@
             HARMIResponse rsp = target.invoke(this.familyClusterInfo.getCurrentViewId (), mi);
             if (rsp.newReplicants != null)
             {
-               // System.out.println("new set of replicants" + rsp.newReplicants + " : view : " + rsp.currentViewId); 
+               // System.out.println("new set of replicants" + rsp.newReplicants + " : view : " + rsp.currentViewId);
                updateClusterInfo (rsp.newReplicants, rsp.currentViewId);
                //setTargets(rsp.newReplicants);
                //currentViewId = rsp.currentViewId;
-            }               
-               
+            }
+
             return rsp.response;
          }
          catch (java.rmi.ConnectException ce)
@@ -144,7 +144,7 @@
          catch (java.rmi.NoSuchObjectException nsoe)
          {
          }
-         catch (java.rmi.UnmarshalException ue ) 
+         catch (java.rmi.UnmarshalException ue )
          {
          }
          catch (java.rmi.UnknownHostException uhe)
@@ -156,18 +156,18 @@
       }
       // if we get here this means list was exhausted
       throw new java.rmi.RemoteException("Service unavailable.");
-      
+
    }
 
    // HARMIProxy implementation ----------------------------------------------
-   
+
    public boolean isLocal()
    {
       return local != null;
    }
-   
-   // InvocationHandler implementation ----------------------------------------------   
-   
+
+   // InvocationHandler implementation ----------------------------------------------
+
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
       // The isLocal call is handled by the proxy
@@ -176,7 +176,7 @@
       {
          return method.invoke(this, args);
       }
-      
+
       // we try to optimize the call locally first
       //
       if (local != null)
@@ -198,9 +198,9 @@
    }
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    protected void removeDeadTarget(Object target)
    {
       //System.out.println("Size before : " + Integer.toString(targets.length));
@@ -209,22 +209,22 @@
    }
 
    // Private -------------------------------------------------------
-   
+
    private void readObject (ObjectInputStream stream)
       throws IOException, ClassNotFoundException
    {
       this.key = stream.readUTF();
       ArrayList targets = (ArrayList)stream.readObject();
       long vid = stream.readLong ();
-      this.loadBalancePolicy = (LoadBalancePolicy)stream.readObject();      
+      this.loadBalancePolicy = (LoadBalancePolicy)stream.readObject();
       HARMIServer server = (HARMIServer)HARMIServer.rmiServers.get(key);
-      
+
       // keep a reference on our family object
       //
       this.familyClusterInfo = ClusteringTargetsRepository.initTarget (this.key, targets, vid);
 
       this.loadBalancePolicy.init(this);
-            
+
       if (server != null)
       {
          synchronized (targets)
@@ -243,14 +243,13 @@
       throws IOException
    {
       ArrayList currentTargets = this.familyClusterInfo.getTargets ();
-      currentTargets.trimToSize ();
       long vid = this.familyClusterInfo.getCurrentViewId ();
-      
+
       stream.writeUTF(key);
       stream.writeObject(currentTargets);
       stream.writeLong(vid);
       stream.writeObject(loadBalancePolicy);
-      
+
    }
-   
-}
+
+}
\ No newline at end of file

Modified: branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
===================================================================
--- branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2006-10-24 18:55:14 UTC (rev 57805)
+++ branches/JBoss_4_0_2_CP/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2006-10-24 20:20:11 UTC (rev 57806)
@@ -12,6 +12,7 @@
 import java.io.ObjectOutput;
 import java.rmi.MarshalledObject;
 import java.rmi.ServerException;
+import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.WeakHashMap;
 import javax.transaction.TransactionRolledbackException;
@@ -44,7 +45,7 @@
    // Public --------------------------------------------------------
    /** The serialVersionUID
     * @since 1.7.2.8
-    */ 
+    */
    private static final long serialVersionUID = -967671822225981666L;
    private static final Logger log = Logger.getLogger(JRMPInvokerProxyHA.class);
    public static final WeakHashMap txFailoverAuthorizations = new WeakHashMap();
@@ -109,7 +110,7 @@
    {
       this.familyClusterInfo.resetView ();
    }
-   
+
    public boolean txContextAllowsFailover (Invocation invocation)
    {
       javax.transaction.Transaction tx = invocation.getTransaction();
@@ -117,7 +118,7 @@
       {
          synchronized (tx)
          {
-            return ! txFailoverAuthorizations.containsKey (tx);               
+            return ! txFailoverAuthorizations.containsKey (tx);
          }
       }
       else
@@ -125,7 +126,7 @@
          return true;
       }
    }
-   
+
    public void invocationHasReachedAServer (Invocation invocation)
    {
       javax.transaction.Transaction tx = invocation.getTransaction();
@@ -133,7 +134,7 @@
       {
          synchronized (tx)
          {
-            txFailoverAuthorizations.put (tx, null);               
+            txFailoverAuthorizations.put (tx, null);
          }
       }
    }
@@ -158,11 +159,11 @@
       mi.setTransactionPropagationContext(getTransactionPropagationContext());
       mi.setValue("CLUSTER_VIEW_ID", new Long(this.familyClusterInfo.getCurrentViewId ()));
       Invoker target = (Invoker)getRemoteTarget(invocation);
-      
+
       boolean failoverAuthorized = true;
          Exception lastException = null;
       while (target != null && failoverAuthorized)
-      {                        
+      {
          boolean definitivlyRemoveNodeOnFailure = true;
          try
          {
@@ -187,7 +188,7 @@
                updateClusterInfo (rsp.newReplicants, rsp.currentViewId);
             }
             //else System.out.println("Static set of replicants: " + this.familyClusterInfo.getCurrentViewId () + " (me = " + this + ")");
-            
+
             invocationHasReachedAServer (invocation);
 
             return rsp.response;
@@ -250,9 +251,13 @@
             //unlike in the non-HA case?
             invocationHasReachedAServer (invocation);
             if (e.detail instanceof TransactionRolledbackException)
-            {                  
+            {
                throw (TransactionRolledbackException) e.detail;
             }
+            if (e.detail instanceof RemoteException)
+            {
+               throw (RemoteException) e.detail;
+            }
             throw e;
          }
          catch (Exception e)
@@ -272,7 +277,7 @@
             resetView ();
          }
 
-         failoverAuthorized = txContextAllowsFailover (invocation);            
+         failoverAuthorized = txContextAllowsFailover (invocation);
          target = (Invoker)getRemoteTarget(invocation);
 
          failoverCounter++;
@@ -299,7 +304,6 @@
    {
       ArrayList targets = this.familyClusterInfo.getTargets();
       long vid = this.familyClusterInfo.getCurrentViewId ();
-      targets.trimToSize();
       out.writeObject(targets);
       out.writeObject(this.loadBalancePolicy);
       out.writeObject (this.proxyFamilyName);
@@ -330,4 +334,4 @@
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list