You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ju...@apache.org on 2003/12/31 15:51:44 UTC

cvs commit: incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering LocalCluster.java LocalChannel.java DataListener.java DataDeltaListener.java DataDelta.java Cluster.java AbstractCluster.java

jules       2003/12/31 06:51:44

  Modified:    modules/clustering/src/java/org/apache/geronimo/clustering
                        LocalCluster.java LocalChannel.java
                        DataListener.java DataDeltaListener.java
                        DataDelta.java Cluster.java AbstractCluster.java
  Log:
  assimilation of David's migration to GeronimoMBeanTarget
  javadoc changes
  
  Revision  Changes    Path
  1.7       +109 -82   incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/LocalCluster.java
  
  Index: LocalCluster.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/LocalCluster.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LocalCluster.java	30 Dec 2003 21:16:03 -0000	1.6
  +++ LocalCluster.java	31 Dec 2003 14:51:44 -0000	1.7
  @@ -56,7 +56,6 @@
   package org.apache.geronimo.clustering;
   
   import java.util.List;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
  @@ -69,84 +68,112 @@
    *
    * @version $Revision$ $Date$
    */
  -public class LocalCluster
  -        extends AbstractCluster
  -        implements MetaDataListener, DataListener, DataDeltaListener {
  -    protected Log log = LogFactory.getLog(LocalCluster.class);
  -
  -    // LocalCluster
  -
  -    protected LocalChannel channel;
  -
  -    public List getMembers() {
  -        return channel.getMembers();
  -    }
  -
  -    public void join() {
  -        channel.join(this);
  -    }
  -
  -    public void leave() {
  -        channel.leave(this);
  -    }
  -
  -    public void doStart() {
  -        log = LogFactory.getLog(getClass().getName() + "#" + getName() + "/" + getNode());
  -        log.info("starting");
  -        channel = LocalChannel.find(getName());
  -        synchronized (channel) {
  -            setData(channel.getData());
  -            join();
  -        }
  -    }
  -
  -    public void doStop() {
  -        log.info("stopping");
  -        leave();
  -    }
  -
  -    public void doFail() {
  -        log.info("failing");
  -        leave();			// ??
  -    }
  -
  -    // MetaDataListener
  -    public void setMetaData(List members) {
  -        log.info("membership changed: " + members);
  -    }
  -
  -    // DataListener
  -    protected Data _data;
  -
  -    // TODO - should probably return byte[] - needs renaming
  -    public Data getData() {
  -        return _data;
  -    }
  -
  -    // TODO - should probably expect byte[] - needs renaming
  -    public void
  -            setData(Data data) {
  -        String xtra = "we must be the first node up";
  -
  -        if (data != null) {
  -            xtra = "we are joining an extant cluster";
  -            _data = data;
  -        } else {
  -            _data = new Data();
  -        }
  -
  -        log.debug("initialising data - " + xtra);
  -    }
  -
  -    // DataDeltaListener
  -    public void applyDataDelta(DataDelta delta) {
  -        log.trace("applying data delta - " + delta);
  -    }
  -
  -    public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
  -        GeronimoMBeanInfo mbeanInfo = AbstractCluster.getGeronimoMBeanInfo();
  -        mbeanInfo.setTargetClass(LocalCluster.class);
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Members", true, false, "List of cluster members"));
  -        return mbeanInfo;
  -    }
  +public class
  +  LocalCluster
  +  extends AbstractCluster
  +  implements MetaDataListener, DataListener, DataDeltaListener
  +{
  +  protected Log          _log=LogFactory.getLog(LocalCluster.class);
  +  protected LocalChannel _channel;
  +
  +  //----------------------------------------
  +  // LocalCluster
  +  //----------------------------------------
  +
  +  /**
  +   * Returns a List of current Cluster members.
  +   */
  +  public List getMembers(){return _channel.getMembers();}
  +
  +  //----------------------------------------
  +  // MetaDataListener
  +  //----------------------------------------
  +
  +  public void
  +    setMetaData(List members)
  +  {
  +    _log.info("membership changed: "+members);
  +  }
  +
  +  //----------------------------------------
  +  // DataListener
  +  //----------------------------------------
  +
  +  protected Data _data;
  +
  +  public Data getData() {return _data;}
  +
  +  public void
  +    setData(Data data)
  +  {
  +    String xtra="we must be the first node up";
  +
  +    if (data!=null)
  +    {
  +      xtra="we are joining an extant cluster";
  +      _data=data;
  +    }
  +    else
  +    {
  +      _data=new Data();
  +    }
  +
  +    _log.debug("initialising data - "+xtra);
  +  }
  +
  +  //----------------------------------------
  +  // DataDeltaListener
  +  //----------------------------------------
  +
  +  public void
  +    applyDataDelta(DataDelta delta)
  +  {
  +    _log.trace("applying data delta - "+delta);
  +  }
  +
  +  //----------------------------------------
  +  // GeronimoMBeanTarget
  +  //----------------------------------------
  +
  +  public void
  +    doStart()
  +  {
  +    _log=LogFactory.getLog(getClass().getName()+"#"+getName()+"/"+getNode());
  +    _log.info("starting");
  +    _channel=LocalChannel.find(getName());
  +    synchronized (_channel)
  +    {
  +      setData(_channel.getData());
  +      _channel.join(this);
  +    }
  +
  +    super.doStart();
  +  }
  +
  +  public void
  +    doStop()
  +  {
  +    super.doStop();
  +
  +    _log.info("stopping");
  +    _channel.leave(this);
  +  }
  +
  +  public void
  +    doFail()
  +  {
  +    super.doFail();
  +
  +    _log.info("failing");
  +    _channel.leave(this);	// TODO - ??
  +  }
  +
  +  public static GeronimoMBeanInfo
  +    getGeronimoMBeanInfo()
  +  {
  +    GeronimoMBeanInfo mbeanInfo=AbstractCluster.getGeronimoMBeanInfo();
  +    mbeanInfo.setTargetClass(LocalCluster.class);
  +    mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Members", true, false, "List of cluster members"));
  +    return mbeanInfo;
  +  }
   }
  
  
  
  1.4       +65 -3     incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/LocalChannel.java
  
  Index: LocalChannel.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/LocalChannel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalChannel.java	30 Dec 2003 15:32:20 -0000	1.3
  +++ LocalChannel.java	31 Dec 2003 14:51:44 -0000	1.4
  @@ -65,7 +65,9 @@
   import org.apache.commons.logging.LogFactory;
   
   /**
  - * A uniquely identifiable n->n intra-vm event-raising communications channel...
  + * A uniquely identifiable n->n intra-vm event-raising communications
  + * channel. A number of nodes which are part of the same cluster and
  + * reside in the same VM should share a single Channel object.
    *
    * @version $Revision$ $Date$
    */
  @@ -76,6 +78,12 @@
     protected static Log _log=LogFactory.getLog(LocalChannel.class);
     protected static Map _map=new HashMap();
   
  +  /**
  +   * Return either an existing Channel, or a freshly created one.
  +   *
  +   * @param name a <code>String</code> value
  +   * @return a <code>LocalChannel</code> value
  +   */
     public static LocalChannel
       find(String name)
     {
  @@ -103,12 +111,29 @@
     protected String _name;
     protected List   _members=new Vector();
   
  +
  +  /**
  +   * Creates a new <code>LocalChannel</code> instance.
  +   *
  +   * @param name a <code>String</code> value
  +   */
     protected LocalChannel(String name) {_name=name;}
   
  +  /**
  +   * Return current Channel members.
  +   *
  +   * @return a <code>List</code> value
  +   */
     public List getMembers(){synchronized (_members){return Collections.unmodifiableList(_members);}}
   
     // MetaData
   
  +  /**
  +   * Notify interested Cluster members of a change in membership,
  +   * including the node which generated it.
  +   *
  +   * @param members a <code>List</code> value
  +   */
     protected void
       notifyMembershipChanged(List members)
     {
  @@ -125,6 +150,11 @@
         }
     }
   
  +  /**
  +   * Add the given node to this Channel.
  +   *
  +   * @param member an <code>Object</code> value
  +   */
     public void
       join(Object member)
     {
  @@ -136,6 +166,11 @@
       }
     }
   
  +  /**
  +   * Remove the given node from this Channel.
  +   *
  +   * @param member an <code>Object</code> value
  +   */
     public void
       leave(Object member)
     {
  @@ -145,11 +180,17 @@
         notifyMembershipChanged(_members);
       }
   
  -    // last one out could turn out the lights...
  +    // last one out could turn off the lights...
     }
   
     // Data
   
  +  /**
  +   * Get the Cluster's Data - uses an election policy (currently
  +   * hardwired) to decide which node to get it from.
  +   *
  +   * @return a <code>Data</code> value - The data
  +   */
     public synchronized Data
       getData()
     {
  @@ -171,6 +212,27 @@
   	    return ((DataListener)member).getData();
   	}
   	return null;
  +      }
  +    }
  +  }
  +
  +  /**
  +   * Apply the given delta to all interested members of the cluster,
  +   * excluding the member which generated it.
  +   *
  +   * @param l a <code>DataDeltaListener</code> value - The node that generated the delta
  +   * @param delta a <code>DataDelta</code> value - The delta
  +   */
  +  public void
  +    notifyDataDelta(DataDeltaListener l, DataDelta delta)
  +  {
  +    synchronized (_members)
  +    {
  +      for (Iterator i=_members.iterator(); i.hasNext();)
  +      {
  +	Object member=i.next();
  +	if (member != l && member instanceof DataDeltaListener)
  +	  ((DataDeltaListener)member).applyDataDelta(delta);
         }
       }
     }
  
  
  
  1.3       +3 -5      incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataListener.java
  
  Index: DataListener.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DataListener.java	30 Dec 2003 15:32:20 -0000	1.2
  +++ DataListener.java	31 Dec 2003 14:51:44 -0000	1.3
  @@ -69,15 +69,13 @@
     /**
      * Called by Cluster to retrieve current Cluster state.
      *
  -   * @param state an <code>Object</code> to be used as the
  -   * node's initial state.
      */
     public Data getData();
     /**
      * Called by Cluster to initialise the state of a [new] node.
      *
  -   * @param state an <code>Object</code> to be used as the
  -   * node's initial state.
  +   * @param state <code>Data</code> to be used as the node's initial
  +   * state.
      */
     public void setData(Data state);
   }
  
  
  
  1.3       +4 -4      incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataDeltaListener.java
  
  Index: DataDeltaListener.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataDeltaListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DataDeltaListener.java	30 Dec 2003 15:32:20 -0000	1.2
  +++ DataDeltaListener.java	31 Dec 2003 14:51:44 -0000	1.3
  @@ -67,10 +67,10 @@
     DataDeltaListener
   {
     /**
  -   * Called by Cluster to initialise the state of a [new] node.
  +   * Called by Cluster to notify node of a change to Cluster state.
      *
  -   * @param delta a <code>Object</code> delta to be applied to the
  -   * nodes current state.
  +   * @param delta a <code>DataDelta</code> to be applied to the node's
  +   * current state.
      */
     public void applyDataDelta(DataDelta delta);
   }
  
  
  
  1.2       +7 -1      incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataDelta.java
  
  Index: DataDelta.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataDelta.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataDelta.java	30 Dec 2003 15:32:20 -0000	1.1
  +++ DataDelta.java	31 Dec 2003 14:51:44 -0000	1.2
  @@ -64,5 +64,11 @@
   public abstract class
     DataDelta
   {
  +  /**
  +   * Apply the enclosed delta to the Data arg.
  +   *
  +   * @param data a <code>Data</code> value - The Data to which to
  +   * apply the delta.
  +   */
     public abstract void apply(Data data);
   }
  
  
  
  1.4       +5 -2      incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/Cluster.java
  
  Index: Cluster.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/Cluster.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Cluster.java	30 Dec 2003 21:16:03 -0000	1.3
  +++ Cluster.java	31 Dec 2003 14:51:44 -0000	1.4
  @@ -60,7 +60,10 @@
   /**
    * A 'Cluster' is the in-vm representative of a Cluster of Geronimo
    * nodes. The particular cluster to which it belongs is identified by
  - * it's 'name' property.
  + * it's 'name' property. I hope to support different types of cluster
  + * including (initially) SimpleCluster, in which every node replicates
  + * every other node and CleverCluster, which automagically partitions
  + * data into SubClusters etc...
    *
    * @version $Revision$ $Date$
    */
  
  
  
  1.5       +65 -56    incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/AbstractCluster.java
  
  Index: AbstractCluster.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/AbstractCluster.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractCluster.java	30 Dec 2003 21:16:03 -0000	1.4
  +++ AbstractCluster.java	31 Dec 2003 14:51:44 -0000	1.5
  @@ -71,59 +71,68 @@
    *
    * @version $Revision$ $Date$
    */
  -public abstract class AbstractCluster implements Cluster, GeronimoMBeanTarget {
  -    protected static Log _log = LogFactory.getLog(AbstractCluster.class);
  -    private ObjectName objectName;
  -
  -    public String getName() {
  -        String name = objectName.getKeyProperty("name");
  -
  -        if (name == null) {
  -            name = "GERONIMO";
  -            _log.warn("MBean name should contain 'name' property - defaulting to: " + name);
  -        }
  -
  -        return name;
  -    }
  -
  -    public String getNode() {
  -        String node = objectName.getKeyProperty("node");
  -
  -        if (node == null) {
  -            node = "0";
  -            _log.warn("MBean name should contain 'node' property - defaulting to: " + node);
  -        }
  -
  -        return node;
  -    }
  -
  -    public void setMBeanContext(GeronimoMBeanContext context) {
  -        objectName = (context == null)? null:context.getObjectName();
  -    }
  -
  -    public boolean canStart() {
  -        return true;
  -    }
  -
  -    public void doStart() {
  -    }
  -
  -    public boolean canStop() {
  -        return true;
  -    }
  -
  -    public void doStop() {
  -    }
  -
  -    public void doFail() {
  -    }
  -
  -    public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
  -        GeronimoMBeanInfo mbeanInfo = new GeronimoMBeanInfo();
  -        //set target class in concrete subclass
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Name", true, false, "Name of cluster we are a part of"));
  -        mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Node", true, false, "Node id within the cluster"));
  -        return mbeanInfo;
  -
  -    }
  +public abstract class
  +  AbstractCluster
  +  implements Cluster, GeronimoMBeanTarget
  +{
  +  protected static Log _log=LogFactory.getLog(AbstractCluster.class);
  +  protected ObjectName _objectName;
  +
  +  //----------------------------------------
  +  // Cluster
  +  //----------------------------------------
  +
  +  public String
  +    getName()
  +  {
  +    String name=_objectName.getKeyProperty("name");
  +
  +    if (name==null)
  +    {
  +      name="GERONIMO";
  +      _log.warn("MBean name should contain 'name' property - defaulting to: "+name);
  +    }
  +
  +    return name;
  +  }
  +
  +  public String
  +    getNode()
  +  {
  +    String node=_objectName.getKeyProperty("node");
  +
  +    if (node==null)
  +    {
  +      node="0";
  +      _log.warn("MBean name should contain 'node' property - defaulting to: "+node);
  +    }
  +
  +    return node;
  +  }
  +
  +  //----------------------------------------
  +  // GeronimoMBeanTarget
  +  //----------------------------------------
  +
  +  public boolean canStart() {return true;}
  +  public void doStart() {}
  +  public boolean canStop() {return true;}
  +  public void doStop() {}
  +  public void doFail() {}
  +
  +  public void
  +    setMBeanContext(GeronimoMBeanContext context)
  +  {
  +    _objectName=(context==null)?null:context.getObjectName();
  +  }
  +
  +  public static GeronimoMBeanInfo
  +    getGeronimoMBeanInfo()
  +  {
  +    GeronimoMBeanInfo mbeanInfo=new GeronimoMBeanInfo();
  +    //set target class in concrete subclass
  +    mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Name", true, false, "Name of cluster we are a part of"));
  +    mbeanInfo.addAttributeInfo(new GeronimoAttributeInfo("Node", true, false, "Node id within the cluster"));
  +    return mbeanInfo;
  +  }
   }