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/session SessionMessageImpl.java DeltaManager.java SimpleTcpReplicationManager.java
Date Wed, 05 May 2004 16:36:13 GMT
fhanik      2004/05/05 09:36:13

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster
                        SessionMessage.java
               modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java SimpleTcpReplicationManager.java
  Added:       modules/cluster/src/share/org/apache/catalina/cluster/session
                        SessionMessageImpl.java
  Log:
  Refactored the session message to be an interface, so that all
  base classes are interfaces implemented by the different modules.
  
  Revision  Changes    Path
  1.8       +33 -121   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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SessionMessage.java	7 Apr 2004 20:43:54 -0000	1.7
  +++ SessionMessage.java	5 May 2004 16:36:12 -0000	1.8
  @@ -56,9 +56,7 @@
    */
    import java.security.Principal;
    import org.apache.catalina.cluster.Member;
  -public class SessionMessage
  -    //implements serializable,
  -    implements java.io.Serializable
  +public interface SessionMessage extends java.io.Serializable
   {
   
       /**
  @@ -92,142 +90,56 @@
        * When a session state is transferred, this is the event.
        */
       public static final int EVT_ALL_SESSION_DATA = 12;
  -
  -
  -    /*
  -
  -     * Private serializable variables to keep the messages state
  +    
  +    /**
  +     * 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.
        */
  -    private int mEvtType = -1;
  -    private byte[] mSession;
  -    private String mSessionID;
  -    private Member mSrc;
  -    private String mContextName;
  -    private long serializationTimestamp;
  -    private String uniqueId;
  -
  -
  +    public Member getAddress();
       /**
  -     * Creates a session message. Depending on what event type you want this
  -     * message to represent, you populate the different parameters in the constructor<BR>
  -     * The following rules apply dependent on what event type argument you use:<BR>
  -     * <B>EVT_SESSION_CREATED</B><BR>
  -     *    The parameters: session, sessionID must be set.<BR>
  -     * <B>EVT_SESSION_EXPIRED</B><BR>
  -     *    The parameters: sessionID must be set.<BR>
  -     * <B>EVT_SESSION_ACCESSED</B><BR>
  -     *    The parameters: sessionID must be set.<BR>
  -     * <B>EVT_SESSION_EXPIRED_XXXX</B><BR>
  -     *    The parameters: sessionID must be set.<BR>
  -     * <B>EVT_ATTRIBUTE_ADDED</B><BR>
  -     *    The parameters: sessionID, attrName, attrValue must be set.<BR>
  -     * <B>EVT_ATTRIBUTE_REMOVED</B><BR>
  -     *    The parameters: sessionID, attrName must be set.<BR>
  -     * <B>EVT_SET_USER_PRINCIPAL</B><BR>
  -     *    The parameters: sessionID, principal<BR>
  -     * <B>EVT_REMOVE_SESSION_NOTE</B><BR>
  -     *    The parameters: sessionID, attrName<
  -     * <B>EVT_SET_SESSION_NOTE</B><BR>
  -     *    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
  -     * @param attrName - the name of the attribute added/removed
  -     * @param attrValue - the value of the attribute added
  -
  -     */
  -    public SessionMessage( String contextName,
  -                           int eventtype,
  -                           byte[] session,
  -                           String sessionID)
  -    {
  -        mEvtType = eventtype;
  -        mSession = session;
  -        mSessionID = sessionID;
  -        mContextName = contextName;
  -        uniqueId = sessionID;
  -    }
  -
  -    public SessionMessage( String contextName,
  -                           int eventtype,
  -                           byte[] session,
  -                           String sessionID,
  -                           String uniqueID)
  -    {
  -        this(contextName,eventtype,session,sessionID);
  -        uniqueId = uniqueID;
  -    }
  -
  +     * Called by the cluster before sending it to the other
  +     * nodes
  +     * @param member Member
  +     */
  +    public void setAddress(Member member);
  +    
  +    public String getContextName();
  +    
  +    public String getEventTypeString();
  +    
       /**
        * returns the event type
        * @return one of the event types EVT_XXXX
        */
  -    public int getEventType() { return mEvtType; }
  +    public int getEventType(); 
       /**
        * @return the serialized data for the session
        */
  -    public byte[] getSession() { return mSession;}
  +    public byte[] getSession();
       /**
        * @return the session ID for the session
        */
  -    public String getSessionID(){ return mSessionID; }
  +    public String getSessionID();
  +    
       /**
  -     * @return the name of the attribute
  +     * Timestamp message 
  +     * @return long
        */
  -//    public String getAttributeName() { return mAttributeName; }
  +    public long getTimestamp();
       /**
  -     * the value of the attribute
  +     * Called by the cluster before sending out 
  +     * the message
  +     * @param timestamp long
        */
  -//    public Object getAttributeValue() {return mAttributeValue; }
  -
  -//    public SerializablePrincipal getPrincipal() { return mPrincipal;}
  +    public void setTimestamp(long timestamp);
   
  -    public void setTimestamp(long time) {serializationTimestamp=time;}
  -    public long getTimestamp() { return serializationTimestamp;}
       /**
  -     * @return the event type in a string representating, useful for debugging
  +     * 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 getEventTypeString()
  -    {
  -        switch (mEvtType)
  -        {
  -            case EVT_SESSION_CREATED : return "SESSION-MODIFIED";
  -            case EVT_SESSION_EXPIRED : return "SESSION-EXPIRED";
  -            case EVT_SESSION_ACCESSED : return "SESSION-ACCESSED";
  -            case EVT_GET_ALL_SESSIONS : return "SESSION-GET-ALL";
  -            case EVT_SESSION_DELTA : return "SESSION-DELTA";
  -            case EVT_ALL_SESSION_DATA : return "ALL-SESSION-DATA";
  -            default : return "UNKNOWN-EVENT-TYPE";
  -        }
  -    }
  +    public String getUniqueId();
  +
   
  -    /**
  -     * 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()
  -    {
  -        return this.mSrc;
  -    }
  -
  -    /**
  -     * Use this method to set the address that this message originated from.
  -     * This can be used when re-sending the EVT_GET_ALL_SESSIONS message to
  -     * another machine in the group.
  -     */
  -    public void setAddress(Member src)
  -    {
  -        this.mSrc = src;
  -    }
  -
  -    public String getContextName() {
  -       return mContextName;
  -    }
  -    public String getUniqueId() {
  -        return uniqueId;
  -    }
  -    public void setUniqueId(String uniqueId) {
  -        this.uniqueId = uniqueId;
  -    }
   }//SessionMessage
  
  
  
  1.24      +8 -8      jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
  
  Index: DeltaManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- DeltaManager.java	27 Apr 2004 17:50:43 -0000	1.23
  +++ DeltaManager.java	5 May 2004 16:36:12 -0000	1.24
  @@ -339,7 +339,7 @@
         
         
         if ( distribute ) {
  -          SessionMessage msg = new SessionMessage(
  +          SessionMessage msg = new SessionMessageImpl(
                 getName(),
                 SessionMessage.EVT_SESSION_CREATED,
                 null,
  @@ -631,7 +631,7 @@
               if (cluster.getMembers().length > 0) {
                   Member mbr = cluster.getMembers()[0];
                   SessionMessage msg =
  -                    new SessionMessage(this.getName(),
  +                    new SessionMessageImpl(this.getName(),
                                          SessionMessage.EVT_GET_ALL_SESSIONS,
                                          null,
                                          "GET-ALL");
  @@ -777,12 +777,12 @@
                  if (deltaRequest.getSize() > 0) {
      
                      byte[] data = unloadDeltaRequest(deltaRequest);
  -                   msg = new SessionMessage(name, SessionMessage.EVT_SESSION_DELTA,
  +                   msg = new SessionMessageImpl(name, SessionMessage.EVT_SESSION_DELTA,
                                               data, sessionId,
                                               sessionId+System.currentTimeMillis());
                      session.resetDeltaRequest();
                  } else if ( !session.isPrimarySession() ) {
  -                   msg = new SessionMessage(getName(),
  +                   msg = new SessionMessageImpl(getName(),
                                            SessionMessage.EVT_SESSION_ACCESSED,
                                            null,
                                            sessionId,
  @@ -793,7 +793,7 @@
                  if ( (msg == null) ) {
                      long replDelta = System.currentTimeMillis() - session.getLastTimeReplicated();
                      if ( replDelta > (getMaxInactiveInterval()*1000) ) {
  -                       msg = new SessionMessage(getName(),
  +                       msg = new SessionMessageImpl(getName(),
                                                SessionMessage.EVT_SESSION_ACCESSED,
                                                null,
                                                sessionId+System.currentTimeMillis());
  @@ -813,7 +813,7 @@
          }
          
          protected void sessionExpired(String id) {
  -           SessionMessage msg = new SessionMessage(getName(), 
  +           SessionMessage msg = new SessionMessageImpl(getName(), 
                                                      SessionMessage.EVT_SESSION_EXPIRED,
                                                      null,
                                                      id);
  @@ -848,7 +848,7 @@
                          log.debug("Manager ("+name+") unloading sessions");
                          byte[] data = doUnload();
                          log.debug("Manager ("+name+") unloading sessions complete");
  -                       SessionMessage newmsg = new SessionMessage(name,
  +                       SessionMessage newmsg = new SessionMessageImpl(name,
                              SessionMessage.EVT_ALL_SESSION_DATA,
                              data, "");
                          cluster.send(newmsg, sender);
  
  
  
  1.23      +5 -5      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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- SimpleTcpReplicationManager.java	27 Feb 2004 14:58:56 -0000	1.22
  +++ SimpleTcpReplicationManager.java	5 May 2004 16:36:13 -0000	1.23
  @@ -283,7 +283,7 @@
               if ( invalidatedSessions.get(sessionId) != null ) {
                   synchronized ( invalidatedSessions ) {
                       invalidatedSessions.remove(sessionId);
  -                    SessionMessage msg = new SessionMessage(name,
  +                    SessionMessage msg = new SessionMessageImpl(name,
                       SessionMessage.EVT_SESSION_EXPIRED,
                       null,
                       sessionId);
  @@ -303,7 +303,7 @@
                           long lastaccdist = System.currentTimeMillis() -
                               session.getLastAccessWasDistributed();
                           if ( ((interval*1000) / lastaccdist)< 3 ) {
  -                            SessionMessage accmsg = new SessionMessage(name,
  +                            SessionMessage accmsg = new SessionMessageImpl(name,
                                   SessionMessage.EVT_SESSION_ACCESSED,
                                   null,
                                   sessionId);
  @@ -320,7 +320,7 @@
                           }
                           catch (Exception ignore) {}
                       }
  -                    SessionMessage msg = new SessionMessage(name,
  +                    SessionMessage msg = new SessionMessageImpl(name,
                           SessionMessage.EVT_SESSION_CREATED,
                           writeSession(session),
                           session.getId());
  @@ -438,7 +438,7 @@
               if (cluster.getMembers().length > 0) {
                   Member mbr = cluster.getMembers()[0];
                   SessionMessage msg =
  -                    new SessionMessage(this.getName(),
  +                    new SessionMessageImpl(this.getName(),
                                          SessionMessage.EVT_GET_ALL_SESSIONS,
                                          null,
                                          "GET-ALL");
  @@ -535,7 +535,7 @@
                       oout.flush();
                       oout.close();
                       byte[] data = bout.toByteArray();
  -                    SessionMessage newmsg = new SessionMessage(name,
  +                    SessionMessage newmsg = new SessionMessageImpl(name,
                           SessionMessage.EVT_ALL_SESSION_DATA,
                           data, "");
                       cluster.send(newmsg, sender);
  
  
  
  1.1                  jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java
  
  Index: SessionMessageImpl.java
  ===================================================================
  package org.apache.catalina.cluster.session;
  
  import org.apache.catalina.cluster.SessionMessage;
  import org.apache.catalina.cluster.Member;
  /**
   * <p>Title: </p>
   * <p>Description: </p>
   * <p>Copyright: Copyright (c) 2004</p>
   * <p>Company: </p>
   * @author not attributable
   * @version 1.0
   */
  
  public class SessionMessageImpl implements SessionMessage, java.io.Serializable {
      public SessionMessageImpl() {
      }
      
      
      /*
  
       * Private serializable variables to keep the messages state
       */
      private int mEvtType = -1;
      private byte[] mSession;
      private String mSessionID;
      private Member mSrc;
      private String mContextName;
      private long serializationTimestamp;
      private String uniqueId;
  
  
      /**
       * Creates a session message. Depending on what event type you want this
       * message to represent, you populate the different parameters in the constructor<BR>
       * The following rules apply dependent on what event type argument you use:<BR>
       * <B>EVT_SESSION_CREATED</B><BR>
       *    The parameters: session, sessionID must be set.<BR>
       * <B>EVT_SESSION_EXPIRED</B><BR>
       *    The parameters: sessionID must be set.<BR>
       * <B>EVT_SESSION_ACCESSED</B><BR>
       *    The parameters: sessionID must be set.<BR>
       * <B>EVT_SESSION_EXPIRED_XXXX</B><BR>
       *    The parameters: sessionID must be set.<BR>
       * <B>EVT_ATTRIBUTE_ADDED</B><BR>
       *    The parameters: sessionID, attrName, attrValue must be set.<BR>
       * <B>EVT_ATTRIBUTE_REMOVED</B><BR>
       *    The parameters: sessionID, attrName must be set.<BR>
       * <B>EVT_SET_USER_PRINCIPAL</B><BR>
       *    The parameters: sessionID, principal<BR>
       * <B>EVT_REMOVE_SESSION_NOTE</B><BR>
       *    The parameters: sessionID, attrName<
       * <B>EVT_SET_SESSION_NOTE</B><BR>
       *    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
       * @param attrName - the name of the attribute added/removed
       * @param attrValue - the value of the attribute added
  
       */
      public SessionMessageImpl( String contextName,
                             int eventtype,
                             byte[] session,
                             String sessionID)
      {
          mEvtType = eventtype;
          mSession = session;
          mSessionID = sessionID;
          mContextName = contextName;
          uniqueId = sessionID;
      }
  
      public SessionMessageImpl( String contextName,
                             int eventtype,
                             byte[] session,
                             String sessionID,
                             String uniqueID)
      {
          this(contextName,eventtype,session,sessionID);
          uniqueId = uniqueID;
      }
  
      /**
       * returns the event type
       * @return one of the event types EVT_XXXX
       */
      public int getEventType() { return mEvtType; }
      /**
       * @return the serialized data for the session
       */
      public byte[] getSession() { return mSession;}
      /**
       * @return the session ID for the session
       */
      public String getSessionID(){ return mSessionID; }
      /**
       * @return the name of the attribute
       */
  //    public String getAttributeName() { return mAttributeName; }
      /**
       * the value of the attribute
       */
  //    public Object getAttributeValue() {return mAttributeValue; }
  
  //    public SerializablePrincipal getPrincipal() { return mPrincipal;}
  
      public void setTimestamp(long time) {serializationTimestamp=time;}
      public long getTimestamp() { return serializationTimestamp;}
      /**
       * @return the event type in a string representating, useful for debugging
       */
      public String getEventTypeString()
      {
          switch (mEvtType)
          {
              case EVT_SESSION_CREATED : return "SESSION-MODIFIED";
              case EVT_SESSION_EXPIRED : return "SESSION-EXPIRED";
              case EVT_SESSION_ACCESSED : return "SESSION-ACCESSED";
              case EVT_GET_ALL_SESSIONS : return "SESSION-GET-ALL";
              case EVT_SESSION_DELTA : return "SESSION-DELTA";
              case EVT_ALL_SESSION_DATA : return "ALL-SESSION-DATA";
              default : return "UNKNOWN-EVENT-TYPE";
          }
      }
  
      /**
       * 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()
      {
          return this.mSrc;
      }
  
      /**
       * Use this method to set the address that this message originated from.
       * This can be used when re-sending the EVT_GET_ALL_SESSIONS message to
       * another machine in the group.
       */
      public void setAddress(Member src)
      {
          this.mSrc = src;
      }
  
      public String getContextName() {
         return mContextName;
      }
      public String getUniqueId() {
          return uniqueId;
      }
      public void setUniqueId(String uniqueId) {
          this.uniqueId = uniqueId;
      }
  
  
  }
  
  
  

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