pero 2004/11/02 11:07:51
Modified: catalina/src/share/org/apache/catalina/session
JDBCStore.java PersistentManagerBase.java
StoreBase.java mbeans-descriptors.xml
Log:
Add processExpiresFrequency to PersistentManagerBase and made some small JDBCStore
optimizations (pero)
Revision Changes Path
1.11 +28 -30
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/JDBCStore.java
Index: JDBCStore.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/JDBCStore.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JDBCStore.java 23 Jun 2004 13:51:36 -0000 1.10
+++ JDBCStore.java 2 Nov 2004 19:07:50 -0000 1.11
@@ -440,9 +440,6 @@
* @exception IOException if an input/output error occurred
*/
public String[] keys() throws IOException {
- String keysSql =
- "SELECT " + sessionIdCol + " FROM " + sessionTable +
- " WHERE " + sessionAppCol + " = ?";
ResultSet rst = null;
String keys[] = null;
synchronized (this) {
@@ -455,6 +452,9 @@
}
try {
if (preparedKeysSql == null) {
+ String keysSql =
+ "SELECT " + sessionIdCol + "
FROM " + sessionTable +
+ " WHERE " + sessionAppCol + "
= ?";
preparedKeysSql = _conn.prepareStatement(keysSql);
}
@@ -500,9 +500,6 @@
*/
public int getSize() throws IOException {
int size = 0;
- String sizeSql =
- "SELECT COUNT(" + sessionIdCol + ") FROM " + sessionTable +
- " WHERE " + sessionAppCol + " = ?";
ResultSet rst = null;
synchronized (this) {
@@ -516,6 +513,9 @@
try {
if (preparedSizeSql == null) {
+ String sizeSql =
+ "SELECT COUNT(" + sessionIdCol
+ ") FROM " + sessionTable +
+ " WHERE " + sessionAppCol + "
= ?";
preparedSizeSql = _conn.prepareStatement(sizeSql);
}
@@ -562,11 +562,7 @@
ObjectInputStream ois = null;
BufferedInputStream bis = null;
Container container = manager.getContainer();
- String loadSql =
- "SELECT " + sessionIdCol + ", " + sessionDataCol + " FROM " +
- sessionTable + " WHERE " + sessionIdCol + " = ? AND " +
- sessionAppCol + " = ?";
-
+
synchronized (this) {
int numberOfTries = 2;
while (numberOfTries > 0) {
@@ -577,7 +573,11 @@
try {
if (preparedLoadSql == null) {
- preparedLoadSql = _conn.prepareStatement(loadSql);
+ String loadSql =
+ "SELECT " +
sessionIdCol + ", " + sessionDataCol + " FROM " +
+ sessionTable + " WHERE
" + sessionIdCol + " = ? AND " +
+ sessionAppCol + " = ?";
+ preparedLoadSql = _conn.prepareStatement(loadSql);
}
preparedLoadSql.setString(1, id);
@@ -607,8 +607,7 @@
_session = (StandardSession) manager.createEmptySession();
_session.readObjectData(ois);
_session.setManager(manager);
-
- } else if (manager.getContainer().getLogger().isDebugEnabled())
{
+ } else if
(manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(getStoreName() +
": No persisted data object found");
}
} catch (SQLException e) {
@@ -649,9 +648,6 @@
* @exception IOException if an input/output error occurs
*/
public void remove(String id) throws IOException {
- String removeSql =
- "DELETE FROM " + sessionTable + " WHERE " + sessionIdCol +
- " = ? AND " + sessionAppCol + " = ?";
synchronized (this) {
int numberOfTries = 2;
@@ -664,6 +660,9 @@
try {
if (preparedRemoveSql == null) {
+ String removeSql =
+ "DELETE FROM " + sessionTable
+ " WHERE " + sessionIdCol +
+ " = ? AND " + sessionAppCol +
" = ?";
preparedRemoveSql = _conn.prepareStatement(removeSql);
}
@@ -692,8 +691,6 @@
* @exception IOException if an input/output error occurs
*/
public void clear() throws IOException {
- String clearSql =
- "DELETE FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
synchronized (this) {
int numberOfTries = 2;
@@ -705,6 +702,8 @@
try {
if (preparedClearSql == null) {
+ String clearSql =
+ "DELETE FROM " + sessionTable
+ " WHERE " + sessionAppCol + " = ?";
preparedClearSql = _conn.prepareStatement(clearSql);
}
@@ -729,13 +728,6 @@
* @exception IOException if an input/output error occurs
*/
public void save(Session session) throws IOException {
- String saveSql =
- "INSERT INTO " + sessionTable + " (" + sessionIdCol + ", " +
- sessionAppCol + ", " +
- sessionDataCol + ", " +
- sessionValidCol + ", " +
- sessionMaxInactiveCol + ", " +
- sessionLastAccessedCol + ") VALUES (?, ?, ?, ?, ?, ?)";
ObjectOutputStream oos = null;
ByteArrayOutputStream bos = null;
ByteArrayInputStream bis = null;
@@ -767,6 +759,13 @@
in = new BufferedInputStream(bis, size);
if (preparedSaveSql == null) {
+ String saveSql =
+ "INSERT INTO " + sessionTable
+ " (" + sessionIdCol + ", " +
+ sessionAppCol + ", " +
+ sessionDataCol + ", " +
+ sessionValidCol + ", " +
+ sessionMaxInactiveCol + ", " +
+ sessionLastAccessedCol + ")
VALUES (?, ?, ?, ?, ?, ?)";
preparedSaveSql = _conn.prepareStatement(saveSql);
}
@@ -911,9 +910,8 @@
} catch (Throwable f) {
;
}
- this.preparedClearSql = null;
-
- try {
+
+ try {
preparedRemoveSql.close();
} catch (Throwable f) {
;
1.23 +81 -40
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- PersistentManagerBase.java 23 Oct 2004 00:16:08 -0000 1.22
+++ PersistentManagerBase.java 2 Nov 2004 19:07:50 -0000 1.23
@@ -130,7 +130,7 @@
/**
* The descriptive information about this implementation.
*/
- private static final String info = "PersistentManagerBase/1.0";
+ private static final String info = "PersistentManagerBase/1.1";
/**
@@ -203,35 +203,76 @@
*/
protected long processingTime = 0;
+ /**
+ * Frequency of the session expiration, and related manager operations.
+ * Manager operations will be done once for the specified amount of
+ * backgrondProcess calls (ie, the lower the amount, the most often the
+ * checks will occur).
+ */
+ protected int processExpiresFrequency = 6;
- // ------------------------------------------------------------- Properties
+
+ /**
+ * Iteration count for background processing.
+ */
+ private int count = 0;
+ // ------------------------------------------------------------- Properties
/**
- * Perform the background processes for this Manager
+ * Return the frequency of manager checks.
*/
- public void backgroundProcess() {
+ public int getProcessExpiresFrequency() {
- long timeNow = System.currentTimeMillis();
+ return (this.processExpiresFrequency);
- this.processExpires();
- this.processPersistenceChecks();
- if ((this.getStore() != null)
- && (this.getStore() instanceof StoreBase)) {
- ((StoreBase) this.getStore()).processExpires();
+ }
+
+
+ /**
+ * Set the manager checks frequency.
+ *
+ * @param processExpiresFrequency the new manager checks frequency
+ */
+ public void setProcessExpiresFrequency(int processExpiresFrequency) {
+
+ if (processExpiresFrequency <= 0) {
+ return;
}
- long timeEnd = System.currentTimeMillis();
- processingTime += ( timeEnd - timeNow );
+ int oldProcessExpiresFrequency = this.processExpiresFrequency;
+ this.processExpiresFrequency = processExpiresFrequency;
+ support.firePropertyChange("processExpiresFrequency",
+ new Integer(oldProcessExpiresFrequency),
+ new Integer(this.processExpiresFrequency));
}
+
+ /**
+ * Implements the Manager interface, direct call to processExpires and
processPersistenceChecks
+ */
+ public void backgroundProcess() {
+ count = (count + 1) % processExpiresFrequency;
+ if (count == 0) {
+ long timeNow = System.currentTimeMillis();
+
+ processExpires();
+ processPersistenceChecks();
+ if ((getStore() != null) && (getStore() instanceof StoreBase))
{
+ ((StoreBase) 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
- * means sessions are not backed up.
- */
+ * 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 means sessions
+ * are not backed up.
+ */
public int getMaxIdleBackup() {
return maxIdleBackup;
@@ -248,12 +289,12 @@
* means sessions are not backed up.
* <p>
* Note that this is not a hard limit: sessions are checked
- * against this age limit periodically according to <b>checkInterval</b>.
+ * against this age limit periodically according to
<b>processExpiresFrequency</b>.
* This value should be considered to indicate when a session is
* ripe for backing up.
* <p>
* So it is possible that a session may be idle for maxIdleBackup +
- * checkInterval seconds, plus the time it takes to handle other
+ * processExpiresFrequency * engine.backgroundProcessorDelay seconds, plus the
time it takes to handle other
* session expiration, swapping, etc. tasks.
*
* @param backup The number of seconds after their last accessed
@@ -331,12 +372,13 @@
/**
- * Set the Container with which this Manager has been associated. If
- * it is a Context (the usual case), listen for changes to the session
- * timeout property.
- *
- * @param container The associated Container
- */
+ * Set the Container with which this Manager has been associated. If it is a
+ * Context (the usual case), listen for changes to the session timeout
+ * property.
+ *
+ * @param container
+ * The associated Container
+ */
public void setContainer(Container container) {
// De-register from the old Container (if any)
@@ -559,23 +601,23 @@
/**
- * Invalidate all sessions that have expired.
- */
- public void processExpires() {
-
- Session sessions[] = findSessions();
-
- for (int i = 0; i < sessions.length; i++) {
- sessions[i].isValid();
- }
- }
+ * Invalidate all sessions that have expired.
+ */
+ public void processExpires() {
+
+ Session sessions[] = findSessions();
+
+ for (int i = 0; i < sessions.length; i++) {
+ sessions[i].isValid();
+ }
+
+ }
/**
- * Called by the background thread after active sessions have
- * been checked for expiration, to allow sessions to be
- * swapped out, backed up, etc.
- */
+ * Called by the background thread after active sessions have been checked
+ * for expiration, to allow sessions to be swapped out, backed up, etc.
+ */
public void processPersistenceChecks() {
processMaxIdleSwaps();
@@ -1136,6 +1178,5 @@
}
}
-
}
1.10 +9 -3
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StoreBase.java
Index: StoreBase.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StoreBase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StoreBase.java 23 Jun 2004 13:51:36 -0000 1.9
+++ StoreBase.java 2 Nov 2004 19:07:51 -0000 1.10
@@ -175,7 +175,7 @@
long timeNow = System.currentTimeMillis();
String[] keys = null;
- if(!started) {
+ if(!started) {
return;
}
@@ -185,7 +185,10 @@
manager.getContainer().getLogger().error("Error getting keys", e);
return;
}
-
+ if (manager.getContainer().getLogger().isDebugEnabled()) {
+ manager.getContainer().getLogger().debug(getStoreName()+ ":
processExpires check number of " + keys.length + " sessions" );
+ }
+
for (int i = 0; i < keys.length; i++) {
try {
StandardSession session = (StandardSession) load(keys[i]);
@@ -194,6 +197,9 @@
}
if (session.isValid()) {
continue;
+ }
+ if (manager.getContainer().getLogger().isDebugEnabled()) {
+ manager.getContainer().getLogger().debug(getStoreName()+ ":
processExpires expire store session " + keys[i] );
}
if ( ( (PersistentManagerBase) manager).isLoaded( keys[i] )) {
// recycle old backup session
1.10 +5 -1
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- mbeans-descriptors.xml 5 Oct 2004 17:12:52 -0000 1.9
+++ mbeans-descriptors.xml 2 Nov 2004 19:07:51 -0000 1.10
@@ -181,7 +181,11 @@
description="The default maximum inactive interval for Sessions
created by this Manager"
type="int"/>
-
+
+ <attribute name="processExpiresFrequency"
+ description="The frequency of the manager checks (expiration and
passivation)"
+ type="int"/>
+
<attribute name="sessionIdLength"
description="The session id length (in bytes) of Sessions
created by this Manager"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]