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/30 15:54:38 UTC

cvs commit: incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering MetaDataListener.java DataListener.java DataDeltaListener.java LocalCluster.java LocalChannel.java MembershipChangedListener.java

jules       2003/12/30 06:54:38

  Modified:    modules/clustering/src/java/org/apache/geronimo/clustering
                        LocalCluster.java LocalChannel.java
  Added:       modules/clustering/src/java/org/apache/geronimo/clustering
                        MetaDataListener.java DataListener.java
                        DataDeltaListener.java
  Removed:     modules/clustering/src/java/org/apache/geronimo/clustering
                        MembershipChangedListener.java
  Log:
  rationalise existing listeners
  introduce new DataDeltaListener
  
  Revision  Changes    Path
  1.4       +47 -45    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalCluster.java	29 Dec 2003 18:50:11 -0000	1.3
  +++ LocalCluster.java	30 Dec 2003 14:54:38 -0000	1.4
  @@ -73,11 +73,10 @@
   public class
     LocalCluster
     extends AbstractCluster
  -  implements LocalClusterMBean, MembershipChangedListener
  +  implements LocalClusterMBean, MetaDataListener, DataListener, DataDeltaListener
   {
     protected Log _log=LogFactory.getLog(LocalCluster.class);
   
  -
     // LocalCluster
   
     protected LocalChannel _channel;
  @@ -96,64 +95,67 @@
   
     public void
       doStart()
  +  {
  +    _log=LogFactory.getLog(getClass().getName()+"#"+getName()+"/"+getNode());
  +    _log.info("starting");
  +    _channel=LocalChannel.find(getName());
  +    synchronized (_channel)
       {
  -      _log=LogFactory.getLog(getClass().getName()+"#"+getName()+"/"+getNode());
  -      _log.info("starting");
  -      _channel=LocalChannel.find(getName());
  -      synchronized (_channel)
  -      {
  -	setCurrentState(_channel.getCurrentState());
  -	join();
  -      }
  +      setData(_channel.getData());
  +      join();
       }
  +  }
   
     public void
       doStop()
  -    {
  -      _log.info("stopping");
  -      leave();
  -    }
  +  {
  +    _log.info("stopping");
  +    leave();
  +  }
   
     public void
       doFail()
  -    {
  -      _log.info("failing");
  -      leave();			// ??
  -    }
  +  {
  +    _log.info("failing");
  +    leave();			// ??
  +  }
   
  -  // MembershipChangedListener
  +  // MetaDataListener
     public void
  -    membershipChanged(List newMembers)
  -    {
  -      _log.info("membership changed: "+newMembers);
  -    }
  +    setMetaData(List members)
  +  {
  +    _log.info("membership changed: "+members);
  +  }
   
  -  // initial state
  -  protected Object _currentState;
  +  // DataListener
  +  protected Object _data;
   
     // TODO - should probably return byte[] - needs renaming
  -  protected Object
  -    getCurrentState()
  -    {
  -      return _currentState;
  -    }
  +  public Object getData() {return _data;}
   
     // TODO - should probably expect byte[] - needs renaming
  -  protected void
  -    setCurrentState(Object currentState)
  +  public void
  +    setData(Object data)
  +  {
  +    String xtra="we must be the first node up";
  +
  +    if (data!=null)
  +    {
  +      xtra="we are joining an extant cluster";
  +      _data=data;
  +    }
  +    else
       {
  -      String xtra="we must be the first node up";
  +      _data=new Object();
  +    }
   
  -      if (currentState!=null)
  -      {
  -	xtra="we are joining an extant cluster";
  -	_currentState=currentState;
  -      }
  -      else
  -      {
  -	_currentState=new Object();
  -      }
  +    _log.debug("initialising data - "+xtra);
  +  }
   
  -      _log.debug("initialising state - "+xtra);
  -    }
  +  // DataDeltaListener
  +  public void
  +    applyDataDelta(Object delta)
  +  {
  +    _log.trace("applying data delta - "+delta);
  +  }
   }
  
  
  
  1.2       +63 -53    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalChannel.java	29 Dec 2003 18:50:11 -0000	1.1
  +++ LocalChannel.java	30 Dec 2003 14:54:38 -0000	1.2
  @@ -78,26 +78,26 @@
   
     public static LocalChannel
       find(String name)
  +  {
  +    synchronized (_map)
       {
  -      synchronized (_map)
  -      {
  -	LocalChannel channel=(LocalChannel)_map.get(name);
  -
  -	if (channel==null)
  -	{
  -	  channel=new LocalChannel(name);
  -	  _map.put(name, channel);
  +      LocalChannel channel=(LocalChannel)_map.get(name);
   
  -	  _log.trace("created channel: "+name);
  -	}
  -	else
  -	{
  -	  _log.trace("found channel: "+name);
  -	}
  +      if (channel==null)
  +      {
  +	channel=new LocalChannel(name);
  +	_map.put(name, channel);
   
  -	return channel;
  +	_log.trace("created channel: "+name);
         }
  +      else
  +      {
  +	_log.trace("found channel: "+name);
  +      }
  +
  +      return channel;
       }
  +  }
   
     // instance
     protected String _name;
  @@ -107,61 +107,71 @@
   
     public List getMembers(){synchronized (_members){return Collections.unmodifiableList(_members);}}
   
  -  // membership
  +  // MetaData
   
     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);
  -	}
  -    }
  +  {
  +    for (Iterator i=members.iterator(); i.hasNext();)
  +      try
  +      {
  +	Object member=i.next();
  +	if (member instanceof MetaDataListener)
  +	  ((MetaDataListener)member).setMetaData(members);
  +      }
  +      catch (Exception e)
  +      {
  +	_log.warn("problem notifying membership changed", e);
  +      }
  +  }
   
     public void
  -    join(MembershipChangedListener member)
  +    join(Object member)
  +  {
  +    // first one in could turn on the lights...
  +    synchronized (_members)
       {
  -      // first one in could turn on the lights...
  -      synchronized (_members)
  -      {
  -	_members.add(member);
  -	notifyMembershipChanged(_members);
  -      }
  +      _members.add(member);
  +      notifyMembershipChanged(_members);
       }
  +  }
   
     public void
  -    leave(MembershipChangedListener member)
  +    leave(Object member)
  +  {
  +    synchronized (_members)
       {
  -      synchronized (_members)
  -      {
  -	_members.remove(member);
  -	notifyMembershipChanged(_members);
  -      }
  -
  -      // last one out could turn out the lights...
  +      _members.remove(member);
  +      notifyMembershipChanged(_members);
       }
   
  -  // state
  +    // last one out could turn out the lights...
  +  }
  +
  +  // Data
   
     public synchronized Object
  -    getCurrentState()
  -    {
  -      // TODO - we need a pluggable election policy to decide who will
  -      // be asked for state...
  +    getData()
  +  {
  +    // TODO - we need a pluggable election policy to decide who will
  +    // be asked for state...
   
  -      synchronized (_members)
  +    synchronized (_members)
  +    {
  +      if (_members.isEmpty())
  +	return null;
  +      else
         {
  -	if (_members.isEmpty())
  -	  return null;
  -	else
  +	for (Iterator i=_members.iterator(); i.hasNext();)
  +	{
  +	  Object member=i.next();
   	  // TODO - we need to do a deep copy of the state here -
   	  // serialise and deserialise...
  -	  return ((LocalCluster)_members.get(0)).getCurrentState();
  +	  if (member instanceof DataListener)
  +	    return ((DataListener)member).getData();
  +	}
  +	return null;
         }
       }
  +  }
   }
  
  
  
  1.1                  incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/MetaDataListener.java
  
  Index: MetaDataListener.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 interface implemented by components that wish to be notified
   * upon membership of a Cluster changing.
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/30 14:54:38 $
   */
  public interface
    MetaDataListener
  {
    /**
     * Called by Cluster when a change in membership occurs. 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...
     *
     * @param members a <code>List</code> of members.
     */
    public void setMetaData(List members);
  }
  
  
  
  1.1                  incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataListener.java
  
  Index: DataListener.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 interface implemented by components that wish to have their
   * state initialised from the Cluster.
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/30 14:54:38 $
   */
  public interface
    DataListener
  {
    /**
     * Called by Cluster to retrieve current Cluster state.
     *
     * @param state an <code>Object</code> to be used as the
     * node's initial state.
     */
    public Object 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.
     */
    public void setData(Object state);
  }
  
  
  
  1.1                  incubator-geronimo/modules/clustering/src/java/org/apache/geronimo/clustering/DataDeltaListener.java
  
  Index: DataDeltaListener.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 interface implemented by components that wish to have their
   * state initialised from the Cluster.
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/30 14:54:38 $
   */
  public interface
    DataDeltaListener
  {
    /**
     * Called by Cluster to initialise the state of a [new] node.
     *
     * @param delta a <code>Object</code> delta to be applied to the
     * nodes current state.
     */
    public void applyDataDelta(Object delta);
  }