User: slaboure
  Date: 01/12/29 08:11:43

  Modified:    src/main/org/jboss/ha/framework/server
                        DistributedStateImpl.java
  Log:
  - possibility to know if a modification has been done locally or initiated from 
another node
  - remove now returns the old value
  - DistributedStateImpl is now registred as a standard MBean
  - we no more use asynch calls (usefull for HTTPSession clustering). This should be 
made optional by the user code
  
  Revision  Changes    Path
  1.5       +55 -16    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DistributedStateImpl.java 2001/11/26 15:04:50     1.4
  +++ DistributedStateImpl.java 2001/12/29 16:11:43     1.5
  @@ -15,6 +15,9 @@
   import java.util.Vector;
   import java.rmi.server.UnicastRemoteObject;
   
  +import javax.management.MBeanServer;
  +import javax.management.ObjectName;
  +
   import org.jboss.ha.framework.interfaces.DistributedState.DSListener;
   import org.jboss.ha.framework.interfaces.HAPartition.HAPartitionStateTransfer;
   import org.jboss.ha.framework.interfaces.HAPartition.HAMembershipListener;
  @@ -26,7 +29,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><br>
    * <p><b>2001/11/26: Sacha Labourey</b>
  @@ -36,7 +39,7 @@
    * </ol>
    */
   public class DistributedStateImpl
  -implements DistributedState, HAPartitionStateTransfer
  +implements DistributedStateImplMBean, HAPartitionStateTransfer
   {
      // Constants -----------------------------------------------------
      
  @@ -49,14 +52,19 @@
      protected HAPartition partition;
      
      protected org.jboss.logging.Logger log = null;
  +   
  +   protected MBeanServer mbeanServer = null;
      
  -   // Static --------------------------------------------------------
  +   // Static --------------------------------------------------------c
      
      // Constructors --------------------------------------------------
      
  -   public DistributedStateImpl (HAPartition partition)
  +   public DistributedStateImpl () {} // for JMX checks
  +   
  +   public DistributedStateImpl (HAPartition partition, MBeanServer server)
      {
         this.partition = partition;
  +      this.mbeanServer = server;
         this.log = org.jboss.logging.Logger.getLogger (this.getClass ());
      }
      
  @@ -68,7 +76,18 @@
         // this service.
         //
         partition.subscribeToStateTransferEvents (SERVICE_NAME, this);
  -      partition.registerRPCHandler (SERVICE_NAME, this);      
  +      partition.registerRPCHandler (SERVICE_NAME, this);  
  +      
  +      // subscribed this "sub-service" of HAPartition with JMX
  +      // TODO: In the future (when state transfer issues will be completed), 
  +      // we will need to redesign the way HAPartitions and its sub-protocols are
  +      // registered with JMX. They will most probably be independant JMX services.
  +      //
  +      String name = "JBOSS-SYSTEM:service=" + SERVICE_NAME + 
  +                    ",partitionName=" + this.partition.getPartitionName();
  +      ObjectName jmxName = new ObjectName(name);
  +      mbeanServer.registerMBean(this, jmxName);
  +      org.jboss.system.Registry.bind (name, this);
      }
      
      public void start () throws Exception
  @@ -77,6 +96,9 @@
      
      public void stop () throws Exception
      {
  +      String name = "JBOSS-SYSTEM:service=" + SERVICE_NAME + 
  +                    ",partitionName=" + this.partition.getPartitionName();
  +      org.jboss.system.Registry.unbind (name);
      }
      
      // DistributedState implementation ----------------------------------------------
  @@ -85,15 +107,21 @@
      {
         Object[] args =
         {category, key, value};
  -      partition.callAsynchMethodOnCluster (SERVICE_NAME, "_set", args, false);
  +      partition.callMethodOnCluster (SERVICE_NAME, "_set", args, true);
  +      this._setInternal (category, key, value);
  +      notifyKeyListeners (category, key, value, true);
      }
      
  -   public void remove (String category, String key) throws Exception
  +   public Serializable remove (String category, String key) throws Exception
      {
         Object[] args =
         {category, key};
  -      partition.callAsynchMethodOnCluster (SERVICE_NAME, "_remove", args, false);
  +      partition.callMethodOnCluster (SERVICE_NAME, "_remove", args, true);
  +
  +      Serializable removed = this._removeInternal (category, key);
  +      notifyKeyListenersOfRemove (category, key, removed , true);
         
  +      return removed ;      
      }
      
      public Serializable get (String category, String key)
  @@ -171,6 +199,12 @@
      
      public void _set (String category, String key, Serializable value) throws 
Exception
      {
  +      this._setInternal (category, key, value);
  +      notifyKeyListeners (category, key, value, false);
  +   }
  +   
  +   public void _setInternal (String category, String key, Serializable value) 
throws Exception
  +   {
         synchronized(this.categories)
         {
            HashMap cat = (HashMap)categories.get (category);
  @@ -180,25 +214,30 @@
               categories.put (category, cat);
            }
            cat.put (key, value);
  -         notifyKeyListeners (category, key, value);
         }
      }
      
  -   public void _remove (String category, String key) throws Exception
  +   public void _remove (String category, String key, boolean local) throws Exception
  +   {
  +      Serializable removed = this._removeInternal (category, key);
  +      notifyKeyListenersOfRemove (category, key, removed, false);
  +   }
  +      
  +   public Serializable _removeInternal (String category, String key) throws 
Exception
      {
         synchronized(this.categories)
         {
            HashMap cat = (HashMap)categories.get (category);
  -         if (cat == null) return;
  +         if (cat == null) return null;
            Object removed = cat.remove (key);
            if (removed != null)
            {
  -            notifyKeyListenersOfRemove (category, key, (Serializable)removed);
               if (cat.size () == 0)
               {
                  categories.remove (category);
               }
            }
  +         return (Serializable)removed;
         }
      }
         
  @@ -226,7 +265,7 @@
      
      // Protected -----------------------------------------------------
      
  -   protected void notifyKeyListeners (String category, String key, Serializable 
value)
  +   protected void notifyKeyListeners (String category, String key, Serializable 
value, boolean locallyModified)
      {
         synchronized(this.keyListeners)
         {
  @@ -236,12 +275,12 @@
            for (int i = 0; i < listeners.size (); i++)
            {
               DistributedState.DSListener listener = 
(DistributedState.DSListener)listeners.get (i);
  -            listener.valueHasChanged (category, key, value);
  +            listener.valueHasChanged (category, key, value, locallyModified);
            }
         }
      }
      
  -   protected void notifyKeyListenersOfRemove (String category, String key, 
Serializable oldContent)
  +   protected void notifyKeyListenersOfRemove (String category, String key, 
Serializable oldContent, boolean locallyModified)
      {
         synchronized(this.keyListeners)
         {
  @@ -251,7 +290,7 @@
            for (int i = 0; i < listeners.size (); i++)
            {
               DistributedState.DSListener listener = 
(DistributedState.DSListener)listeners.get (i);
  -            listener.keyHasBeenRemoved (category, key, oldContent);
  +            listener.keyHasBeenRemoved (category, key, oldContent, locallyModified);
            }
         }
      }
  
  
  

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

Reply via email to