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 Sun, 16 Nov 2003 22:22:45 GMT
fhanik      2003/11/16 14:22:45

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster
                        Member.java SessionMessage.java
               modules/cluster/src/share/org/apache/catalina/cluster/io
                        XByteBuffer.java
               modules/cluster/src/share/org/apache/catalina/cluster/mcast
                        McastMember.java McastService.java
                        McastServiceImpl.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        SimpleTcpCluster.java
  Log:
  added in member alive time
  
  Revision  Changes    Path
  1.2       +12 -4     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/Member.java
  
  Index: Member.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/Member.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Member.java	19 Feb 2003 20:57:17 -0000	1.1
  +++ Member.java	16 Nov 2003 22:22:45 -0000	1.2
  @@ -98,4 +98,12 @@
        * @return
        */
       public int getPort();
  +
  +    /**
  +     * Contains information on how long this member has been online.
  +     * The result is the number of milli seconds this member has been
  +     * broadcasting its membership to the cluster.
  +     * @return nr of milliseconds since this member started.
  +     */
  +    public long getMemberAliveTime();
   }
  
  
  
  1.4       +10 -39    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionMessage.java	15 Nov 2003 00:58:20 -0000	1.3
  +++ SessionMessage.java	16 Nov 2003 22:22:45 -0000	1.4
  @@ -138,36 +138,10 @@
        * Event type used when an attribute has been added to a session,
        * the attribute will be sent to all the other nodes in the cluster
        */
  -//    public static final int EVT_ATTRIBUTE_ADDED  = 5;
  -    /**
  -     * Event type used when an attribute has been removed from a session,
  -     * the attribute will be sent to all the other nodes in the cluster
  -     */
  -//    public static final int EVT_ATTRIBUTE_REMOVED_WONOTIFY = 6;
  -
  -    /**
  -     * Event type used when an attribute has been removed from a session,
  -     * the attribute will be sent to all the other nodes in the cluster
  -     */
  -//    public static final int EVT_ATTRIBUTE_REMOVED_WNOTIFY = 8;
  -
  -    /**
  -     * Event type used when a user principal is being cached in the session
  -     */
  -//    public static final int EVT_SET_USER_PRINCIPAL = 9;
  +    public static final int EVT_SESSION_DELTA  = 13;
   
       /**
  -     * Event type used when a user principal is being cached in the session
  -     */
  -//    public static final int EVT_REMOVE_SESSION_NOTE = 10;
  -
  -
  -    /**
  -     * Event type used when a user principal is being cached in the session
  -     */
  -//    public static final int EVT_SET_SESSION_NOTE = 11;
  -    /**
  -     * Event type used when all sessions are sent over as binary data
  +     * When a session state is transferred, this is the event.
        */
       public static final int EVT_ALL_SESSION_DATA = 12;
   
  @@ -208,7 +182,7 @@
        * <B>EVT_REMOVE_SESSION_NOTE</B><BR>
        *    The parameters: sessionID, attrName<
        * <B>EVT_SET_SESSION_NOTE</B><BR>
  -     *    The parameters: sessionID, attrName, attrValue<
  +     *    The parameters: sessionID, attrName, attrValue
        * @param eventtype - one of the 8 event type defined in this class
        * @param session - the serialized byte array of the session itself
        * @param sessionID - the id that identifies this session
  @@ -263,14 +237,9 @@
               case EVT_SESSION_CREATED : return "SESSION-MODIFIED";
               case EVT_SESSION_EXPIRED_WNOTIFY : return "SESSION-EXPIRED-WITH-NOTIFY";
               case EVT_SESSION_EXPIRED_WONOTIFY : return "SESSION-EXPIRED-WITHOUT-NOTIFY";
  -//            case EVT_ATTRIBUTE_ADDED : return "SESSION-ATTRIBUTE-ADDED";
  -//            case EVT_ATTRIBUTE_REMOVED_WNOTIFY : return "SESSION-ATTRIBUTE-REMOVED-WITH-NOTIFY";
  -//            case EVT_ATTRIBUTE_REMOVED_WONOTIFY: return "SESSION-ATTRIBUTE-REMOVED-WITHOUT-NOTIFY";
               case EVT_SESSION_ACCESSED : return "SESSION-ACCESSED";
               case EVT_GET_ALL_SESSIONS : return "SESSION-GET-ALL";
  -//            case EVT_SET_SESSION_NOTE: return "SET-SESSION-NOTE";
  -//            case EVT_SET_USER_PRINCIPAL : return "SET-USER-PRINCIPAL";
  -//            case EVT_REMOVE_SESSION_NOTE : return "REMOVE-SESSION-NOTE";
  +            //case EVT_SET_USER_PRINCIPAL : return "SET-USER-PRINCIPAL";
               case EVT_ALL_SESSION_DATA : return "ALL-SESSION-DATA";
               default : return "UNKNOWN-EVENT-TYPE";
           }
  @@ -296,5 +265,7 @@
           this.mSrc = src;
       }
   
  -    public String getContextName() { return mContextName; }
  +    public String getContextName() {
  +       return mContextName;
  +    }
   }//SessionMessage
  
  
  
  1.2       +65 -4     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/io/XByteBuffer.java
  
  Index: XByteBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/io/XByteBuffer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XByteBuffer.java	19 Feb 2003 20:32:10 -0000	1.1
  +++ XByteBuffer.java	16 Nov 2003 22:22:45 -0000	1.2
  @@ -242,6 +242,25 @@
       }//toInt
   
       /**
  +     * Convert eight bytes to a long
  +     * @param b - the byte array containing the four bytes
  +     * @param off - the offset
  +     * @return the long value constructed from the eight bytes
  +     * @exception java.lang.ArrayOutOfBoundsException
  +     */
  +    public static long toLong(byte[] b,int off){
  +        return ( ( (long) b[off+7]) & 0xFF) +
  +            ( ( ( (long) b[off+6]) & 0xFF) << 8) +
  +            ( ( ( (long) b[off+5]) & 0xFF) << 16) +
  +            ( ( ( (long) b[off+4]) & 0xFF) << 24) +
  +            ( ( ( (long) b[off+3]) & 0xFF) << 32) +
  +            ( ( ( (long) b[off+2]) & 0xFF) << 40) +
  +            ( ( ( (long) b[off+1]) & 0xFF) << 48) +
  +            ( ( ( (long) b[off+0]) & 0xFF) << 56);
  +    }//toInt
  +
  +
  +    /**
        * Converts an integer to four bytes
        * @param n - the integer
        * @return - four bytes in an array
  @@ -258,6 +277,33 @@
           return b;
       } //toBytes
   
  +
  +    /**
  +     * Converts an long to eight bytes
  +     * @param n - the long
  +     * @return - eight bytes in an array
  +     */
  +    public static byte[] toBytes(long n) {
  +        byte[] b = new byte[8];
  +        b[7] = (byte) (n);
  +        n >>>= 8;
  +        b[6] = (byte) (n);
  +        n >>>= 8;
  +        b[5] = (byte) (n);
  +        n >>>= 8;
  +        b[4] = (byte) (n);
  +        n >>>= 8;
  +        b[3] = (byte) (n);
  +        n >>>= 8;
  +        b[2] = (byte) (n);
  +        n >>>= 8;
  +        b[1] = (byte) (n);
  +        n >>>= 8;
  +        b[0] = (byte) (n);
  +        return b;
  +    } //toBytes
  +
  +
       /**
        * Similar to a String.IndexOf, but uses pure bytes
        * @param src - the source bytes to be searched
  @@ -316,5 +362,20 @@
           System.arraycopy(END_DATA,0,result,START_DATA.length+4+data.length,END_DATA.length);
           return result;
       }//createDataPackage
  +
  +    public static void main(String[] args) {
  +       System.out.println("Before="+Integer.MAX_VALUE);
  +       byte[] d = toBytes(Integer.MAX_VALUE);
  +       System.out.println("After="+toInt(d,0));
  +
  +
  +       System.out.println("Before="+Long.MAX_VALUE);
  +       d = toBytes(Long.MAX_VALUE);
  +       System.out.println("After="+toLong(d,0));
  +
  +       System.out.println("Before=" + 4564564);
  +       d = toBytes((long)4564564);
  +       System.out.println("After=" + toLong(d, 0));
  +    }
   
   }//class
  
  
  
  1.2       +53 -18    jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastMember.java
  
  Index: McastMember.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastMember.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- McastMember.java	19 Feb 2003 20:32:10 -0000	1.1
  +++ McastMember.java	16 Nov 2003 22:22:45 -0000	1.2
  @@ -108,6 +108,11 @@
        * Counter for how many messages have been sent from this member
        */
       protected int msgCount = 0;
  +    /**
  +     * The number of milliseconds since this members was
  +     * created, is kept track of using the start time
  +     */
  +    protected long memberAliveTime = 0;
   
   
       /**
  @@ -118,10 +123,12 @@
        */
       public McastMember(String name,
                          String host,
  -                       int port) {
  +                       int port,
  +                       long aliveTime) {
           this.host = host;
           this.port = port;
           this.name = name;
  +        this.memberAliveTime=aliveTime;
       }
   
       /**
  @@ -152,17 +159,20 @@
        * @return - the bytes for this member deserialized
        * @throws Exception
        */
  -    protected byte[] getData() throws Exception {
  +    protected byte[] getData(long startTime) throws Exception {
           //package looks like
  +        //alive - 8 bytes
           //port - 4 bytes
           //host - 4 bytes
           //name - remaining bytes
           byte[] named = getName().getBytes();
           byte[] addr = java.net.InetAddress.getByName(host).getAddress();
  -        byte[] data = new byte[4+addr.length+named.length];
  -        System.arraycopy(XByteBuffer.toBytes(port),0,data,0,4);
  -        System.arraycopy(addr,0,data,4,4);
  -        System.arraycopy(named,0,data,4+addr.length,named.length);
  +        byte[] data = new byte[8+4+addr.length+named.length];
  +        long alive=System.currentTimeMillis()-startTime;
  +        System.arraycopy(XByteBuffer.toBytes((long)alive),0,data,0,8);
  +        System.arraycopy(XByteBuffer.toBytes(port),0,data,8,4);
  +        System.arraycopy(addr,0,data,12,addr.length);
  +        System.arraycopy(named,0,data,8+4+addr.length,named.length);
           return data;
       }
       /**
  @@ -171,13 +181,22 @@
        * @return a member object.
        */
       protected static McastMember getMember(byte[] data) {
  -        byte[] portd = new byte[4];
  -        System.arraycopy(data,0,portd,0,4);
  -        byte[] addr = new byte[4];
  -        System.arraycopy(data,4,addr,0,4);
  -        byte[] named = new byte[data.length-8];
  -        System.arraycopy(data,8,named,0,named.length);
  -        return new McastMember(new String(named),addressToString(addr),XByteBuffer.toInt(portd,0));
  +       //package looks like
  +       //alive - 8 bytes
  +       //port - 4 bytes
  +       //host - 4 bytes
  +       //name - remaining bytes
  +       byte[] alived = new byte[8];
  +       System.arraycopy(data, 0, alived, 0, 8);
  +       byte[] portd = new byte[4];
  +       System.arraycopy(data, 8, portd, 0, 4);
  +       byte[] addr = new byte[4];
  +       System.arraycopy(data, 12, addr, 0, 4);
  +       byte[] named = new byte[data.length - 16];
  +       System.arraycopy(data, 16, named, 0, named.length);
  +       return new McastMember(new String(named), addressToString(addr),
  +                              XByteBuffer.toInt(portd, 0),
  +                              XByteBuffer.toLong(alived, 0));
       }
   
       /**
  @@ -205,11 +224,27 @@
       }
   
       /**
  +     * Contains information on how long this member has been online.
  +     * The result is the number of milli seconds this member has been
  +     * broadcasting its membership to the cluster.
  +     * @return nr of milliseconds since this member started.
  +     */
  +    public long getMemberAliveTime() {
  +       return memberAliveTime;
  +    }
  +
  +    public void setMemberAliveTime(long time) {
  +       memberAliveTime=time;
  +    }
  +
  +
  +
  +    /**
        * String representation of this object
        * @return
        */
       public String toString()  {
  -        return "org.apache.catalina.cluster.mcast.McastMember["+name+","+host+","+port+"]";
  +        return "org.apache.catalina.cluster.mcast.McastMember["+name+","+host+","+port+",
alive="+memberAliveTime+"]";
       }
   
       /**
  
  
  
  1.3       +7 -6      jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java
  
  Index: McastService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- McastService.java	20 Mar 2003 20:46:12 -0000	1.2
  +++ McastService.java	16 Nov 2003 22:22:45 -0000	1.3
  @@ -99,7 +99,7 @@
       /**
        * The local member
        */
  -    protected Member localMember;
  +    protected McastMember localMember;
   
       /**
        * Create a membership service.
  @@ -142,6 +142,7 @@
        * Return the local member
        */
       public Member getLocalMember() {
  +        localMember.setMemberAliveTime(System.currentTimeMillis()-impl.getServiceStartTime());
           return localMember;
       }
   
  @@ -164,7 +165,7 @@
           String host = getProperties().getProperty("tcpListenHost");
           int port = Integer.parseInt(getProperties().getProperty("tcpListenPort"));
           String name = "tcp://"+host+":"+port;
  -        localMember = new McastMember(name,host,port);
  +        localMember = new McastMember(name,host,port,0);
           impl = new McastServiceImpl((McastMember)localMember,Long.parseLong(properties.getProperty("msgFrequency")),
                                       Long.parseLong(properties.getProperty("memberDropTime")),
                                       Integer.parseInt(properties.getProperty("mcastPort")),
  
  
  
  1.4       +16 -5     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java
  
  Index: McastServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- McastServiceImpl.java	20 Mar 2003 20:46:12 -0000	1.3
  +++ McastServiceImpl.java	16 Nov 2003 22:22:45 -0000	1.4
  @@ -138,6 +138,11 @@
       protected SenderThread sender;
   
       /**
  +     * When was the service started
  +     */
  +    protected long serviceStartTime = 0;
  +
  +    /**
        * Create a new mcast service impl
        * @param member - the local member
        * @param sendFrequency - the time (ms) in between pings sent out
  @@ -189,6 +194,7 @@
           receiver.setDaemon(true);
           receiver.start();
           sender.start();
  +        serviceStartTime = System.currentTimeMillis();
       }
   
       /**
  @@ -200,6 +206,7 @@
           doRun = false;
           sender = null;
           receiver = null;
  +        serviceStartTime = Long.MAX_VALUE;
       }
   
       /**
  @@ -225,11 +232,15 @@
        */
       public void send() throws Exception{
           member.inc();
  -        byte[] data = member.getData();
  +        byte[] data = member.getData(this.serviceStartTime);
           DatagramPacket p = new DatagramPacket(data,data.length);
           p.setAddress(address);
           p.setPort(port);
           socket.send(p);
  +    }
  +
  +    public long getServiceStartTime() {
  +       return this.serviceStartTime;
       }
   
   
  
  
  
  1.19      +6 -11     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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SimpleTcpCluster.java	15 Nov 2003 01:07:23 -0000	1.18
  +++ SimpleTcpCluster.java	16 Nov 2003 22:22:45 -0000	1.19
  @@ -145,10 +145,6 @@
        * The properties for the
        */
       protected java.util.Properties svcproperties = new java.util.Properties();
  -    /**
  -     * Our current local address
  -     */
  -    protected Member localMember;
   
       /**
        * Tcp address to listen for incoming changes
  @@ -495,7 +491,6 @@
               service = MembershipFactory.getMembershipService(serviceclass,svcproperties);
               service.addMembershipListener(this);
               service.start();
  -            localMember = service.getLocalMember();
               Thread.currentThread().sleep((msgFrequency*4));
               this.started = true;
           } catch ( Exception x ) {
  @@ -509,7 +504,7 @@
       public void send(SessionMessage msg, Member dest) {
           try
           {
  -            msg.setAddress(localMember);
  +            msg.setAddress(service.getLocalMember());
               Member destination = dest;
               if ( (destination == null) && (msg.getEventType() == SessionMessage.EVT_GET_ALL_SESSIONS)
) {
                   if (service.getMembers().length > 0)
  @@ -522,7 +517,7 @@
               byte[] data = outs.toByteArray();
               if(destination != null) {
                     Member tcpdest = dest;
  -                  if ( (tcpdest != null) && (!localMember.equals(tcpdest)))  {
  +                  if ( (tcpdest != null) && (!service.getLocalMember().equals(tcpdest)))
 {
                          mReplicationTransmitter.sendMessage(msg.getSessionID(),
                                                              data,
                                                              InetAddress.getByName(tcpdest.getHost()),
  
  
  

---------------------------------------------------------------------
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