User: slaboure
  Date: 01/11/26 07:04:50

  Modified:    src/main/org/jboss/ha/framework/server
                        DistributedStateImpl.java
  Log:
  No more remote, no more RMI exported.
  No more listening for membership changes.
  Added javadoc comments.
  Added Asynchronous calls to the partition when possible.
  Reordered content to fit in JBoss coding conventions.
  
  Revision  Changes    Path
  1.4       +107 -105  
jbossmx/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
  
  Index: DistributedStateImpl.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DistributedStateImpl.java 2001/11/26 03:24:51     1.3
  +++ DistributedStateImpl.java 2001/11/26 15:04:50     1.4
  @@ -1,160 +1,98 @@
  +/*
  + * JBoss, the OpenSource J2EE WebOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
   package org.jboss.ha.framework.server;
   
   
  -import java.util.Vector;
  +import java.io.Serializable;
   import java.util.ArrayList;
  -import java.util.HashMap;
  -import java.util.Iterator;
   import java.util.Collection;
  -
  -import java.rmi.server.RemoteStub;
  -import java.rmi.Remote;
  +import java.util.HashMap;
  +import java.util.Vector;
   import java.rmi.server.UnicastRemoteObject;
   
  -import java.io.Serializable;
  -
  -import org.jboss.logging.Logger;
  -
  +import org.jboss.ha.framework.interfaces.DistributedState.DSListener;
  +import org.jboss.ha.framework.interfaces.HAPartition.HAPartitionStateTransfer;
  +import org.jboss.ha.framework.interfaces.HAPartition.HAMembershipListener;
   import org.jboss.ha.framework.interfaces.DistributedState;
   import org.jboss.ha.framework.interfaces.HAPartition;
   
  -/** 
  +/**
    *   This class manages distributed state across the cluster.
    *
  - *   @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>
  + * <p><b>2001/11/26: Sacha Labourey</b>
  + * <ol>
  + *   <li>No more a remote object</li>
  + *   <li>No more listening for Membership changes (was doing nothing with the 
callback)</li>
  + * </ol>
    */
  -public class DistributedStateImpl 
  -   implements Remote, DistributedState,
  -              HAPartition.HAPartitionStateTransfer,
  -              HAPartition.HAMembershipListener
  +public class DistributedStateImpl
  +implements DistributedState, HAPartitionStateTransfer
   {
  +   // Constants -----------------------------------------------------
  +   
  +   protected final static String SERVICE_NAME = "DistributedState";
  +   
  +   // Attributes ----------------------------------------------------
  +   
      protected HashMap categories = new HashMap ();
      protected HashMap keyListeners = new HashMap ();
      protected HAPartition partition;
      
  -   protected final static String SERVICE_NAME = "DistributedState";
  +   protected org.jboss.logging.Logger log = null;
      
  -   protected Logger log = null;
  +   // Static --------------------------------------------------------
      
  +   // Constructors --------------------------------------------------
      
      public DistributedStateImpl (HAPartition partition)
      {
         this.partition = partition;
  -      this.log = Logger.getLogger (this.getClass ());
  +      this.log = org.jboss.logging.Logger.getLogger (this.getClass ());
      }
      
  +   // Public --------------------------------------------------------
  +   
      public void init () throws Exception
      {
         // When we subscribe to state transfer events, GetState will be called to 
initialize
         // this service.
         //
         partition.subscribeToStateTransferEvents (SERVICE_NAME, this);
  -      partition.registerMembershipListener (this);
  -      partition.registerRPCHandler (SERVICE_NAME, this);
  -      
  +      partition.registerRPCHandler (SERVICE_NAME, this);      
      }
      
      public void start () throws Exception
      {
  -      // Export myself as an RMI server
  -      //
  -      RemoteStub stub = UnicastRemoteObject.exportObject (this);
  -      
  -      // bind myself as a replicant service
  -      //
  -      partition.getDistributedReplicantManager ().add (SERVICE_NAME, stub);
      }
      
      public void stop () throws Exception
      {
  -      //partition.getDistributedReplicantManager ().remove (SERVICE_NAME); 
  -      UnicastRemoteObject.unexportObject (this, true);
  -   }
  -   
  -   /////////////////////
  -   // State transfer API
  -   /////////////////////
  -   public Serializable getCurrentState ()
  -   {
  -      return categories;
      }
      
  -   public void setCurrentState (Serializable newState)
  -   {
  -      synchronized (this.categories)
  -      {
  -         categories.clear ();
  -         categories.putAll ((HashMap)newState);
  -         if (keyListeners.size () > 0)
  -         {
  -            cleanupKeyListeners ();
  -         }
  -      }
  -   }
  -   
  -   ////////////////////
  -   // Group membership API
  -   ////////////////////
  -   public void membershipChanged (Vector deadMembers, Vector newMembers, Vector 
allMembers)
  -   {
  -      // If membership changes, this has no effect on the distributed state
  -      //
  -   }
  -   
  -   ///////////////
  -   // DistributedReplicantManager API
  -   ///////////////
  -   
  -   public void _set (String category, String key, Serializable value) throws 
Exception
  -   {
  -      synchronized(this.categories)
  -      {
  -         HashMap cat = (HashMap)categories.get (category);
  -         if (cat == null)
  -         {
  -            cat = new HashMap ();
  -            categories.put (category, cat);
  -         }
  -         cat.put (key, value);
  -         notifyKeyListeners (category, key, value);
  -      }
  -   }
  -   
  +   // DistributedState implementation ----------------------------------------------
  +
      public void set (String category, String key, Serializable value) throws 
Exception
      {
         Object[] args =
         {category, key, value};
  -      partition.callMethodOnCluster (SERVICE_NAME, "_set", args, false);
  -   }
  -   
  -   public void _remove (String category, String key) throws Exception
  -   {
  -      synchronized(this.categories)
  -      {
  -         HashMap cat = (HashMap)categories.get (category);
  -         if (cat == null) return;
  -         Object removed = cat.remove (key);
  -         if (removed != null)
  -         {
  -            notifyKeyListenersOfRemove (category, key, (Serializable)removed);
  -            if (cat.size () == 0)
  -            {
  -               categories.remove (category);
  -            }
  -         }
  -      }
  +      partition.callAsynchMethodOnCluster (SERVICE_NAME, "_set", args, false);
      }
      
  -   
      public void remove (String category, String key) throws Exception
      {
         Object[] args =
         {category, key};
  -      partition.callMethodOnCluster (SERVICE_NAME, "_remove", args, false);
  +      partition.callAsynchMethodOnCluster (SERVICE_NAME, "_remove", args, false);
         
      }
      
  @@ -200,7 +138,7 @@
      }
      
      
  -   public void registerDSListener (String category, DistributedState.DSListener 
subscriber)
  +   public void registerDSListener (String category, DSListener subscriber)
      {
         synchronized(this.keyListeners)
         {
  @@ -214,7 +152,7 @@
         }
      }
      
  -   public void unregisterDSListener (String category, DistributedState.DSListener 
subscriber)
  +   public void unregisterDSListener (String category, DSListener subscriber)
      {
         synchronized(this.keyListeners)
         {
  @@ -229,6 +167,65 @@
         }
      }
      
  +   // HAPartition RPC method invocations implementation 
----------------------------------------------
  +   
  +   public void _set (String category, String key, Serializable value) throws 
Exception
  +   {
  +      synchronized(this.categories)
  +      {
  +         HashMap cat = (HashMap)categories.get (category);
  +         if (cat == null)
  +         {
  +            cat = new HashMap ();
  +            categories.put (category, cat);
  +         }
  +         cat.put (key, value);
  +         notifyKeyListeners (category, key, value);
  +      }
  +   }
  +   
  +   public void _remove (String category, String key) throws Exception
  +   {
  +      synchronized(this.categories)
  +      {
  +         HashMap cat = (HashMap)categories.get (category);
  +         if (cat == null) return;
  +         Object removed = cat.remove (key);
  +         if (removed != null)
  +         {
  +            notifyKeyListenersOfRemove (category, key, (Serializable)removed);
  +            if (cat.size () == 0)
  +            {
  +               categories.remove (category);
  +            }
  +         }
  +      }
  +   }
  +      
  +   // HAPartitionStateTransfer implementation 
----------------------------------------------
  +   
  +   public Serializable getCurrentState ()
  +   {
  +      return categories;
  +   }
  +   
  +   public void setCurrentState (Serializable newState)
  +   {
  +      synchronized (this.categories)
  +      {
  +         categories.clear ();
  +         categories.putAll ((HashMap)newState);
  +         if (keyListeners.size () > 0)
  +         {
  +            cleanupKeyListeners ();
  +         }
  +      }
  +   }
  +      
  +   // Package protected ---------------------------------------------
  +   
  +   // Protected -----------------------------------------------------
  +   
      protected void notifyKeyListeners (String category, String key, Serializable 
value)
      {
         synchronized(this.keyListeners)
  @@ -263,4 +260,9 @@
      {
         // NOT IMPLEMENTED YET
      }
  +
  +   // Private -------------------------------------------------------
  +   
  +   // Inner classes -------------------------------------------------
  +      
   }
  
  
  

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

Reply via email to