User: slaboure
  Date: 01/09/30 08:19:32

  Added:       src/main/org/jboss/ha/framework/interfaces
                        DistributedReplicantManager.java
                        DistributedState.java HAPartition.java
                        HARMIClient.java HARMIProxy.java HARMIResponse.java
                        HARMIServer.java LoadBalancePolicy.java
                        RoundRobin.java
  Log:
  moved client side files of the HA framework
  from org.jboss.ha to org.jboss.ha.framework.interfaces
  
  Revision  Changes    Path
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/DistributedReplicantManager.java
  
  Index: DistributedReplicantManager.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  
  import java.util.ArrayList;
  
  import java.io.Serializable;
  
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  
  public interface DistributedReplicantManager extends Remote
  {
     /**
      * When a particular key in the DistributedReplicantManager table gets modified, 
all listeners
      * will be notified of replicant changes for that key.
      */
     public interface ReplicantListener
     {
        public void replicantsChanged(String key, ArrayList newReplicants);
     }
  
     public void registerListener(String key, ReplicantListener subscriber) throws 
Exception;
     public void unregisterListener(String key, ReplicantListener subscriber) throws 
Exception;
  
     // State binding methods
     //
     /**
      * remove the entire key from the ReplicationService
      */
     public void remove(String key) throws Exception;;
  
     /**
      * Add a replicant, it will be attached to this cluster node
      */
     public void add(String key, Serializable replicant) throws Exception;
  
     /**
      * Lookup the replicant attached to this cluster node
      */
     public Serializable lookupLocalReplicant(String key) throws Exception;
  
     /**
      * Return a list of all replicants.
      */
     public ArrayList lookupReplicants(String key) throws Exception;
  
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/DistributedState.java
  
  Index: DistributedState.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  import java.util.Collection;
  import java.io.Serializable;
  
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface DistributedState extends Remote
  {
     /**
      * When a particular key in the DistributedState table gets modified, all 
listeners
      * will be notified of replicant changes for that key. Keys are organized in 
categories.
      */
     public interface DSListener
     {
        public void valueHasChanged(String category, String key, Serializable value);
        public void keyHasBeenRemoved (String category, String key, Serializable 
previousContent);
     }
  
     public void registerDSListener(String category, DSListener subscriber) throws 
RemoteException;
     public void unregisterDSListener(String category, DSListener subscriber) throws 
RemoteException;
  
     // State binding methods
     //
     /**
      * remove the entire key from the ReplicationService
      */
     public void remove(String category, String key) throws Exception;
  
     /**
      * Associates a value to a key in a specific category
      */
     public void set(String category, String key, Serializable value) throws Exception;
  
     /**
      * Lookup the replicant attached to this cluster node
      */
     public Serializable get(String category, String key) throws RemoteException;
  
     /**
      * Return a list of all categories.
      */
     public Collection getAllCategories() throws RemoteException;
  
     /**
      * Return a list of all keys in a category.
      */
     public Collection getAllKeys(String category) throws RemoteException;
  
     /**
      * Return a list of all values in a category.
      */
     public Collection getAllValues(String category) throws RemoteException;
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/HAPartition.java
  
  Index: HAPartition.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE WebOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.ha.framework.interfaces;
  
  import java.util.ArrayList;
  import java.util.Vector;
  import java.io.Serializable;
  
  public interface HAPartition
  {
     // General methods
     //
     public String getNodeName();
     public String getPartitionName();
  
     public DistributedReplicantManager getDistributedReplicantManager();
     public DistributedState getDistributedStateService ();
     
     // ***************************
     // ***************************
     // RPC multicast communication
     // ***************************
     // ***************************
     //
     public void registerRPCHandler(String objectName, Object handler);
     public void unregisterRPCHandler(String objectName, Object subscriber);
  
     // Called only on all members of this partition on all nodes
     // (not subpartitions or other partitions)
     //
     public ArrayList callMethodOnCluster(String objectName, String methodName, 
Object[] args, boolean excludeSelf) throws Exception;
     
     // *************************
     // *************************
     // State transfer management
     // *************************
     // *************************
     //
     
     public interface HAPartitionStateTransfer
     {
        public Serializable getCurrentState ();
        public void setCurrentState(Serializable newState);
     }
     
     public void subscribeToStateTransferEvents (String objectName, 
HAPartition.HAPartitionStateTransfer subscriber) throws Exception;
     public void unsubscribeFromStateTransferEvents (String objectName, 
HAPartition.HAPartitionStateTransfer subscriber);
  
     // *************************
     // *************************
     // Group Membership listeners
     // *************************
     // *************************
     //
     public interface HAMembershipListener
     {
        public void membershipChanged(Vector deadMembers, Vector newMembers, Vector 
allMembers);
     }
  
     public void registerMembershipListener(HAMembershipListener listener);
     public void unregisterMembershipListener(HAMembershipListener listener);
  
  }
  
  
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
  
  Index: HARMIClient.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE WebOS
   *
   * 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;
  
  /**
   *
   *
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
   *   @version $Revision: 1.1 $
   *
   *   <p><b>Revisions:</b>
   *
   *   <p><b>20010831 Bill Burke:</b>
   *   <ul>
   *   <li> First import of sources
   *   </ul>
   */
  
  public class HARMIClient implements java.io.Serializable, 
java.lang.reflect.InvocationHandler, HARMIProxy
  {
     protected String key = null;
     protected ArrayList targets = null;
     protected LoadBalancePolicy loadBalancePolicy;
     protected transient long tag = 0;
     protected transient Object local = null;
     
     public HARMIClient ()
     {}
     
     public HARMIClient (ArrayList targets, LoadBalancePolicy policy, String key)
     {
        this.targets = targets;
        this.loadBalancePolicy = policy;
        this.loadBalancePolicy.init (this);      
        this.key = key;
     }
     
     public HARMIClient (ArrayList targets,
                         LoadBalancePolicy policy,
                         String key,
                         Object local)
     {
        this.targets = targets;
        this.loadBalancePolicy = policy;
        this.loadBalancePolicy.init (this);      
        this.key = key;
        this.local = local;
     }
     
     public boolean isLocal ()
     {
        return local != null;
     }
     
     public ArrayList getTargets ()
     {
        return targets;
     }
     
     public void setTargets (ArrayList newTargets)
     {
        synchronized(targets)
        {
           targets.clear ();
           targets.addAll (newTargets);
        }
     }
     
     public long getTag ()
     {
        return tag;
     }
     
     public void setTag (long tag)
     {
        this.tag = tag;
     }
     
     public Object getRemoteTarget ()
     {
        System.out.println ("number of targets: " + targets.size ());
        if (targets.size () == 0)
        {
           return null;
        }
        synchronized (targets)
        {
           return loadBalancePolicy.chooseTarget (targets);
        }
     }
     
     public void remoteTargetHasFailed (Object target)
     {
        removeDeadTarget (target);
     }
     
     protected void removeDeadTarget (Object target)
     {
        //System.out.println("Size before : " + Integer.toString(targets.length));
        if (targets != null)
        {
           synchronized (targets)
           {
              //System.out.println("removeDeadTarget has been called");
              int length = targets.size ();
              for (int i=0; i<length; ++i)
              {
                 if (targets.get (i) == target)
                 {
                    targets.remove (i);
                    return;
                 }
              }
           }
        }
        // nothing found
     }
     
     public Method findLocalMethod (Method method, Object[] args) throws Exception
     {
        return method;
     }
     
     public Object invoke (Object proxy, Method method, Object[] args) throws Throwable
     {
        // The isLocal call is handled by the proxy
        //
        if (method.getName ().equals ("isLocal") && (args == null || args.length == 0))
        {
           return method.invoke (this, args);
        }
        
        // we try to optimize the call locally first
        //
        if (local != null)
        {
           try
           {
              System.out.println ("collocated call");
              Method localMethod = findLocalMethod (method, args);
              return localMethod.invoke (local, args);
           }
           catch (InvocationTargetException ite)
           {
              throw ite.getTargetException ();
           }
        }
        else
        {
           return invokeRemote (null, method, args);
        }
     }
     
     public Object invokeRemote (Object proxy, Method method, Object[] args) throws 
Throwable
     {
        HARMIServer target = (HARMIServer)getRemoteTarget ();
        while (target != null)
        {
           try
           {
              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 (tag, mo);
              if (rsp.newReplicants != null)
              {
                 System.out.println ("new set of replicants");
                 setTargets (rsp.newReplicants);
                 setTag (rsp.tag);
              }
              return rsp.response;
           }
           catch (ConnectException ce)
           {
           }
           catch (ConnectIOException cioe)
           {
           }
           catch (NoSuchObjectException nsoe)
           {
           }
           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.");
        
     }
     
     private void readObject (java.io.ObjectInputStream stream)
     throws IOException, ClassNotFoundException
     {
        this.key = (String)stream.readUTF ();
        this.targets = (ArrayList)stream.readObject ();
        this.loadBalancePolicy = (LoadBalancePolicy)stream.readObject ();      
        HARMIServer server = (HARMIServer)HARMIServer.rmiServers.get (key);
        
        this.loadBalancePolicy.init (this);
        
        if (server != null)
        {
           synchronized(targets)
           {
              try
              {
                 targets = server.getReplicants ();
                 local = server.getLocal ();
              }
              catch (Exception ignored)
              {}
           }
        }
     }
     private void writeObject (java.io.ObjectOutputStream stream)
     throws IOException
     {
        stream.writeUTF (key);
        stream.writeObject (targets);
        stream.writeObject (loadBalancePolicy);
     }
     
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIProxy.java
  
  Index: HARMIProxy.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  public interface HARMIProxy extends java.io.Serializable
  {
     public boolean isLocal();
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIResponse.java
  
  Index: HARMIResponse.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  import java.util.ArrayList;
  
  public class HARMIResponse implements java.io.Serializable
  
  {
  
     public ArrayList newReplicants = null;
  
     public long tag = 0;
  
     public Object response = null;
  
  }
  
  
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/HARMIServer.java
  
  Index: HARMIServer.java
  ===================================================================
  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;
  
  /**
   *
   */
  public interface HARMIServer
     extends Remote
  {
     public HARMIResponse invoke(long tag, MarshalledObject mimo) throws Exception;
     public ArrayList getReplicants() throws Exception;
     public Object getLocal() throws Exception;
  
     public static Hashtable rmiServers = new Hashtable();
  
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/LoadBalancePolicy.java
  
  Index: LoadBalancePolicy.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  import java.util.ArrayList;
  
  public interface LoadBalancePolicy extends java.io.Serializable
  {
     // Init method called by the HARMIProxy so that the implementation
     // can use HARMIClient data to take its decision
     //
     public void init (HARMIClient father);
     
     public Object chooseTarget (ArrayList targets);
  }
  
  
  1.1                  
jbossmx/src/main/org/jboss/ha/framework/interfaces/RoundRobin.java
  
  Index: RoundRobin.java
  ===================================================================
  package org.jboss.ha.framework.interfaces;
  
  
  import java.util.ArrayList;
  
  
  public class RoundRobin implements LoadBalancePolicy
  {
     protected transient int cursorRemote = 0;
  
     public void init (HARMIClient father)
     {
        // do not use the HARMIClient in this policy
     }
     
     public Object chooseTarget(ArrayList targets)
     {
        cursorRemote = ( (cursorRemote + 1) % targets.size() );
        return targets.get(cursorRemote);
     }
  }
  
  

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

Reply via email to