fhanik      2004/01/12 21:26:59

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java DeltaSession.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        ReplicationValve.java SimpleTcpCluster.java
  Log:
  Implemented distributed expiration of sessions.
  
  Revision  Changes    Path
  1.6       +14 -7     
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DeltaManager.java 13 Jan 2004 04:22:28 -0000      1.5
  +++ DeltaManager.java 13 Jan 2004 05:26:59 -0000      1.6
  @@ -808,6 +808,14 @@
              }
      
          }
  +       
  +       protected void sessionExpired(String id) {
  +           SessionMessage msg = new SessionMessage(getName(), 
  +                                                   
SessionMessage.EVT_SESSION_EXPIRED,
  +                                                   null,
  +                                                   id);
  +           cluster.send(msg);
  +       }
      
          /**
           * When the manager expires session not tied to a request.
  @@ -856,10 +864,9 @@
                          break;
                      }
                      case SessionMessage.EVT_SESSION_EXPIRED: {
  -                       Session session = findSession(msg.getSessionID());
  +                       DeltaSession session = 
(DeltaSession)findSession(msg.getSessionID());
                          if (session != null) {
  -                           session.expire();
  -                           this.remove(session);
  +                           session.expire(true,false);
                          } //end if
                          break;
                      }
  
  
  
  1.8       +29 -11    
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
  
  Index: DeltaSession.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DeltaSession.java 13 Jan 2004 04:22:28 -0000      1.7
  +++ DeltaSession.java 13 Jan 2004 05:26:59 -0000      1.8
  @@ -347,7 +347,7 @@
        * @param primarySession
        */
       public void setPrimarySession(boolean primarySession) {
  -       this.isPrimarySession=primarySession;
  +        this.isPrimarySession=primarySession;
       }
   
       /**
  @@ -543,7 +543,7 @@
           if (isValid && interval == 0) {
               expire();
           } else {
  -            if ( addDeltaRequest ) deltaRequest.setMaxInactiveInterval(interval);
  +            if ( addDeltaRequest && (deltaRequest!=null) ) 
deltaRequest.setMaxInactiveInterval(interval);
           }
   
       }
  @@ -559,7 +559,7 @@
       }
       public void setNew(boolean isNew, boolean addDeltaRequest) {
           this.isNew = isNew;
  -        if (addDeltaRequest) deltaRequest.setNew(isNew);
  +        if (addDeltaRequest && (deltaRequest!=null)) deltaRequest.setNew(isNew);
       }
   
   
  @@ -592,7 +592,7 @@
           Principal oldPrincipal = this.principal;
           this.principal = principal;
           support.firePropertyChange("principal", oldPrincipal, this.principal);
  -        if (addDeltaRequest) deltaRequest.setPrincipal(principal);
  +        if (addDeltaRequest && (deltaRequest!=null)) 
deltaRequest.setPrincipal(principal);
       }
   
   
  @@ -624,6 +624,8 @@
        */
       public boolean isValid() {
           
  +        
  +        
           if (this.expiring){
               return true;
           }
  @@ -631,12 +633,16 @@
           if (!this.isValid ) {
               return false;
           }
  -
  +        
           if (maxInactiveInterval >= 0) {
               long timeNow = System.currentTimeMillis();
               int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
               if ( (timeIdle >= maxInactiveInterval) && (isPrimarySession()) ) {
                   expire(true);
  +            } else if ( timeIdle >= (2*maxInactiveInterval) ) {
  +                //if the session has been idle twice as long as allowed,
  +                //the primary session has probably crashed
  +                expire(true);
               }
           }
   
  @@ -704,10 +710,16 @@
        *  this session?
        */
       public void expire(boolean notify) {
  +        expire(notify,true);
  +    }
  +    
  +    public void expire(boolean notify, boolean notifyCluster) {
   
           // Mark this session as "being expired" if needed
           if (expiring)
               return;
  +        
  +        String expiredId = getId();
   
           synchronized (this) {
   
  @@ -768,6 +780,12 @@
   
               // We have completed expire of this session
               expiring = false;
  +            
  +            if ( notifyCluster ) {
  +                log.debug("Notifying cluster of expiration primary=" +
  +                         isPrimarySession() + " id=" + expiredId);
  +                ( (DeltaManager) manager).sessionExpired(expiredId);
  +            }
   
           }
   
  @@ -1198,7 +1216,7 @@
               }
           }
           
  -        if (addDeltaRequest) deltaRequest.removeAttribute(name);
  +        if (addDeltaRequest && (deltaRequest!=null)) 
deltaRequest.removeAttribute(name);
   
           // Do we need to do valueUnbound() and attributeRemoved() notification?
           if (!notify) {
  @@ -1307,7 +1325,7 @@
               throw new IllegalArgumentException("Attribute ["+name+"] is not 
serializable");
           }
           
  -        if (addDeltaRequest) deltaRequest.setAttribute(name,value);
  +        if (addDeltaRequest && (deltaRequest!=null)) 
deltaRequest.setAttribute(name,value);
   
           // Validate our current state
           if (!isValid())
  
  
  
  1.9       +5 -5      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationValve.java
  
  Index: ReplicationValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationValve.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ReplicationValve.java     12 Jan 2004 07:50:07 -0000      1.8
  +++ ReplicationValve.java     13 Jan 2004 05:26:59 -0000      1.9
  @@ -154,7 +154,7 @@
       protected static synchronized void addClusterSendTime(long time) {
           totalSendTime+=time;
           nrOfRequests++;
  -        if ( (System.currentTimeMillis()-lastSendTime)>5000 ) {
  +        if ( (nrOfRequests % 100) == 0 ) {
               log.info("Average cluster serialize/send 
time="+(totalSendTime/nrOfRequests)+" ms for "+
                        nrOfRequests+" requests ("+totalSendTime+"ms).");
               lastSendTime=System.currentTimeMillis();
  
  
  
  1.27      +4 -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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- SimpleTcpCluster.java     13 Jan 2004 04:22:28 -0000      1.26
  +++ SimpleTcpCluster.java     13 Jan 2004 05:26:59 -0000      1.27
  @@ -719,19 +719,6 @@
       }
   
       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
       }
   
       // --------------------------------------------------------- Cluster Wide 
Deployments
  
  
  

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

Reply via email to