geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject cvs commit: incubator-geronimo/modules/clustering/src/deploy clustering-service.xml
Date Mon, 29 Dec 2003 18:50:12 GMT
jules       2003/12/29 10:50:12

  Modified:    modules/clustering/src/java/org/apache/geronimo/clustering
                        LocalCluster.java AbstractCluster.java
               modules/clustering/src/deploy clustering-service.xml
  Added:       modules/clustering/src/java/org/apache/geronimo/clustering
                        MembershipChangedListener.java LocalChannel.java
  Log:
  abstracted out Channel
  added first cut of membershipChanged and initialState protocols
  configured for two clusters - GERONIMO (3 nodes), GERONIMO2 (2 nodes)
  
  Revision  Changes    Path
  1.3       +68 -12    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocalCluster.java	28 Dec 2003 19:12:51 -0000	1.2
  +++ LocalCluster.java	29 Dec 2003 18:50:11 -0000	1.3
  @@ -58,6 +58,10 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import java.util.Vector;
  +import java.util.List;
  +import java.util.Collections;
  +
   /**
    * An initial Cluster impl, which only clusters within a single
    * VM. Thus development on Clustering can start before an inter-vm
  @@ -69,35 +73,87 @@
   public class
     LocalCluster
     extends AbstractCluster
  -  implements LocalClusterMBean
  +  implements LocalClusterMBean, MembershipChangedListener
   {
  -  protected Log _log=LogFactory.getLog(Cluster.class);
  +  protected Log _log=LogFactory.getLog(LocalCluster.class);
  +
  +
  +  // LocalCluster
   
  +  protected LocalChannel _channel;
  +
  +  /**
  +   * @jmx.managed-attribute
  +   */
  +  public List getMembers(){return _channel.getMembers();}
  +
  +  public void join()  {_channel.join(this);}
  +  public void leave() {_channel.leave(this);}
  +
  +  // StateManageable
     public boolean canStart() {return true;}
     public boolean canStop()  {return true;}
   
     public void
       doStart()
       {
  -      _log=LogFactory.getLog(getClass().getName()+"#"+getName());
  -      _log.info("starting Clustering Service");
  +      _log=LogFactory.getLog(getClass().getName()+"#"+getName()+"/"+getNode());
  +      _log.info("starting");
  +      _channel=LocalChannel.find(getName());
  +      synchronized (_channel)
  +      {
  +	setCurrentState(_channel.getCurrentState());
  +	join();
  +      }
       }
   
     public void
       doStop()
       {
  -      _log.info("stopping Clustering Service");
  +      _log.info("stopping");
  +      leave();
       }
   
     public void
       doFail()
       {
  -      _log.info("failing Clustering Service");
  +      _log.info("failing");
  +      leave();			// ??
       }
   
  -  //----------------------------------------
  -  /**
  -   * @jmx.managed-operation
  -   */
  -  public String test(){return getName();}
  +  // MembershipChangedListener
  +  public void
  +    membershipChanged(List newMembers)
  +    {
  +      _log.info("membership changed: "+newMembers);
  +    }
  +
  +  // initial state
  +  protected Object _currentState;
  +
  +  // TODO - should probably return byte[] - needs renaming
  +  protected Object
  +    getCurrentState()
  +    {
  +      return _currentState;
  +    }
  +
  +  // TODO - should probably expect byte[] - needs renaming
  +  protected void
  +    setCurrentState(Object currentState)
  +    {
  +      String xtra="we must be the first node up";
  +
  +      if (currentState!=null)
  +      {
  +	xtra="we are joining an extant cluster";
  +	_currentState=currentState;
  +      }
  +      else
  +      {
  +	_currentState=new Object();
  +      }
  +
  +      _log.debug("initialising state - "+xtra);
  +    }
   }
  
  
  
  1.3       +18 -1     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractCluster.java	28 Dec 2003 19:12:51 -0000	1.2
  +++ AbstractCluster.java	29 Dec 2003 18:50:11 -0000	1.3
  @@ -93,4 +93,21 @@
   
         return name;
       }
  +
  +  /**
  +   * @jmx.managed-attribute
  +   */
  +  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;
  +    }
   }
  
  
  
  1.1                  incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/MembershipChangedListener.java
  
  Index: MembershipChangedListener.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.clustering;
  
  import java.util.List;
  
  /**
   * An initial Cluster impl, which only clusters within a single
   * VM. Thus development on Clustering can start before an inter-vm
   * transport layer has been put in place...
   *
   * @jmx:mbean extends="org.apache.geronimo.clustering.AbstractClusterMBean"
   * @version $Revision: 1.1 $ $Date: 2003/12/29 18:50:11 $
   */
  public interface
    MembershipChangedListener
  {
    // this is better than a memberLeft/memberJoined notification as it
    // can handle multiple concurrent leave/joins, this may occur in the
    // case of event elysion...
    public void membershipChanged(List newMembers);
  }
  
  
  
  1.1                  incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/LocalChannel.java
  
  Index: LocalChannel.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.clustering;
  
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Vector;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * A uniquely identifiable n->n intra-vm event-raising communications channel...
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/29 18:50:11 $
   */
  public class
    LocalChannel
  {
    // class
    protected static Log _log=LogFactory.getLog(LocalChannel.class);
    protected static Map _map=new HashMap();
  
    public static LocalChannel
      find(String name)
      {
        synchronized (_map)
        {
  	LocalChannel channel=(LocalChannel)_map.get(name);
  
  	if (channel==null)
  	{
  	  channel=new LocalChannel(name);
  	  _map.put(name, channel);
  
  	  _log.trace("created channel: "+name);
  	}
  	else
  	{
  	  _log.trace("found channel: "+name);
  	}
  
  	return channel;
        }
      }
  
    // instance
    protected String _name;
    protected List   _members=new Vector();
  
    protected LocalChannel(String name) {_name=name;}
  
    public List getMembers(){synchronized (_members){return Collections.unmodifiableList(_members);}}
  
    // membership
  
    protected void
      notifyMembershipChanged(List members)
      {
        for (Iterator i=members.iterator(); i.hasNext();)
  	try
  	{
  	  ((MembershipChangedListener)i.next()).membershipChanged(members);
  	}
  	catch (Exception e)
  	{
  	  _log.warn("problem notifying membership changed", e);
  	}
      }
  
    public void
      join(MembershipChangedListener member)
      {
        // first one in could turn on the lights...
        synchronized (_members)
        {
  	_members.add(member);
  	notifyMembershipChanged(_members);
        }
      }
  
    public void
      leave(MembershipChangedListener member)
      {
        synchronized (_members)
        {
  	_members.remove(member);
  	notifyMembershipChanged(_members);
        }
  
        // last one out could turn out the lights...
      }
  
    // state
  
    public synchronized Object
      getCurrentState()
      {
        // TODO - we need a pluggable election policy to decide who will
        // be asked for state...
  
        synchronized (_members)
        {
  	if (_members.isEmpty())
  	  return null;
  	else
  	  // TODO - we need to do a deep copy of the state here -
  	  // serialise and deserialise...
  	  return ((LocalCluster)_members.get(0)).getCurrentState();
        }
      }
  }
  
  
  
  1.2       +25 -1     incubator-geronimo/modules/clustering/src/deploy/clustering-service.xml
  
  Index: clustering-service.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/clustering/src/deploy/clustering-service.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- clustering-service.xml	28 Dec 2003 16:10:19 -0000	1.1
  +++ clustering-service.xml	29 Dec 2003 18:50:11 -0000	1.2
  @@ -18,7 +18,31 @@
   
     <mbean
       code="org.apache.geronimo.clustering.LocalCluster"
  -    name="geronimo.clustering:role=Cluster,name=GERONIMO"
  +    name="geronimo.clustering:role=Cluster,name=GERONIMO,node=0"
  +    >
  +  </mbean>
  +
  +  <mbean
  +    code="org.apache.geronimo.clustering.LocalCluster"
  +    name="geronimo.clustering:role=Cluster,name=GERONIMO,node=1"
  +    >
  +  </mbean>
  +
  +  <mbean
  +    code="org.apache.geronimo.clustering.LocalCluster"
  +    name="geronimo.clustering:role=Cluster,name=GERONIMO,node=2"
  +    >
  +  </mbean>
  +
  +  <mbean
  +    code="org.apache.geronimo.clustering.LocalCluster"
  +    name="geronimo.clustering:role=Cluster,name=GERONIMO2,node=0"
  +    >
  +  </mbean>
  +
  +  <mbean
  +    code="org.apache.geronimo.clustering.LocalCluster"
  +    name="geronimo.clustering:role=Cluster,name=GERONIMO2,node=1"
       >
     </mbean>
   
  
  
  

Mime
View raw message