costin      2003/02/06 15:01:41

  Modified:    catalina/src/share/org/apache/catalina/session
                        ManagerBase.java
  Log:
  Another backport from head: more informations about the session creation (to
  be exposed via JMX or used directly ).
  
  This is very usefull in debugging and in finding out what happens in production
  servers.
  
  Revision  Changes    Path
  1.18      +115 -8    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/ManagerBase.java
  
  Index: ManagerBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/ManagerBase.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ManagerBase.java  1 Jan 2003 06:24:26 -0000       1.17
  +++ ManagerBase.java  6 Feb 2003 23:01:41 -0000       1.18
  @@ -73,6 +73,9 @@
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Random;
  +import java.util.Iterator;
  +import java.util.Date;
  +
   import org.apache.catalina.Container;
   import org.apache.catalina.DefaultContext;
   import org.apache.catalina.Engine;
  @@ -135,8 +138,8 @@
        * The DefaultContext with which this Manager is associated.
        */
       protected DefaultContext defaultContext = null;
  -    
  -    
  +
  +
       /**
        * Return the MessageDigest implementation to be used when
        * creating session identifiers.
  @@ -203,6 +206,14 @@
        */
       protected HashMap sessions = new HashMap();
   
  +    // Total number of sessions created by this manager
  +    protected int sessionCounter=0;
  +
  +    protected int maxActive=0;
  +
  +    // number of duplicated session ids - anything >0 means we have problems
  +    protected int duplicates=0;
  +
   
       /**
        * The string manager for this package.
  @@ -290,8 +301,8 @@
           support.firePropertyChange("defaultContext", oldDefaultContext, 
this.defaultContext);
   
       }
  -    
  -    
  +
  +
       /**
        * Return the debugging detail level for this component.
        */
  @@ -530,6 +541,9 @@
   
           synchronized (sessions) {
               sessions.put(session.getId(), session);
  +            if( sessions.size() > maxActive ) {
  +                maxActive=sessions.size();
  +            }
           }
   
       }
  @@ -588,6 +602,7 @@
           synchronized (sessions) {
               while (sessions.get(sessionId) != null){ // Guarantee uniqueness
                   sessionId = generateSessionId();
  +                duplicates++;
                   // @todo Move appending of jvmRoute generateSessionId()???
                   if (jvmRoute != null) {
                       sessionId += '.' + jvmRoute;
  @@ -596,6 +611,7 @@
           }
   
           session.setId(sessionId);
  +        sessionCounter++;
   
           return (session);
   
  @@ -795,5 +811,96 @@
   
       }
   
  +    public void setSessionCounter(int sessionCounter) {
  +        this.sessionCounter = sessionCounter;
  +    }
  +
  +    /** Total sessions created by this manager.
  +     *
  +     * @return sessions created
  +     */
  +    public int getSessionCounter() {
  +        return sessionCounter;
  +    }
  +
  +    /** Number of duplicated session IDs generated by the random source.
  +     *  Anything bigger than 0 means problems.
  +     *
  +     * @return
  +     */
  +    public int getDuplicates() {
  +        return duplicates;
  +    }
  +
  +    public void setDuplicates(int duplicates) {
  +        this.duplicates = duplicates;
  +    }
  +
  +    /** Returns the number of active sessions
  +     *
  +     * @return number of sessions active
  +     */
  +    public int getActiveSessions() {
  +        return sessions.size();
  +    }
  +
  +    /** Max number of concurent active sessions
  +     *
  +     * @return
  +     */
  +    public int getMaxActive() {
  +        return maxActive;
  +    }
  +
  +    public void setMaxActive(int maxActive) {
  +        this.maxActive = maxActive;
  +    }
  +
  +    /** For debugging: return a list of all session ids currently active
  +     *
  +     */
  +    public String listSessionIds() {
  +        StringBuffer sb=new StringBuffer();
  +        Iterator keys=sessions.keySet().iterator();
  +        while( keys.hasNext() ) {
  +            sb.append(keys.next()).append(" ");
  +        }
  +        return sb.toString();
  +    }
  +
  +    /** For debugging: get a session attribute
  +     *
  +     * @param sessionId
  +     * @param key
  +     * @return
  +     */
  +    public String getSessionAttribute( String sessionId, String key ) {
  +        Session s=(Session)sessions.get(sessionId);
  +        if( s==null ) {
  +            log("Session not found " + sessionId);
  +            return null;
  +        }
  +        Object o=s.getSession().getAttribute(key);
  +        if( o==null ) return null;
  +        return o.toString();
  +    }
  +
  +    public void expireSession( String sessionId ) {
  +        Session s=(Session)sessions.get(sessionId);
  +        if( s==null ) {
  +            log("Session not found " + sessionId);
  +            return;
  +        }
  +        s.expire();
  +    }
  +
  +    public String getLastAccessedTime( String sessionId ) {
  +        Session s=(Session)sessions.get(sessionId);
  +        if( s==null ) {
  +            log("Session not found " + sessionId);
  +            return "";
  +        }
  +        return new Date(s.getLastAccessedTime()).toString();
  +    }
   
   }
  
  
  

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

Reply via email to