bip         01/05/06 19:14:10

  Modified:    catalina/src/share/org/apache/catalina/cluster
                        MulticastReceiver.java MulticastSender.java
                        StandardCluster.java
  Added:       catalina/src/share/org/apache/catalina/cluster
                        ClusterReceiver.java ClusterSender.java
                        ClusterSessionBase.java
  Log:
  Made the Cluster package pluggable, StandardCluster is a Standard implementation
  of a Cluster. It uses MulticastSocket to communicate within the Cluster.
  
  If a new Cluster which uses a different protocol are to be added it need to
  implement org.apache.catalina.Cluster and the sender/receiver classes must
  implement org.apache.catalina.cluster.[ClusterSender/ClusterReceiver].
  
  Logging and some minor additions have been added.
  
  Revision  Changes    Path
  1.2       +46 -11    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastReceiver.java
  
  Index: MulticastReceiver.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastReceiver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MulticastReceiver.java    2001/05/04 20:48:01     1.1
  +++ MulticastReceiver.java    2001/05/07 02:14:10     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastReceiver.java,v
 1.1 2001/05/04 20:48:01 bip Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/05/04 20:48:01 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastReceiver.java,v
 1.2 2001/05/07 02:14:10 bip Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/07 02:14:10 $
    *
    * ====================================================================
    *
  @@ -84,14 +84,14 @@
    * it onto an internal stack and let it be picked up when needed.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $, $Date: 2001/05/07 02:14:10 $
    */
   
  -public class MulticastReceiver implements Runnable {
  +public final class MulticastReceiver
  +    extends ClusterSessionBase implements ClusterReceiver {
   
       // ----------------------------------------------------- Instance Variables
   
  -
       /**
        * The unique message ID
        */
  @@ -108,6 +108,11 @@
       private String threadName = "MulticastReceiver";
   
       /**
  +     * The name of our component, used for logging.
  +     */
  +    private String receiverName = "MulticastReceiver";
  +
  +    /**
        * The stack that keeps incoming requests
        */
       private static Vector stack = new Vector();
  @@ -146,8 +151,38 @@
           this.senderId = senderId;
       }
   
  +    /**
  +     * Return a <code>String</code> containing the name of this
  +     * implementation, used for logging
  +     *
  +     * @return The name of the implementation
  +     */
  +    public String getName() {
  +        return(this.receiverName);
  +    }
  +
  +    /**
  +     * Set the time in seconds for this component to
  +     * Sleep before it checks for new received data in the Cluster
  +     *
  +     * @param checkInterval The time to sleep
  +     */
  +    public void setCheckInterval(int checkInterval) {
  +        this.checkInterval = checkInterval;
  +    }
  +
  +    /**
  +     * Get the time in seconds this Cluster sleeps
  +     *
  +     * @return The time in seconds this Cluster sleeps
  +     */
  +    public int getCheckInterval() {
  +        return(this.checkInterval);
  +    }
  +
       /**
  -     * Receive the objects currently in our stack
  +     * Receive the objects currently in our stack and clear
  +     * if afterwards.
        *
        * @return An array with objects
        */
  @@ -199,11 +234,11 @@
               if(obj.getSenderId().equals(this.senderId))
                   stack.add(obj);
           } catch (IOException e) {
  -            System.out.println("An error occured when trying to replicate: "+
  -                               e.toString());
  +            log("An error occured when trying to replicate: "+
  +                e.toString());
           } catch (ClassNotFoundException e) {
  -            System.out.println("An error occured when trying to replicate: "+
  -                               e.toString());
  +            log("An error occured when trying to replicate: "+
  +                e.toString());
           }
       }
   
  
  
  
  1.2       +50 -12    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastSender.java
  
  Index: MulticastSender.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastSender.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MulticastSender.java      2001/05/04 20:48:01     1.1
  +++ MulticastSender.java      2001/05/07 02:14:10     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastSender.java,v
 1.1 2001/05/04 20:48:01 bip Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/05/04 20:48:01 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/MulticastSender.java,v
 1.2 2001/05/07 02:14:10 bip Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/07 02:14:10 $
    *
    * ====================================================================
    *
  @@ -80,20 +80,25 @@
    * packets to a Cluster.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $, $Date: 2001/05/07 02:14:10 $
    */
   
  -public class MulticastSender {
  +public class MulticastSender
  +    extends ClusterSessionBase implements ClusterSender {
   
       // ----------------------------------------------------- Instance Variables
   
  -
       /**
        * The unique message ID
        */
       private static String senderId = null;
   
       /**
  +     * The name of our component, used for logging.
  +     */
  +    private String senderName = "MulticastSender";
  +
  +    /**
        * The MulticastSocket to use
        */
       private MulticastSocket multicastSocket = null;
  @@ -130,11 +135,45 @@
       }
   
       /**
  +     * Return a <code>String</code> containing the name of this
  +     * implementation, used for logging
  +     *
  +     * @return The name of the implementation
  +     */
  +    public String getName() {
  +        return(this.senderName);
  +    }
  +
  +    /**
  +     * Send an object using a multicastSocket
  +     *
  +     * @param o The object to be sent.
  +     */
  +    public void send(Object o) {
  +        ObjectOutputStream oos = null;
  +        ByteArrayOutputStream bos = null;
  +
  +        try {        
  +            bos = new ByteArrayOutputStream();
  +            oos = new ObjectOutputStream(new BufferedOutputStream(bos));
  +        
  +            oos.writeObject(o);
  +            oos.flush();
  +        
  +            byte[] obs = bos.toByteArray();
  +
  +            send(obs);
  +        } catch (IOException e) {
  +            log("An error occured when trying to replicate.");
  +        }
  +    }
  +    
  +    /**
        * Send multicast data
        *
        * @param b data to be sent
        */
  -    public synchronized void send(byte[] b) {
  +    public void send(byte[] b) {
           ReplicationWrapper out = new ReplicationWrapper(b, senderId);
           ObjectOutputStream oos = null;
           ByteArrayOutputStream bos = null;
  @@ -148,12 +187,11 @@
           
               byte[] obs = bos.toByteArray();
               int size = obs.length;
  -            System.out.println("size: "+size);
               DatagramPacket p = new DatagramPacket(obs, size,
                                                     multicastAddress, multicastPort);
  -            multicastSocket.send(p);
  +            send(p);
           } catch (IOException e) {
  -            //            log("An error occured when trying to replicate.");
  +            log("An error occured when trying to replicate.");
           }
       }
   
  @@ -162,11 +200,11 @@
        *
        * @param p data to be sent
        */
  -    public synchronized void send(DatagramPacket p) {
  +    private synchronized void send(DatagramPacket p) {
           try {
               multicastSocket.send(p);
           } catch (IOException e) {
  -            //            log("An error occured when trying to replicate.");
  +            log("An error occured when trying to replicate.");
           }
       }
   }
  
  
  
  1.2       +90 -33    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/StandardCluster.java
  
  Index: StandardCluster.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/StandardCluster.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardCluster.java      2001/05/04 20:48:03     1.1
  +++ StandardCluster.java      2001/05/07 02:14:10     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/StandardCluster.java,v
 1.1 2001/05/04 20:48:03 bip Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/05/04 20:48:03 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/StandardCluster.java,v
 1.2 2001/05/07 02:14:10 bip Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/05/07 02:14:10 $
    *
    * ====================================================================
    *
  @@ -76,9 +76,6 @@
   import org.apache.catalina.LifecycleException;
   import org.apache.catalina.LifecycleListener;
   import org.apache.catalina.Logger;
  -import org.apache.catalina.cluster.ClusterMemberInfo;
  -import org.apache.catalina.cluster.MulticastSender;
  -import org.apache.catalina.cluster.MulticastReceiver;
   import org.apache.catalina.util.LifecycleSupport;
   
   /**
  @@ -86,7 +83,7 @@
    * a cluster and provides callers with a valid multicast receiver/sender.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $, $Date: 2001/05/07 02:14:10 $
    */
   
   public final class StandardCluster
  @@ -162,7 +159,7 @@
       /**
        * The debug level for this Container
        */
  -    private int debug = 99;
  +    private int debug = 0;
   
       /**
        * The interval for the background thread to sleep
  @@ -191,16 +188,24 @@
       }
   
       /**
  -     * Return the name of the cluster that this Server is currently
  -     * configured to operate within.
  +     * Set the debug level for this component
        *
  -     * @return The name of the cluster associated with this server
  +     * @param debug The debug level
        */
  -    public String getClusterName() {
  -        return(this.clusterName);
  +    public void setDebug(int debug) {
  +        this.debug = debug;
       }
   
       /**
  +     * Get the debug level for this component
  +     *
  +     * @return The debug level
  +     */
  +    public int getDebug() {
  +        return(this.debug);
  +    }
  +
  +    /**
        * Set the name of the cluster to join, if no cluster with
        * this name is present create one.
        *
  @@ -215,6 +220,16 @@
       }
   
       /**
  +     * Return the name of the cluster that this Server is currently
  +     * configured to operate within.
  +     *
  +     * @return The name of the cluster associated with this server
  +     */
  +    public String getClusterName() {
  +        return(this.clusterName);
  +    }
  +
  +    /**
        * Set the Container associated with our Cluster
        *
        * @param container The Container to use
  @@ -228,12 +243,12 @@
       }
   
       /**
  -     * Get the Port associated with our Cluster
  +     * Get the Container associated with our Cluster
        *
  -     * @return The Port associated with our Cluster
  +     * @return The Container associated with our Cluster
        */
  -    public int getMulticastPort() {
  -        return(this.multicastPort);
  +    public Container getContainer() {
  +        return(this.container);
       }
   
       /**
  @@ -250,12 +265,12 @@
       }
   
       /**
  -     * Get the Groupaddress associated with our Cluster
  +     * Get the Port associated with our Cluster
        *
  -     * @return The Groupaddress associated with our Cluster
  +     * @return The Port associated with our Cluster
        */
  -    public InetAddress getMulticastAddress() {
  -        return(this.multicastAddress);
  +    public int getMulticastPort() {
  +        return(this.multicastPort);
       }
   
       /**
  @@ -276,12 +291,35 @@
       }
   
       /**
  -     * Get the Container associated with our Cluster
  +     * Get the Groupaddress associated with our Cluster
        *
  -     * @return The Container associated with our Cluster
  +     * @return The Groupaddress associated with our Cluster
        */
  -    public Container getContainer() {
  -        return(this.container);
  +    public InetAddress getMulticastAddress() {
  +        return(this.multicastAddress);
  +    }
  +
  +    /**
  +     * Set the time in seconds for this component to
  +     * Sleep before it checks for new received data in the Cluster
  +     *
  +     * @param checkInterval The time to sleep
  +     */
  +    public void setCheckInterval(int checkInterval) {
  +        int oldCheckInterval = this.checkInterval;
  +        this.checkInterval = checkInterval;
  +        support.firePropertyChange("checkInterval",
  +                                   oldCheckInterval,
  +                                   this.checkInterval);
  +    }
  +
  +    /**
  +     * Get the time in seconds this Cluster sleeps
  +     *
  +     * @return The time in seconds this Cluster sleeps
  +     */
  +    public int getCheckInterval() {
  +        return(this.checkInterval);
       }
   
       // --------------------------------------------------------- Public Methods
  @@ -309,31 +347,50 @@
       }
   
       /**
  -     * Returns a <code>MulticastSender</code> which is the interface
  -     * to use when communicating in the Cluster. 
  +     * Returns a <code>ClusterSender</code> which is the interface
  +     * to use when sending information in the Cluster. senderId is
  +     * used as a identifier so that information sent through this
  +     * instance can only be used with the respectice
  +     * <code>ClusterReceiver</code>
        *
  -     * @return The MulticastSender to use
  +     * @return The ClusterSender
        */
  -    public MulticastSender getMulticastSender(String senderId) {
  +    public ClusterSender getClusterSender(String senderId) {
  +        Logger logger = null;
           MulticastSender send = new MulticastSender(senderId,
                                                      multicastSocket,
                                                      multicastAddress,
                                                      multicastPort);
  +        if (container != null)
  +            logger = container.getLogger();
   
  +        send.setLogger(logger);
  +        send.setDebug(debug);
  +
           return(send);
       }
   
       /**
  -     * Returns a <code>MulticastReceiver</code> which is the interface
  -     * to use when communicating in the Cluster. 
  +     * Returns a <code>ClusterReceiver</code> which is the interface
  +     * to use when receiving information in the Cluster. senderId is
  +     * used as a indentifier, only information send through the
  +     * <code>ClusterSender</code> with the same senderId can be received.
        *
  -     * @return The MulticastSender to use
  +     * @return The ClusterReceiver
        */
  -    public MulticastReceiver getMulticastReceiver(String senderId) {
  +    public ClusterReceiver getClusterReceiver(String senderId) {
  +        Logger logger = null;
           MulticastReceiver recv = new MulticastReceiver(senderId,
                                                          multicastSocket,
                                                          multicastAddress,
                                                          multicastPort);
  +
  +        if (container != null)
  +            logger = container.getLogger();
  +
  +        recv.setDebug(debug);
  +        recv.setLogger(logger);
  +        recv.setCheckInterval(checkInterval);
           recv.start();
   
           return(recv);
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterReceiver.java
  
  Index: ClusterReceiver.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterReceiver.java,v
 1.1 2001/05/07 02:14:10 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/07 02:14:10 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.catalina.cluster;
  
  import org.apache.catalina.Logger;
  
  /**
   * This class is responsible for Receiving incoming packets in a Cluster.
   * Different Implementations may use different protocol to
   * communicate within the Cluster.
   *
   * @author Bip Thelin
   * @version $Revision: 1.1 $, $Date: 2001/05/07 02:14:10 $
   */
  
  public interface ClusterReceiver extends Runnable {
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * The senderId is a identifier used to identify different
       * packages being received in a Cluster. Each package received through
       * the concrete implementation of this interface will have
       * the senderId set at runtime. Usually the senderId is the
       * name of the component that is using this <code>ClusterReceiver</code>
       *
       * @param senderId The senderId to use
       */
      public void setSenderId(String senderId);
  
      /**
       * get the senderId used to identify messages being received in a Cluster.
       *
       * @return The senderId for this ClusterReceiver
       */
      public String getSenderId();
  
      /**
       * Set the debug detail level for this component.
       *
       * @param debug The debug level
       */
      public void setDebug(int debug);
  
      /**
       * Get the debug level for this component
       *
       * @return The debug level
       */
      public int getDebug();
  
      /**
       * Set the time in seconds for this component to
       * Sleep before it checks for new received data in the Cluster
       *
       * @param checkInterval The time to sleep
       */
      public void setCheckInterval(int checkInterval);
  
      /**
       * Get the time in seconds this implementation sleeps
       *
       * @return The time in seconds this implementation sleeps
       */
      public int getCheckInterval();
  
      /**
       * Set the Logger for this component.
       *
       * @param debug The Logger to use with this component.
       */
      public void setLogger(Logger logger);
  
      /**
       * Get the Logger for this component
       *
       * @return The Logger associated with this component.
       */
      public Logger getLogger();
  
      /**
       * The log method to use in the implementation
       *
       * @param message The message to be logged.
       */
      public void log(String message);
  
      /**
       * Get an array of objects that has been received by this component.
       * Only Objects which was received with the same senderId as the
       * one specified for this <code>ClusterReceiver</code> is being returned.
       *
       * @return a value of type 'Object[]'
       */
      public Object[] getObjects();
  
      /**
       * Start this component, must be called before it can be used.
       */
      public void start();
  
      /*
       * The background thread.
       */
      public void run();
  
      /**
       * The stop method for this component, should be called when closing
       * down the Cluster.
       */
      public void stop();
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterSender.java
  
  Index: ClusterSender.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterSender.java,v
 1.1 2001/05/07 02:14:10 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/07 02:14:10 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.catalina.cluster;
  
  import org.apache.catalina.Logger;
  
  /**
   * This class is responsible for sending outgoing packets to a Cluster.
   * Different Implementations may use different protocol to
   * communicate within the Cluster.
   *
   * @author Bip Thelin
   * @version $Revision: 1.1 $, $Date: 2001/05/07 02:14:10 $
   */
  
  public interface ClusterSender {
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * The senderId is a identifier used to identify different
       * packages being sent in a Cluster. Each package sent through
       * the concrete implementation of this interface will have
       * the senderId set at runtime. Usually the senderId is the
       * name of the component that is using this <code>ClusterSender</code>
       *
       * @param senderId The senderId to use
       */
      public void setSenderId(String senderId);
  
      /**
       * get the senderId used to identify messages being sent in a Cluster.
       *
       * @return The senderId for this ClusterSender
       */
      public String getSenderId();
  
      /**
       * Set the debug detail level for this component.
       *
       * @param debug The debug level
       */
      public void setDebug(int debug);
  
      /**
       * Get the debug level for this component
       *
       * @return The debug level
       */
      public int getDebug();
  
      /**
       * Set the Logger for this component.
       *
       * @param debug The Logger to use with this component.
       */
      public void setLogger(Logger logger);
  
      /**
       * Get the Logger for this component
       *
       * @return The Logger associated with this component.
       */
      public Logger getLogger();
  
      /**
       * The log method to use in the implementation
       *
       * @param message The message to be logged.
       */
      public void log(String message);
  
      /**
       * Send an array of bytes, the implementation of this
       * <code>ClusterSender</code> is responsible for modifying
       * the bytearray to something that it can use. Before anything
       * is sent it is transformed into a ReplicationWrapper object
       * and the right senderId is set.
       *
       * @param b the bytearray to send
       */
      public void send(byte[] b);
  
      /**
       * Send an object, the implementation of this
       * <code>ClusterSender</code> is responsible for modifying
       * the Object to something that it can use. Before anything
       * is sent it is transformed into a ReplicationWrapper object
       * and the right senderId is set.
       *
       * @param o The object to send
       */
      public void send(Object o);
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterSessionBase.java
  
  Index: ClusterSessionBase.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/cluster/ClusterSessionBase.java,v
 1.1 2001/05/07 02:14:10 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/07 02:14:10 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.catalina.cluster;
  
  import org.apache.catalina.Logger;
  
  /**
   * This is an abstract implementation of <code>ClusterSender</code>
   * and <code>ClusterReceiver</code> which provide basic functionallity
   * shared by the two components.
   *
   * @author Bip Thelin
   * @version $Revision: 1.1 $, $Date: 2001/05/07 02:14:10 $
   */
  
  public abstract class ClusterSessionBase {
  
      // ----------------------------------------------------- Instance Variables
  
      /**
       * The senderId associated with this component
       */
      private String senderId = null;
  
      /**
       * The debug level for this component
       */
      private int debug = 0;
  
      /**
       * The Logger associated with this component.
       */
      private Logger logger = null;
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * The senderId is a identifier used to identify different
       * packagesin a Cluster. Each package received or send through
       * the concrete implementation of this interface will have
       * the senderId set at runtime. Usually the senderId is the
       * name of the component that is using this component.
       *
       * @param senderId The senderId to use
       */
      public void setSenderId(String senderId) {
          this.senderId = senderId;
      }
  
      /**
       * get the senderId used to identify messages being
       * send or received in a Cluster.
       *
       * @return The senderId for this component
       */
      public String getSenderId() {
          return(this.senderId);
      }
  
      /**
       * Set the debug detail level for this component.
       *
       * @param debug The debug level
       */
      public void setDebug(int debug) {
          this.debug = debug;
      }
  
      /**
       * Get the debug level for this component
       *
       * @return The debug level
       */
      public int getDebug() {
          return(this.debug);
      }
  
      /**
       * Set the Logger for this component.
       *
       * @param debug The Logger to use with this component.
       */
      public void setLogger(Logger logger) {
          this.logger = logger;
      }
  
      /**
       * Get the Logger for this component
       *
       * @return The Logger associated with this component.
       */
      public Logger getLogger() {
          return(this.logger);
      }
  
      public abstract String getName();
  
      /**
       * The log method to use in the implementation
       *
       * @param message The message to be logged.
       */
      public void log(String message) {
          Logger logger = getLogger();
  
          if(logger != null)
              logger.log("[Cluster/"+getName()+"]: "+message);
          else
              System.out.println("[Cluster/"+getName()+"]: "+message);
      }
  }
  
  
  

Reply via email to