tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp SimpleTcpCluster.java
Date Thu, 20 Feb 2003 17:54:15 GMT
fhanik      2003/02/20 09:54:15

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/session
                        SimpleTcpReplicationManager.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        SimpleTcpCluster.java
  Log:
  Now listening to the server for an after_start event before requesting data from other nodes
  
  Revision  Changes    Path
  1.2       +3 -12     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/SimpleTcpReplicationManager.java
  
  Index: SimpleTcpReplicationManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/SimpleTcpReplicationManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleTcpReplicationManager.java	19 Feb 2003 20:32:10 -0000	1.1
  +++ SimpleTcpReplicationManager.java	20 Feb 2003 17:54:15 -0000	1.2
  @@ -459,15 +459,6 @@
               log("Received SessionMessage sender="+sender,3);
               switch ( msg.getEventType() ) {
                   case SessionMessage.EVT_GET_ALL_SESSIONS: {
  -                    try {
  -                        //hack, because we don't want to send the data until the
  -                        //manager is started up on the other side.
  -                        Thread.currentThread().sleep(5000);
  -                    }
  -                    catch ( Exception ignore ) {
  -                        //do nothing
  -                    }
  -
                       //get a list of all the session from this manager
                       Object[] sessions = findSessions();
                       java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
  
  
  
  1.2       +40 -17    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleTcpCluster.java	19 Feb 2003 20:32:11 -0000	1.1
  +++ SimpleTcpCluster.java	20 Feb 2003 17:54:15 -0000	1.2
  @@ -70,6 +70,9 @@
   import java.io.IOException;
   import java.util.HashMap;
   
  +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;
  @@ -109,7 +112,9 @@
    */
   
   public class SimpleTcpCluster
  -    implements Cluster, Lifecycle,MembershipListener, ListenCallback {
  +    implements Cluster, Lifecycle,
  +               MembershipListener, ListenCallback,
  +               LifecycleListener {
   
   
       private static org.apache.commons.logging.Log log =
  @@ -231,7 +236,10 @@
        */
       protected HashMap managers = new HashMap();
   
  -
  +    /**
  +     * Nr of milliseconds between every heart beat
  +     */
  +    protected long msgFrequency = 500;
       /**
        * A reference to the membership service.
        */
  @@ -251,6 +259,11 @@
               log.error("In SimpleTcpCluster.constructor()",x);
           }
   
  +        if ( ServerFactory.getServer() instanceof StandardServer ) {
  +            StandardServer server = (StandardServer) ServerFactory.getServer();
  +            server.addLifecycleListener(this);
  +        }
  +
       }
       /**
        * Return descriptive information about this Cluster implementation and
  @@ -319,6 +332,7 @@
           support.firePropertyChange("container",
                                      oldContainer,
                                      this.container);
  +        //this.container.
       }
   
   
  @@ -431,22 +445,14 @@
               mReplicationListener.start();
               mReplicationTransmitter = new ReplicationTransmitter(new SocketSender[0]);
               mReplicationTransmitter.start();
  -            SessionMessage msg =
  -                new SessionMessage(null,
  -                                   SessionMessage.EVT_GET_ALL_SESSIONS,
  -                                   null,
  -                                   null);
  +
               //wait 5 seconds to establish the view membership
  -            log.info("Sleeping for 5 secs to establish cluster membership");
  +            log.info("Sleeping for "+(msgFrequency*4)+" secs to establish cluster membership");
               service = MembershipFactory.getMembershipService(serviceclass,svcproperties);
               service.addMembershipListener(this);
               service.start();
               localMember = service.getLocalMember();
  -            Thread.currentThread().sleep(5000);
  -            if (service.getMembers().length > 0) {
  -                Member mbr = service.getMembers()[0];
  -                send(msg, mbr);
  -            }
  +            Thread.currentThread().sleep((msgFrequency*4));
               this.started = true;
           } catch ( Exception x ) {
               log.error("Unable to start cluster.",x);
  @@ -556,6 +562,7 @@
       public void setMcastFrequency(long time)
       {
           svcproperties.setProperty("msgFrequency",String.valueOf(time));
  +        msgFrequency = time;
       }
   
       public void setMcastDropTime(long time)
  @@ -620,6 +627,22 @@
           } catch ( Exception x ) {
               log.error("Unable to deserialize session message.",x);
           }
  +    }
  +
  +    public void lifecycleEvent(LifecycleEvent lifecycleEvent){
  +        if ( lifecycleEvent.getLifecycle().AFTER_START_EVENT.equals(lifecycleEvent.getType())
) {
  +            //The server has started
  +            SessionMessage msg =
  +                new SessionMessage(null,
  +                                   SessionMessage.EVT_GET_ALL_SESSIONS,
  +                                   null,
  +                                   null);
  +            if (service.getMembers().length > 0) {
  +                Member mbr = service.getMembers()[0];
  +                send(msg, mbr);
  +            }
  +
  +        }//end if
       }
       // ---------------------------------------------  Inner Class
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message