You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Bip Thelin <bi...@razorfish.com> on 2001/04/10 04:19:39 UTC

[PATCH PersistentManager.java] Patch to get the Max Idle Backup working

A little update to PersistentManager.java to backup sessions that's been Idle
for longer than specified max time.

	..bip


Index: LocalStrings.properties
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/LocalStrings.properties,v
retrieving revision 1.4
diff -u -r1.4 LocalStrings.properties
--- LocalStrings.properties     2001/02/03 20:36:20     1.4
+++ LocalStrings.properties     2001/04/10 02:16:05
@@ -37,6 +47,8 @@
 persistentManager.deserializeError=Error deserializing Session {0}: {1}
 persistentManager.serializeError=Error deserializing Session {0}: {1}
 persistentManager.swapMaxIdle=Swapping session {0} to Store, idle for {1} seconds
+persistentManager.backupMaxIdle=Backing up session {0} to Store, idle for {1} seconds
+persistentManager.backupException=Exception occured when backing up Session {0}: {1}
 persistentManager.tooManyActive=Too many active sessions, {0}, looking for idle sessions to swap out
 persistentManager.swapTooManyActive=Swapping out session {0}, idle for {1} seconds too many sessions active
 persistentManager.processSwaps=Checking for sessions to swap out, {0} active sessions in memory


Index: PersistentManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/PersistentManager.java,v
retrieving revision 1.3
diff -u -r1.3 PersistentManager.java
--- PersistentManager.java      2001/04/07 10:25:03     1.3
+++ PersistentManager.java      2001/04/10 02:11:39
@@ -782,7 +782,32 @@
        if (!started || maxIdleBackup < 0)
            return;

-       // FIXME: Do something useful
+       Session sessions[] = findSessions();
+       long timeNow = System.currentTimeMillis();
+
+       // Back up all sessions idle longer than maxIdleBackup
+       if (maxIdleBackup >= 0) {
+           for (int i = 0; i < sessions.length; i++) {
+               StandardSession session = (StandardSession) sessions[i];
+               if (!session.isValid())
+                   continue;
+               int timeIdle = // Truncate, do not round up
+                   (int) ((timeNow - session.getLastAccessedTime()) / 1000L);
+               if (timeIdle > maxIdleBackup) {
+                   if (debug > 1)
+                       log(sm.getString
+                            ("persistentManager.backupMaxIdle",
+                             session.getId(), new Integer(timeIdle)));
+
+                   try {
+                       backup(session);
+                   } catch (IOException e) {
+                       log(sm.getString
+                           ("persistentManager.backupException", session.getId(
), e));
+                   }
+               }
+           }
+       }
     }


@@ -862,10 +887,18 @@
      * Write the session out to Store, but leave the copy in
      * the Manager's memory unmodified.
      */
-    private void backup() throws IOException {
-
-        // FIXME: Do something
+    private void backup(Session session) throws IOException {
+       if (!session.isValid()
+            || isSessionStale(session, System.currentTimeMillis()))
+           return;

+       try {
+           store.save(session);
+       } catch (IOException e) {
+           log(sm.getString
+                ("persistentManager.serializeError", session.getId(), e));
+           throw e;
+       }
     }

Re: [PATCH PersistentManager.java] Patch to get the Max Idle Backup working

Posted by Endre Stølsvik <En...@Stolsvik.com>.
Just wanted to comment that apparently one of the existing lines in that
LocalStrings thingy have a typo:

On Mon, 9 Apr 2001, Bip Thelin wrote:

| Index: LocalStrings.properties
| ===================================================================
| RCS file: /home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/LocalStrings.properties,v
| retrieving revision 1.4
| diff -u -r1.4 LocalStrings.properties
| --- LocalStrings.properties     2001/02/03 20:36:20     1.4
| +++ LocalStrings.properties     2001/04/10 02:16:05
| @@ -37,6 +47,8 @@
|  persistentManager.deserializeError=Error deserializing Session {0}: {1}
                                           ^^^^^^^^^^^^^^^

|  persistentManager.serializeError=Error deserializing Session {0}: {1}
                     ^^^^^^^^^           ^^^^^^^^^^^^^^^

;)

Endre.