fhanik      2004/05/28 19:36:12

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster
                        CatalinaCluster.java SessionMessage.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        SimpleTcpCluster.java
  Added:       modules/cluster/src/share/org/apache/catalina/cluster
                        ClusterMessage.java MessageListener.java
  Log:
  Refactored a little bit more.
  Extending the catalina cluster to handle more than session messages.
  The next step is to implement farm deployment, hence I am expanding the
  cluster to use a message callback model instead of invoking the objects
  directly. this allows you to plug in as many callback objects as possible.
  The first call back object will be the cluster farm object. Coming soon... :)
  
  Revision  Changes    Path
  1.5       +7 -3      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/CatalinaCluster.java
  
  Index: CatalinaCluster.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/CatalinaCluster.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CatalinaCluster.java      27 Feb 2004 14:58:55 -0000      1.4
  +++ CatalinaCluster.java      29 May 2004 02:36:12 -0000      1.5
  @@ -63,14 +63,14 @@
        * Sends a message to all the members in the cluster
        * @param msg SessionMessage
        */
  -    public void send(SessionMessage msg);
  +    public void send(ClusterMessage msg);
       
       /**
        * Sends a message to a specific member in the cluster
        * @param msg SessionMessage
        * @param dest Member
        */
  -    public void send(SessionMessage msg, Member dest);
  +    public void send(ClusterMessage msg, Member dest);
       
       /**
        * returns all the members currently participating in the cluster
  @@ -91,5 +91,9 @@
       public MembershipService getMembershipService();
       
       public void addValve(Valve valve);
  +    
  +    public void addClusterListener(MessageListener listener);
  +    
  +    public void removeClusterListener(MessageListener listener);
       
   }
  
  
  
  1.10      +2 -31     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/SessionMessage.java
  
  Index: SessionMessage.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/SessionMessage.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SessionMessage.java       5 May 2004 16:42:22 -0000       1.9
  +++ SessionMessage.java       29 May 2004 02:36:12 -0000      1.10
  @@ -38,7 +38,7 @@
    */
    import java.security.Principal;
    import org.apache.catalina.cluster.Member;
  -public interface SessionMessage extends java.io.Serializable
  +public interface SessionMessage extends ClusterMessage, java.io.Serializable
   {
   
       /**
  @@ -73,18 +73,7 @@
        */
       public static final int EVT_ALL_SESSION_DATA = 12;
       
  -    /**
  -     * Get the address that this message originated from.  This would be set
  -     * if the message was being relayed from a host other than the one
  -     * that originally sent it.
  -     */
  -    public Member getAddress();
  -    /**
  -     * Called by the cluster before sending it to the other
  -     * nodes
  -     * @param member Member
  -     */
  -    public void setAddress(Member member);
  +
       
       public String getContextName();
       
  @@ -104,24 +93,6 @@
        */
       public String getSessionID();
       
  -    /**
  -     * Timestamp message 
  -     * @return long
  -     */
  -    public long getTimestamp();
  -    /**
  -     * Called by the cluster before sending out 
  -     * the message
  -     * @param timestamp long
  -     */
  -    public void setTimestamp(long timestamp);
  -
  -    /**
  -     * Each message must have a unique ID, in case of using async replication,
  -     * and a smart queue, this id is used to replace messages not yet sent 
  -     * @return String
  -     */
  -    public String getUniqueId();
   
   
   }//SessionMessage
  
  
  
  1.1                  
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/ClusterMessage.java
  
  Index: ClusterMessage.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.catalina.cluster;
  
  import java.io.Serializable;
  
  public interface ClusterMessage
      extends Serializable {
      /**
       * Get the address that this message originated from.  This would be set
       * if the message was being relayed from a host other than the one
       * that originally sent it.
       */
      public Member getAddress();
  
      /**
       * Called by the cluster before sending it to the other
       * nodes
       * @param member Member
       */
      public void setAddress(Member member);
  
      /**
       * Timestamp message
       * @return long
       */
      public long getTimestamp();
  
      /**
       * Called by the cluster before sending out
       * the message
       * @param timestamp long
       */
      public void setTimestamp(long timestamp);
  
      /**
       * Each message must have a unique ID, in case of using async replication,
       * and a smart queue, this id is used to replace messages not yet sent
       * @return String
       */
      public String getUniqueId();
  
  }
  
  
  
  1.1                  
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/MessageListener.java
  
  Index: MessageListener.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.catalina.cluster;
  
  public interface MessageListener {
      
      public void messageReceived(ClusterMessage msg);
      
      public boolean accept(ClusterMessage msg);
      
      public boolean equals(Object listener);
      
      public int hashCode();
  
  }
  
  
  
  1.40      +25 -9     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java
  
  Index: SimpleTcpCluster.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- SimpleTcpCluster.java     26 May 2004 16:38:44 -0000      1.39
  +++ SimpleTcpCluster.java     29 May 2004 02:36:12 -0000      1.40
  @@ -26,7 +26,6 @@
   import org.apache.catalina.ServerFactory;
   import org.apache.catalina.core.StandardServer;
   
  -import org.apache.catalina.Cluster;
   import org.apache.catalina.Container;
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleEvent;
  @@ -41,6 +40,7 @@
   
   import org.apache.catalina.cluster.Member;
   import org.apache.catalina.cluster.CatalinaCluster;
  +import org.apache.catalina.cluster.MessageListener;
   import org.apache.catalina.cluster.MembershipListener;
   import org.apache.catalina.cluster.MembershipService;
   import org.apache.commons.beanutils.MethodUtils;
  @@ -50,6 +50,7 @@
   import org.apache.catalina.cluster.io.ListenCallback;
   
   import org.apache.catalina.cluster.SessionMessage;
  +import org.apache.catalina.cluster.ClusterMessage;
   import org.apache.catalina.cluster.session.ReplicationStream;
   import org.apache.catalina.cluster.ClusterManager;
   import org.apache.catalina.cluster.Constants;
  @@ -385,15 +386,21 @@
       }
   
   
  -    public void send(SessionMessage msg, Member dest) {
  +    public void send(ClusterMessage msg, Member dest) {
           try
           {
               msg.setAddress(membershipService.getLocalMember());
               Member destination = dest;
  -            if ( (destination == null) && (msg.getEventType() == 
SessionMessage.EVT_GET_ALL_SESSIONS) ) {
  -                if (membershipService.getMembers().length > 0)
  -                    destination = membershipService.getMembers()[0];
  -            }
  +            
  +            if ( msg instanceof SessionMessage ) {
  +                SessionMessage smsg = (SessionMessage) msg;
  +                //if we request session state, send to the oldest of members
  +                if ((destination == null) &&
  +                    (smsg.getEventType() == SessionMessage.EVT_GET_ALL_SESSIONS) &&
  +                    (membershipService.getMembers().length > 0)) {
  +                        destination = membershipService.getMembers()[0];
  +                }//end if
  +            }//end if
               msg.setTimestamp(System.currentTimeMillis());
               java.io.ByteArrayOutputStream outs = new 
java.io.ByteArrayOutputStream();
               java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(outs);
  @@ -402,7 +409,7 @@
               if(destination != null) {
                     Member tcpdest = dest;
                     if ( (tcpdest != null) && 
(!membershipService.getLocalMember().equals(tcpdest)))  {
  -                       clusterSender.sendMessage(msg.getSessionID(), data, tcpdest);
  +                       clusterSender.sendMessage(msg.getUniqueId(), data, tcpdest);
                     }//end if
               }
               else {
  @@ -413,7 +420,7 @@
           }
       }
   
  -    public void send(SessionMessage msg) {
  +    public void send(ClusterMessage msg) {
           send(msg,null);
       }
   
  @@ -648,6 +655,15 @@
       public void addValve(Valve valve) {
           this.valve = valve;
       }
  +    
  +    public void addClusterListener(MessageListener listener) {
  +        //TO DO
  +    }
  +
  +    public void removeClusterListener(MessageListener listener) {
  +        //TO DO
  +    }
  +    
       
       private class MemberComparator implements java.util.Comparator {
           
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to