fhanik      2004/02/05 13:08:02

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java DeltaRequest.java
                        DeltaSession.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        SimpleTcpCluster.java
  Log:
  Ported latest bugfixes from StandardSession, hopefully in a near future I can extend 
it, but for now, this is they way it is
  
  Revision  Changes    Path
  1.11      +5 -4      
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DeltaManager.java 5 Feb 2004 01:02:48 -0000       1.10
  +++ DeltaManager.java 5 Feb 2004 21:08:02 -0000       1.11
  @@ -936,6 +936,7 @@
       // -------------------------------------------------------- Private Methods
   
       public void backgroundProcess() {
  +        log.debug("DeltaManager.backgroundProcess invoked at 
"+System.currentTimeMillis());
           processExpires();
       }
       /**
  
  
  
  1.5       +8 -3      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaRequest.java
  
  Index: DeltaRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaRequest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DeltaRequest.java 13 Jan 2004 04:22:28 -0000      1.4
  +++ DeltaRequest.java 5 Feb 2004 21:08:02 -0000       1.5
  @@ -215,6 +215,11 @@
           return actions.size();
       }
       
  +    public void clear() {
  +        actions.clear();
  +        actionPool.clear();
  +    }
  +    
       public void readExternal(java.io.ObjectInput in) throws java.io.IOException,
           java.lang.ClassNotFoundException {
           //sessionId - String
  
  
  
  1.12      +106 -94   
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DeltaSession.java 4 Feb 2004 20:22:26 -0000       1.11
  +++ DeltaSession.java 5 Feb 2004 21:08:02 -0000       1.12
  @@ -339,6 +339,11 @@
        */
       private transient long lastTimeReplicated = System.currentTimeMillis();
       
  +    /**
  +     * The access count for this session
  +     */
  +    protected transient int accessCount = 1;
  +    
       // ----------------------------------------------------- Session Properties
   
       /**
  @@ -642,6 +647,10 @@
               return false;
           }
           
  +        if (accessCount > 0 ) {
  +            return true;
  +        }
  +        
           if (maxInactiveInterval >= 0) {
               long timeNow = System.currentTimeMillis();
               int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
  @@ -686,11 +695,14 @@
           this.thisAccessedTime = System.currentTimeMillis();
   
           evaluateIfValid();
  +        
  +        accessCount++;
       }
   
   
       public void endAccess() {
  -        // FIXME
  +        isNew = false;
  +        accessCount--;
       }
   
   
  @@ -777,17 +789,13 @@
                       }
                   }
               }
  +            accessCount=0;
               setValid(false);
   
               // Remove this session from our manager's active sessions
               if (manager != null)
                   manager.remove(this);
   
  -            // Unbind any objects associated with this session
  -            String keys[] = keys();
  -            for (int i = 0; i < keys.length; i++)
  -                removeAttribute(keys[i], notify);
  -
               // Notify interested session event listeners
               if (notify) {
                   fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
  @@ -795,6 +803,13 @@
   
               // We have completed expire of this session
               expiring = false;
  +
  +            // Unbind any objects associated with this session
  +            String keys[] = keys();
  +            for (int i = 0; i < keys.length; i++)
  +                removeAttributeInternal(keys[i], notify, false);
  +
  +
               
               if ( notifyCluster ) {
                   log.debug("Notifying cluster of expiration primary=" +
  @@ -849,11 +864,13 @@
           id = null;
           lastAccessedTime = 0L;
           maxInactiveInterval = -1;
  +        accessCount = 1;
           notes.clear();
           setPrincipal(null);
           isNew = false;
           isValid = false;
           manager = null;
  +        deltaRequest.clear();
   
       }
   
  @@ -1217,67 +1234,10 @@
           if (!isValid())
               throw new IllegalStateException
                   (sm.getString("standardSession.removeAttribute.ise"));
  -
  -        // Remove this attribute from our collection
  -        Object value = null;
  -        boolean found = false;
  -        synchronized (attributes) {
  -            found = attributes.containsKey(name);
  -            if (found) {
  -                value = attributes.get(name);
  -                attributes.remove(name);
  -            } else {
  -                return;
  -            }
  -        }
  -        
  -        if (addDeltaRequest && (deltaRequest!=null)) 
deltaRequest.removeAttribute(name);
  -
  -        // Do we need to do valueUnbound() and attributeRemoved() notification?
  -        if (!notify) {
  -            return;
  -        }
  -
  -        // Call the valueUnbound() method if necessary
  -        HttpSessionBindingEvent event =
  -          new HttpSessionBindingEvent((HttpSession) this, name, value);
  -        if ((value != null) &&
  -            (value instanceof HttpSessionBindingListener))
  -            ((HttpSessionBindingListener) value).valueUnbound(event);
  -
  -        // Notify interested application event listeners
  -        Context context = (Context) manager.getContainer();
  -        Object listeners[] = context.getApplicationEventListeners();
  -        if (listeners == null)
  -            return;
  -        for (int i = 0; i < listeners.length; i++) {
  -            if (!(listeners[i] instanceof HttpSessionAttributeListener))
  -                continue;
  -            HttpSessionAttributeListener listener =
  -                (HttpSessionAttributeListener) listeners[i];
  -            try {
  -                fireContainerEvent(context,
  -                                   "beforeSessionAttributeRemoved",
  -                                   listener);
  -                listener.attributeRemoved(event);
  -                fireContainerEvent(context,
  -                                   "afterSessionAttributeRemoved",
  -                                   listener);
  -            } catch (Throwable t) {
  -                try {
  -                    fireContainerEvent(context,
  -                                       "afterSessionAttributeRemoved",
  -                                       listener);
  -                } catch (Exception e) {
  -                    ;
  -                }
  -                // FIXME - should we do anything besides log these?
  -                log.error(sm.getString("standardSession.attributeEvent"), t);
  -            }
  -        }
  -
  +        removeAttributeInternal(name,notify,addDeltaRequest);
       }
  -
  +    
  +    
   
       /**
        * Remove the object bound with the specified name from this session.  If
  @@ -1351,12 +1311,18 @@
               throw new IllegalArgumentException
                   (sm.getString("standardSession.setAttribute.iae"));
   
  -        // Replace or add this attribute
  -        Object unbound = null;
  -        synchronized (attributes) {
  -            unbound = attributes.get(name);
  -            attributes.put(name, value);
  +        
  +        // Construct an event with the new value
  +        HttpSessionBindingEvent event = null;
  +        
  +        // Call the valueBound() method if necessary
  +        if ( value instanceof HttpSessionBindingListener ) {
  +            event = new HttpSessionBindingEvent(this, name, value);
  +            ((HttpSessionBindingListener) value).valueBound(event);
           }
  +        
  +        // Replace or add this attribute
  +        Object unbound = attributes.put(name, value);
   
           // Call the valueUnbound() method if necessary
           if ((unbound != null) &&
  @@ -1365,16 +1331,6 @@
                 (new HttpSessionBindingEvent((HttpSession) this, name));
           }
   
  -        // Call the valueBound() method if necessary
  -        HttpSessionBindingEvent event = null;
  -        if (unbound != null)
  -            event = new HttpSessionBindingEvent
  -                ((HttpSession) this, name, unbound);
  -        else
  -            event = new HttpSessionBindingEvent
  -                ((HttpSession) this, name, value);
  -        if (value instanceof HttpSessionBindingListener)
  -            ((HttpSessionBindingListener) value).valueBound(event);
   
           // Notify interested application event listeners
           Context context = (Context) manager.getContainer();
  @@ -1391,6 +1347,10 @@
                       fireContainerEvent(context,
                                          "beforeSessionAttributeReplaced",
                                          listener);
  +                    if ( event == null ) {
  +                        event = new HttpSessionBindingEvent
  +                            (this,name,unbound);
  +                    }
                       listener.attributeReplaced(event);
                       fireContainerEvent(context,
                                          "afterSessionAttributeReplaced",
  @@ -1399,6 +1359,10 @@
                       fireContainerEvent(context,
                                          "beforeSessionAttributeAdded",
                                          listener);
  +                    if (event == null) {
  +                        event = new HttpSessionBindingEvent
  +                            (this, name, unbound);
  +                    }
                       listener.attributeAdded(event);
                       fireContainerEvent(context,
                                          "afterSessionAttributeAdded",
  @@ -1559,13 +1523,7 @@
           if (!this.isValid || expiring || maxInactiveInterval < 0)
               return;
   
  -        if (!isValid()) {
  -            try {
  -                expire();
  -            } catch (Throwable t) {
  -                log.error(sm.getString("standardSession.expireException"), t);
  -            }
  -        }
  +        isValid();
   
       }
   
  @@ -1635,7 +1593,7 @@
        * as an array of Strings.  If there are no defined attributes, a
        * zero-length array is returned.
        */
  -    private String[] keys() {
  +    protected String[] keys() {
   
           String results[] = new String[0];
           synchronized (attributes) {
  @@ -1648,13 +1606,67 @@
       /**
        * Return the value of an attribute without a check for validity.
        */
  -    private Object getAttributeInternal(String name) {
  +    protected Object getAttributeInternal(String name) {
   
           synchronized (attributes) {
               return (attributes.get(name));
           }
   
       }
  +    
  +    protected void removeAttributeInternal(String name, boolean notify, boolean 
addDeltaRequest) {
  +
  +        // Remove this attribute from our collection
  +        Object value = attributes.remove(name);
  +        if ( value == null ) return;
  +
  +        if (addDeltaRequest && (deltaRequest!=null)) 
deltaRequest.removeAttribute(name);
  +
  +        // Do we need to do valueUnbound() and attributeRemoved() notification?
  +        if (!notify) {
  +            return;
  +        }
  +
  +        // Call the valueUnbound() method if necessary
  +        HttpSessionBindingEvent event =
  +          new HttpSessionBindingEvent((HttpSession) this, name, value);
  +        if ((value != null) &&
  +            (value instanceof HttpSessionBindingListener))
  +            ((HttpSessionBindingListener) value).valueUnbound(event);
  +
  +        // Notify interested application event listeners
  +        Context context = (Context) manager.getContainer();
  +        Object listeners[] = context.getApplicationEventListeners();
  +        if (listeners == null)
  +            return;
  +        for (int i = 0; i < listeners.length; i++) {
  +            if (!(listeners[i] instanceof HttpSessionAttributeListener))
  +                continue;
  +            HttpSessionAttributeListener listener =
  +                (HttpSessionAttributeListener) listeners[i];
  +            try {
  +                fireContainerEvent(context,
  +                                   "beforeSessionAttributeRemoved",
  +                                   listener);
  +                listener.attributeRemoved(event);
  +                fireContainerEvent(context,
  +                                   "afterSessionAttributeRemoved",
  +                                   listener);
  +            } catch (Throwable t) {
  +                try {
  +                    fireContainerEvent(context,
  +                                       "afterSessionAttributeRemoved",
  +                                       listener);
  +                } catch (Exception e) {
  +                    ;
  +                }
  +                // FIXME - should we do anything besides log these?
  +                log.error(sm.getString("standardSession.attributeEvent"), t);
  +            }
  +        }
  +
  +    }
  +
       
       protected long getLastTimeReplicated() {
           return lastTimeReplicated;
  
  
  
  1.32      +6 -6      
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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- SimpleTcpCluster.java     5 Feb 2004 16:07:57 -0000       1.31
  +++ SimpleTcpCluster.java     5 Feb 2004 21:08:02 -0000       1.32
  @@ -127,14 +127,13 @@
       public static org.apache.commons.logging.Log log =
           org.apache.commons.logging.LogFactory.getLog( SimpleTcpCluster.class );
   
  -
       // ----------------------------------------------------- Instance Variables
   
   
       /**
        * Descriptive information about this component implementation.
        */
  -    protected static final String info = "SimpleTcpCluster2/1.0";
  +    protected static final String info = "SimpleTcpCluster/1.0";
   
   
       /**
  @@ -339,6 +338,7 @@
   
   
       public synchronized Manager createManager(String name) {
  +        log.debug("Creating ClusterManager for context "+name + " using class 
"+getManagerClassName());
           ClusterManager manager = null;
           try {
               manager = 
(ClusterManager)getClass().getClassLoader().loadClass(getManagerClassName()).newInstance();
  
  
  

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

Reply via email to