You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/12/11 00:00:36 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session PersistentManagerBase.java StandardManager.java mbeans-descriptors.xml

remm        2003/12/10 15:00:36

  Modified:    catalina/src/share/org/apache/catalina/session
                        PersistentManagerBase.java StandardManager.java
                        mbeans-descriptors.xml
  Log:
  - Cleanups in the managers. (but I didn't test it)
  - Thanks to Amy for looking in PersistentManager.
  - Add JMX declaration for PersistentManager. Was it really not there ?
  - Copy over the useful stats from StandardManager.
  
  Revision  Changes    Path
  1.14      +90 -31    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/PersistentManagerBase.java
  
  Index: PersistentManagerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/PersistentManagerBase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PersistentManagerBase.java	14 Nov 2003 10:30:29 -0000	1.13
  +++ PersistentManagerBase.java	10 Dec 2003 23:00:36 -0000	1.14
  @@ -103,7 +103,8 @@
       private static Log log = LogFactory.getLog(PersistentManagerBase.class);
   
       // ---------------------------------------------------- Security Classes
  -     private class PrivilegedStoreClear
  +
  +    private class PrivilegedStoreClear
           implements PrivilegedExceptionAction {
   
           PrivilegedStoreClear() {            
  @@ -115,7 +116,7 @@
           }                       
       }   
        
  -     private class PrivilegedStoreRemove
  +    private class PrivilegedStoreRemove
           implements PrivilegedExceptionAction {
   
           private String id;    
  @@ -168,7 +169,8 @@
           public Object run() throws Exception{
              return store.keys();
           }                       
  -    }   
  +    }
  +
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -187,39 +189,39 @@
       /**
        * The maximum number of active Sessions allowed, or -1 for no limit.
        */
  -    private int maxActiveSessions = -1;
  +    protected int maxActiveSessions = -1;
   
   
       /**
        * The descriptive name of this Manager implementation (for logging).
        */
  -    protected static String name = "PersistentManagerBase";
  +    private static String name = "PersistentManagerBase";
   
   
       /**
        * Has this component been started yet?
        */
  -    private boolean started = false;
  +    protected boolean started = false;
   
   
       /**
        * Store object which will manage the Session store.
        */
  -    private Store store = null;
  +    protected Store store = null;
   
   
       /**
        * Whether to save and reload sessions when the Manager <code>unload</code>
        * and <code>load</code> methods are called.
        */
  -    private boolean saveOnRestart = true;
  +    protected boolean saveOnRestart = true;
   
   
       /**
        * How long a session must be idle before it should be backed up.
        * -1 means sessions won't be backed up.
        */
  -    private int maxIdleBackup = -1;
  +    protected int maxIdleBackup = -1;
   
   
       /**
  @@ -227,30 +229,57 @@
        * This overrides maxActiveSessions, to prevent thrashing if there are lots
        * of active sessions. Setting to -1 means it's ignored.
        */
  -    private int minIdleSwap = -1;
  +    protected int minIdleSwap = -1;
   
       /**
        * The maximum time a session may be idle before it should be swapped
        * to file just on general principle. Setting this to -1 means sessions
        * should not be forced out.
        */
  -    private int maxIdleSwap = -1;
  +    protected int maxIdleSwap = -1;
  +
  +
  +    /**
  +     * Number of session creations that failed due to maxActiveSessions.
  +     */
  +    protected int rejectedSessions = 0;
  +
  +
  +    /**
  +     * Number of sessions that expired.
  +     */
  +    protected int expiredSessions = 0;
  +
  +
  +    /**
  +     * Processing time during session expiration and passivation.
  +     */
  +    protected long processingTime = 0;
   
   
       // ------------------------------------------------------------- Properties
   
  -/**
  +
  +    /**
        * Perform the background processes for this Manager
        */
       public void backgroundProcess() {
  +
  +        long timeNow = System.currentTimeMillis();
  +
           this.processExpires();
           this.processPersistenceChecks();
           if ((this.getStore() != null)
               && (this.getStore() instanceof StoreBase)) {
               ((StoreBase) this.getStore()).processExpires();
           }
  +
  +        long timeEnd = System.currentTimeMillis();
  +        processingTime += ( timeEnd - timeNow );
  +
       }
   
  +
       /**
        * Indicates how many seconds old a session can get, after its last
        * use in a request, before it should be backed up to the store. -1
  @@ -440,6 +469,42 @@
       }
   
   
  +    /** 
  +     * Number of session creations that failed due to maxActiveSessions.
  +     *
  +     * @return
  +     */
  +    public int getRejectedSessions() {
  +        return rejectedSessions;
  +    }
  +
  +
  +    
  +    public void setRejectedSessions(int rejectedSessions) {
  +        this.rejectedSessions = rejectedSessions;
  +    }
  +
  +    /** Number of sessions that expired.
  +     *
  +     * @return
  +     */
  +    public int getExpiredSessions() {
  +        return expiredSessions;
  +    }
  +
  +    public void setExpiredSessions(int expiredSessions) {
  +        this.expiredSessions = expiredSessions;
  +    }
  +
  +    public long getProcessingTime() {
  +        return processingTime;
  +    }
  +
  +    public void setProcessingTime(long processingTime) {
  +        this.processingTime = processingTime;
  +    }
  +
  +
       /**
        * Return the descriptive short name of this Manager implementation.
        */
  @@ -565,20 +630,12 @@
        */
       public void processExpires() {
   
  -        if (!started)
  -            return;
  -
  -        long timeNow = System.currentTimeMillis();
           Session sessions[] = findSessions();
   
           for (int i = 0; i < sessions.length; i++) {
               StandardSession session = (StandardSession) sessions[i];
               if (!session.isValid()) {
  -                try {
  -                    session.expire();
  -                } catch (Throwable t) {
  -                    ;
  -                }
  +                expiredSessions++;
   	    }
           }
   
  @@ -592,9 +649,9 @@
        */
       public void processPersistenceChecks() {
   
  -            processMaxIdleSwaps();
  -            processMaxActiveSwaps();
  -            processMaxIdleBackups();
  +        processMaxIdleSwaps();
  +        processMaxActiveSwaps();
  +        processMaxIdleBackups();
   
       }
   
  @@ -611,9 +668,11 @@
       public Session createSession() {
   
           if ((maxActiveSessions >= 0) &&
  -          (sessions.size() >= maxActiveSessions))
  +            (sessions.size() >= maxActiveSessions)) {
  +            rejectedSessions++;
               throw new IllegalStateException
                   (sm.getString("standardManager.createSession.ise"));
  +        }
   
           return (super.createSession());
   
  @@ -730,7 +789,7 @@
        *
        * @param is Session's id to be removed
        */    
  -    private void removeSession(String id){
  +    protected void removeSession(String id){
           try {
               if (System.getSecurityManager() != null){
                   try{
  @@ -1048,7 +1107,7 @@
       }
   
   
  -    // -------------------------------------------------------- Private Methods
  +    // ------------------------------------------------------ Protected Methods
   
   
       /**
  
  
  
  1.17      +21 -8     jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardManager.java
  
  Index: StandardManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardManager.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StandardManager.java	5 Dec 2003 09:28:55 -0000	1.16
  +++ StandardManager.java	10 Dec 2003 23:00:36 -0000	1.17
  @@ -183,9 +183,22 @@
       protected boolean started = false;
   
   
  -    int rejectedSessions=0;
  -    int expiredSessions=0;
  -    long processingTime=0;
  +    /**
  +     * Number of session creations that failed due to maxActiveSessions.
  +     */
  +    protected int rejectedSessions = 0;
  +
  +
  +    /**
  +     * Number of sessions that expired.
  +     */
  +    protected int expiredSessions = 0;
  +
  +
  +    /**
  +     * Processing time during session expiration.
  +     */
  +    protected long processingTime = 0;
   
   
       // ------------------------------------------------------------- Properties
  @@ -338,7 +351,7 @@
       public Session createSession() {
   
           if ((maxActiveSessions >= 0) &&
  -          (sessions.size() >= maxActiveSessions)) {
  +            (sessions.size() >= maxActiveSessions)) {
               rejectedSessions++;
               throw new IllegalStateException
                   (sm.getString("standardManager.createSession.ise"));
  
  
  
  1.3       +138 -0    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/mbeans-descriptors.xml
  
  Index: mbeans-descriptors.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/mbeans-descriptors.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mbeans-descriptors.xml	27 May 2003 23:15:06 -0000	1.2
  +++ mbeans-descriptors.xml	10 Dec 2003 23:00:36 -0000	1.3
  @@ -129,4 +129,142 @@
   
     </mbean>
   
  +  <mbean         name="PersistentManager"
  +          description="Persistent Manager"
  +               domain="Catalina"
  +                group="Manager"
  +                 type="org.apache.catalina.session.PersistentManager">
  +
  +    <attribute   name="algorithm"
  +          description="The message digest algorithm to be used when generating
  +                       session identifiers"
  +                 type="java.lang.String"/>
  +
  +    <attribute   name="randomFile"
  +          description="File source of random - /dev/urandom or a pipe"
  +                 type="java.lang.String"/>
  +
  +    <attribute   name="className"
  +          description="Fully qualified class name of the managed object"
  +                 type="java.lang.String"
  +            writeable="false"/>
  +
  +    <attribute   name="debug"
  +          description="The debugging detail level for this component"
  +                 type="int"/>
  +
  +    <attribute   name="distributable"
  +          description="The distributable flag for Sessions created by this
  +                       Manager"
  +                 type="boolean"/>
  +
  +    <attribute   name="entropy"
  +          description="A String initialization parameter used to increase the
  +                       entropy of the initialization of our random number
  +                       generator"
  +                 type="java.lang.String"/>
  + 
  +    <attribute   name="managedResource"
  +          description="The managed resource this MBean is associated with"
  +                 type="java.lang.Object"/>
  +
  +    <attribute   name="maxActiveSessions"
  +          description="The maximum number of active Sessions allowed, or -1
  +                       for no limit"
  +                 type="int"/>
  +
  +    <attribute   name="maxInactiveInterval"
  +          description="The default maximum inactive interval for Sessions
  +                       created by this Manager"
  +                 type="int"/>
  +
  +    <attribute   name="name"
  +          description="The descriptive name of this Manager implementation
  +                       (for logging)"
  +                 type="java.lang.String"
  +            writeable="false"/>
  +
  +    <attribute   name="pathname"
  +          description="Path name of the disk file in which active sessions"
  +                 type="java.lang.String"/>
  +
  +    <attribute   name="activeSessions"
  +          description="Number of active sessions at this moment"
  +                 type="int" 
  +            writeable="false"/>
  +
  +    <attribute   name="sessionCounter"
  +          description="Total number of sessions created by this manager"
  +                 type="int" />
  +
  +    <attribute   name="maxActive"
  +          description="Maximum number of active sessions so far"
  +                 type="int" />
  +
  +    <attribute   name="maxIdleBackup"
  +          description="How long a session must be idle before it should be backed up"
  +                 type="int" />
  +
  +    <attribute   name="minIdleSwap"
  +          description="Minimum time a session must be idle before it is swapped to disk"
  +                 type="int" />
  +
  +    <attribute   name="maxIdleSwap"
  +          description="The maximum time a session may be idle before it should be swapped to file just on general principle"
  +                 type="int" />
  +
  +    <attribute   name="rejectedSessions"
  +          description="Number of sessions we rejected due to maxActive beeing reached"
  +                 type="int" />
  +
  +    <attribute   name="expiredSessions"
  +          description="Number of sessions that expired ( doesn't include explicit invalidations )"
  +                 type="int" />
  +
  +    <attribute   name="processingTime"
  +          description="Time spent doing housekeeping and expiration"
  +                 type="long" />
  +
  +    <attribute   name="duplicates"
  +          description="Number of duplicated session ids generated"
  +                 type="int" />
  +
  +    <operation   name="listSessionIds"
  +          description="Return the list of active session ids"
  +               impact="ACTION"
  +           returnType="java.lang.String">
  +    </operation>
  +
  +    <operation   name="getSessionAttribute"
  +          description="Return a session attribute"
  +               impact="ACTION"
  +           returnType="java.lang.String">
  +      <parameter name="sessionId"
  +          description="Id of the session"
  +                 type="java.lang.String"/>
  +      <parameter name="key"
  +          description="key of the attribute"
  +                 type="java.lang.String"/>
  +    </operation>
  +
  +    <operation   name="expireSession"
  +          description="Expire a session"
  +               impact="ACTION"
  +           returnType="void">
  +      <parameter name="sessionId"
  +          description="Id of the session"
  +                 type="java.lang.String"/>
  +    </operation>
  +
  +    <operation   name="getLastAccessedTime"
  +          description="Get the last access time"
  +               impact="ACTION"
  +           returnType="java.lang.String">
  +      <parameter name="sessionId"
  +          description="Id of the session"
  +                 type="java.lang.String"/>
  +    </operation>
  +
  +  </mbean>
  +
   </mbeans-descriptors>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org