User: slaboure
  Date: 01/11/26 08:22:02

  Modified:    src/main/org/jboss/ha/framework/interfaces HARMIClient.java
                        HARMIProxy.java HARMIResponse.java HARMIServer.java
  Log:
  Added javadoc comments.
  Reorganized code to JBoss coding conventions.
  
  Revision  Changes    Path
  1.5       +86 -78    
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
  
  Index: HARMIClient.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HARMIClient.java  2001/11/12 05:32:00     1.4
  +++ HARMIClient.java  2001/11/26 16:22:01     1.5
  @@ -4,25 +4,13 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  +
   package org.jboss.ha.framework.interfaces;
   
  -import java.io.IOException;
   
   import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
  -
  -import java.util.Vector;
   import java.util.ArrayList;
  -import java.util.HashMap;
   
  -import java.rmi.ConnectException;
  -import java.rmi.ConnectIOException;
  -import java.rmi.NoSuchObjectException;
  -import java.rmi.UnknownHostException;
  -import java.rmi.RemoteException;
  -import java.rmi.ServerException;
  -import java.rmi.MarshalledObject;
  -
   import org.jboss.ejb.plugins.jrmp.interfaces.RemoteMethodInvocation;
   
   /**
  @@ -30,7 +18,7 @@
    *
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    *
    *   <p><b>Revisions:</b>
    *
  @@ -40,16 +28,24 @@
    *   </ul>
    */
   
  -public class HARMIClient implements java.io.Serializable, 
java.lang.reflect.InvocationHandler, HARMIProxy
  +public class HARMIClient 
  +   implements HARMIProxy, java.lang.reflect.InvocationHandler, java.io.Serializable
   {
  +   // Constants -----------------------------------------------------
  +   
  +   // Attributes ----------------------------------------------------
  +   
      protected String key = null;
      protected ArrayList targets = null;
      protected LoadBalancePolicy loadBalancePolicy;
      protected transient long currentViewId = 0;
      protected transient Object local = null;
  +   
  +   // Static --------------------------------------------------------
  +   
  +   // Constructors --------------------------------------------------
      
  -   public HARMIClient()
  -   {}
  +   public HARMIClient() {}
      
      public HARMIClient(ArrayList targets, LoadBalancePolicy policy, String key)
      {
  @@ -71,10 +67,7 @@
         this.local = local;
      }
      
  -   public boolean isLocal()
  -   {
  -      return local != null;
  -   }
  +   // Public --------------------------------------------------------
      
      public ArrayList getTargets()
      {
  @@ -89,7 +82,6 @@
            targets.addAll(newTargets);
         }
      }
  -
      
      public Object getRemoteTarget()
      {
  @@ -108,35 +100,66 @@
      {
         removeDeadTarget(target);
      }
  +
  +
  +   public Method findLocalMethod(Method method, Object[] args) throws Exception
  +   {
  +      return method;
  +   }
      
  -   protected void removeDeadTarget(Object target)
  +   
  +   public Object invokeRemote(Object proxy, Method method, Object[] args) throws 
Throwable
      {
  -      //System.out.println("Size before : " + Integer.toString(targets.length));
  -      if (targets != null)
  +      HARMIServer target = (HARMIServer)getRemoteTarget();
  +      while (target != null)
         {
  -         synchronized(targets)
  +         try
            {
  -            //System.out.println("removeDeadTarget has been called");
  -            int length = targets.size();
  -            for (int i=0; i<length; ++i)
  +            RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, method, 
args);
  +            java.rmi.MarshalledObject mo = new java.rmi.MarshalledObject(rmi);
  +            // Is this step actually necessary?  Can I just do 
method.invoke(target, args); ?
  +            HARMIResponse rsp = target.invoke(currentViewId, mo);
  +            if (rsp.newReplicants != null)
               {
  -               if (targets.get(i) == target)
  -               {
  -                  targets.remove(i);
  -                  return;
  -               }
  +//               System.out.println("new set of replicants");
  +               setTargets(rsp.newReplicants);
  +               currentViewId = rsp.currentViewId;
               }
  +            return rsp.response;
  +         }
  +         catch (java.rmi.ConnectException ce)
  +         {
  +         }
  +         catch (java.rmi.ConnectIOException cioe)
  +         {
  +         }
  +         catch (java.rmi.NoSuchObjectException nsoe)
  +         {
            }
  +         catch (java.rmi.UnmarshalException ue ) 
  +         {
  +         }
  +         catch (java.rmi.UnknownHostException uhe)
  +         {
  +         }
  +         // If we reach here, this means that we must fail-over
  +         remoteTargetHasFailed(target);
  +         target = (HARMIServer)getRemoteTarget();
         }
  -      // nothing found
  +      // if we get here this means list was exhausted
  +      throw new java.rmi.RemoteException("Service unavailable.");
  +      
      }
   
  -
  -   public Method findLocalMethod(Method method, Object[] args) throws Exception
  +   // HARMIProxy implementation ----------------------------------------------
  +   
  +   public boolean isLocal()
      {
  -      return method;
  +      return local != null;
      }
      
  +   // InvocationHandler implementation 
----------------------------------------------   
  +   
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      {
         // The isLocal call is handled by the proxy
  @@ -155,7 +178,7 @@
               Method localMethod = findLocalMethod(method, args);
               return localMethod.invoke(local, args);
            }
  -         catch (InvocationTargetException ite)
  +         catch (java.lang.reflect.InvocationTargetException ite)
            {
               throw ite.getTargetException();
            }
  @@ -165,52 +188,36 @@
            return invokeRemote(null, method, args);
         }
      }
  +
  +   // Package protected ---------------------------------------------
      
  -   public Object invokeRemote(Object proxy, Method method, Object[] args) throws 
Throwable
  +   // Protected -----------------------------------------------------
  +   
  +   protected void removeDeadTarget(Object target)
      {
  -      HARMIServer target = (HARMIServer)getRemoteTarget();
  -      while (target != null)
  +      //System.out.println("Size before : " + Integer.toString(targets.length));
  +      if (targets != null)
         {
  -         try
  +         synchronized(targets)
            {
  -            RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, method, 
args);
  -            MarshalledObject mo = new MarshalledObject(rmi);
  -            // Is this step actually necessary?  Can I just do 
method.invoke(target, args); ?
  -            HARMIResponse rsp = target.invoke(currentViewId, mo);
  -            if (rsp.newReplicants != null)
  +            //System.out.println("removeDeadTarget has been called");
  +            int length = targets.size();
  +            for (int i=0; i<length; ++i)
               {
  -//               System.out.println("new set of replicants");
  -               setTargets(rsp.newReplicants);
  -               currentViewId = rsp.currentViewId;
  +               if (targets.get(i) == target)
  +               {
  +                  targets.remove(i);
  +                  return;
  +               }
               }
  -            return rsp.response;
  -         }
  -         catch (ConnectException ce)
  -         {
  -         }
  -         catch (ConnectIOException cioe)
  -         {
  -         }
  -         catch (NoSuchObjectException nsoe)
  -         {
  -         }
  -         catch (java.rmi.UnmarshalException ue ) 
  -         {
            }
  -         catch (UnknownHostException uhe)
  -         {
  -         }
  -         // If we reach here, this means that we must fail-over
  -         remoteTargetHasFailed(target);
  -         target = (HARMIServer)getRemoteTarget();
         }
  -      // if we get here this means list was exhausted
  -      throw new RemoteException("Service unavailable.");
  -      
  +      // nothing found
      }
  +
  +   // Private -------------------------------------------------------
      
  -   private void readObject(java.io.ObjectInputStream stream)
  -   throws IOException, ClassNotFoundException
  +   private void readObject (java.io.ObjectInputStream stream) throws 
java.io.IOException, ClassNotFoundException
      {
         this.key = (String)stream.readUTF();
         this.targets = (ArrayList)stream.readObject();
  @@ -233,12 +240,13 @@
            }
         }
      }
  -   private void writeObject(java.io.ObjectOutputStream stream)
  -   throws IOException
  +   private void writeObject (java.io.ObjectOutputStream stream) throws 
java.io.IOException
      {
         stream.writeUTF(key);
         stream.writeObject(targets);
         stream.writeObject(loadBalancePolicy);
      }
  +   
  +   // Inner classes -------------------------------------------------  
      
  -}
  +}
  \ No newline at end of file
  
  
  
  1.3       +14 -5     
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIProxy.java
  
  Index: HARMIProxy.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIProxy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HARMIProxy.java   2001/10/10 20:02:05     1.2
  +++ HARMIProxy.java   2001/11/26 16:22:01     1.3
  @@ -1,14 +1,23 @@
  +/*
  + * JBoss, the OpenSource J2EE WebOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
   package org.jboss.ha.framework.interfaces;
   
   /** 
    *
  - *   @author [EMAIL PROTECTED]
  - *   @author [EMAIL PROTECTED]
  - *   @version $Revision: 1.2 $
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  + *   @version $Revision: 1.3 $
    *
    * <p><b>Revisions:</b><br>
    */
  -public interface HARMIProxy extends java.io.Serializable
  +
  +public interface HARMIProxy 
  +   extends java.io.Serializable
   {
      public boolean isLocal();
  -}
  +}
  \ No newline at end of file
  
  
  
  1.4       +17 -12    
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIResponse.java
  
  Index: HARMIResponse.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIResponse.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HARMIResponse.java        2001/10/10 20:02:05     1.3
  +++ HARMIResponse.java        2001/11/26 16:22:02     1.4
  @@ -1,24 +1,29 @@
  -package org.jboss.ha.framework.interfaces;
  +/*
  + * JBoss, the OpenSource J2EE WebOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   
  -import java.util.ArrayList;
  +package org.jboss.ha.framework.interfaces;
   
   /** 
  + *   When using HA-RMI, the result of an invocation is embedded in an instance of 
this class.
  + *   It contains the response of the invocation and, if the list of targets has 
changed,
  + *   a new view of the cluster.
    *
  - *   @author [EMAIL PROTECTED]
  - *   @author [EMAIL PROTECTED]
  - *   @version $Revision: 1.3 $
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  + *   @version $Revision: 1.4 $
    *
    * <p><b>Revisions:</b><br>
    */
  -public class HARMIResponse implements java.io.Serializable
   
  +public class HARMIResponse 
  +   implements java.io.Serializable
   {
  -
  -   public ArrayList newReplicants = null;
  -
  -   public long currentViewId = 0;
  -
  +   public java.util.ArrayList newReplicants = null;
  +   public long currentViewId = 0;   
      public Object response = null;
  -
   }
   
  
  
  
  1.4       +35 -28    
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIServer.java
  
  Index: HARMIServer.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIServer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HARMIServer.java  2001/11/09 22:42:02     1.3
  +++ HARMIServer.java  2001/11/26 16:22:02     1.4
  @@ -1,43 +1,50 @@
  +/*
  + * JBoss, the OpenSource J2EE WebOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
   package org.jboss.ha.framework.interfaces;
   
  -import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
   
  -import java.util.Vector;
  -import java.util.ArrayList;
  -import java.util.HashMap;
   import java.util.Hashtable;
  -import java.util.Iterator;
  -import java.util.Collection;
  -
  -import java.io.Serializable;
   
  -import java.rmi.Remote;
  -import java.rmi.server.RemoteStub;
  -import java.rmi.server.UnicastRemoteObject;
  -import java.rmi.RemoteException;
  -import java.rmi.MarshalledObject;
  -
  -import org.jboss.logging.Logger;
  -import org.jboss.ejb.plugins.jrmp.interfaces.RemoteMethodInvocation;
  -
   /** 
  + *   When using HA-RMI, the RMI communication end-point on the server-side is
  + *   an instance of this class. All invocations are sent through this servant
  + *   that will route the call to the appropriate object and call the appropriate
  + *   Java method.
    *
  - *   @author [EMAIL PROTECTED]
  - *   @author [EMAIL PROTECTED]
  - *   @version $Revision: 1.3 $
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  + *   @version $Revision: 1.4 $
    *
    * <p><b>Revisions:</b><br>
    */
  -public interface HARMIServer
  -   extends Remote
  +
  +public interface HARMIServer extends java.rmi.Remote
   {
  -   public HARMIResponse invoke(long tag, MarshalledObject mimo) throws Exception;
  -   public ArrayList getReplicants() throws Exception;
  +   public static Hashtable rmiServers = new Hashtable();
  +
  +   /**
  +    * Performs an invocation through this HA-RMI for the target object hidden 
behind it.
  +    */   
  +   public HARMIResponse invoke (long tag, java.rmi.MarshalledObject mimo) throws 
Exception;
  +   
  +   /**
  +    * Returns a list of node stubs that are current replica of this service.
  +    */   
  +   public java.util.List getReplicants () throws Exception;
  +   
  +   /**
  +    * Get local stub for this service.
  +    */   
      public Object getLocal() throws Exception;
   
  +   /**
  +    * Update, on the fly, the underlying partition used to communicate in the 
cluster.
  +    */   
      public void updateHAPartition (HAPartition partition)  throws Exception;
      
  -   public static Hashtable rmiServers = new Hashtable();
  -
  -}
  +}
  \ No newline at end of file
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to