You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/05/31 08:57:16 UTC
[tomcat] branch 9.0.x updated: Code clean-up - formatting. No fucntional change.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 502dee5d54 Code clean-up - formatting. No fucntional change.
502dee5d54 is described below
commit 502dee5d542b766cad483e7f35b605cbb0ec09a7
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed May 31 09:57:10 2023 +0100
Code clean-up - formatting. No fucntional change.
---
java/org/apache/catalina/session/Constants.java | 8 +-
.../apache/catalina/session/DataSourceStore.java | 103 ++--
java/org/apache/catalina/session/FileStore.java | 58 +-
java/org/apache/catalina/session/JDBCStore.java | 185 +++---
java/org/apache/catalina/session/ManagerBase.java | 358 +++++-------
.../apache/catalina/session/PersistentManager.java | 14 +-
.../catalina/session/PersistentManagerBase.java | 379 ++++++-------
.../apache/catalina/session/StandardManager.java | 94 ++--
.../apache/catalina/session/StandardSession.java | 622 ++++++++-------------
.../catalina/session/StandardSessionFacade.java | 15 +-
java/org/apache/catalina/session/StoreBase.java | 50 +-
.../session/TooManyActiveSessionsException.java | 9 +-
12 files changed, 780 insertions(+), 1115 deletions(-)
diff --git a/java/org/apache/catalina/session/Constants.java b/java/org/apache/catalina/session/Constants.java
index 58a8890a8d..3948fe8dc5 100644
--- a/java/org/apache/catalina/session/Constants.java
+++ b/java/org/apache/catalina/session/Constants.java
@@ -24,8 +24,7 @@ import org.apache.catalina.Globals;
import org.apache.catalina.valves.CrawlerSessionManagerValve;
/**
- * Manifest constants for the <code>org.apache.catalina.session</code>
- * package.
+ * Manifest constants for the <code>org.apache.catalina.session</code> package.
*
* @author Craig R. McClanahan
*/
@@ -33,9 +32,8 @@ import org.apache.catalina.valves.CrawlerSessionManagerValve;
public class Constants {
/**
- * Set of session attribute names used internally by Tomcat that should
- * always be removed from the session before it is persisted, replicated or
- * equivalent.
+ * Set of session attribute names used internally by Tomcat that should always be removed from the session before it
+ * is persisted, replicated or equivalent.
*/
public static final Set<String> excludedAttributeNames;
diff --git a/java/org/apache/catalina/session/DataSourceStore.java b/java/org/apache/catalina/session/DataSourceStore.java
index 69f5693079..534fc3afdc 100644
--- a/java/org/apache/catalina/session/DataSourceStore.java
+++ b/java/org/apache/catalina/session/DataSourceStore.java
@@ -41,10 +41,8 @@ import org.apache.catalina.Session;
import org.apache.juli.logging.Log;
/**
- * Implementation of the {@link org.apache.catalina.Store Store}
- * interface that stores serialized session objects in a database.
- * Sessions that are saved are still subject to being expired
- * based on inactivity.
+ * Implementation of the {@link org.apache.catalina.Store Store} interface that stores serialized session objects in a
+ * database. Sessions that are saved are still subject to being expired based on inactivity.
*
* @author Bip Thelin
*/
@@ -64,12 +62,11 @@ public class DataSourceStore extends JDBCStore {
}
/**
- * Return an array containing the session identifiers of all Sessions
- * currently saved in this Store. If there are no such Sessions, a
- * zero-length array is returned.
+ * Return an array containing the session identifiers of all Sessions currently saved in this Store. If there are no
+ * such Sessions, a zero-length array is returned.
+ *
+ * @param expiredOnly flag, whether only keys of expired sessions should be returned
*
- * @param expiredOnly flag, whether only keys of expired sessions should
- * be returned
* @return array containing the list of session IDs
*
* @exception IOException if an input/output error occurred
@@ -85,11 +82,10 @@ public class DataSourceStore extends JDBCStore {
}
try {
- String keysSql = "SELECT " + sessionIdCol + " FROM "
- + sessionTable + " WHERE " + sessionAppCol + " = ?";
+ String keysSql =
+ "SELECT " + sessionIdCol + " FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
if (expiredOnly) {
- keysSql += " AND (" + sessionLastAccessedCol + " + "
- + sessionMaxInactiveCol + " * 1000 < ?)";
+ keysSql += " AND (" + sessionLastAccessedCol + " + " + sessionMaxInactiveCol + " * 1000 < ?)";
}
try (PreparedStatement preparedKeysSql = _conn.prepareStatement(keysSql)) {
preparedKeysSql.setString(1, getName());
@@ -121,8 +117,7 @@ public class DataSourceStore extends JDBCStore {
}
/**
- * Return an integer containing a count of all Sessions
- * currently saved in this Store. If there are no Sessions,
+ * Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions,
* <code>0</code> is returned.
*
* @return the count of all sessions currently saved in this Store
@@ -132,9 +127,7 @@ public class DataSourceStore extends JDBCStore {
@Override
public int getSize() throws IOException {
int size = 0;
- String sizeSql = "SELECT COUNT(" + sessionIdCol
- + ") FROM " + sessionTable + " WHERE "
- + sessionAppCol + " = ?";
+ String sizeSql = "SELECT COUNT(" + sessionIdCol + ") FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
int numberOfTries = 2;
while (numberOfTries > 0) {
@@ -144,7 +137,7 @@ public class DataSourceStore extends JDBCStore {
return size;
}
- try (PreparedStatement preparedSizeSql = _conn.prepareStatement(sizeSql)){
+ try (PreparedStatement preparedSizeSql = _conn.prepareStatement(sizeSql)) {
preparedSizeSql.setString(1, getName());
try (ResultSet rst = preparedSizeSql.executeQuery()) {
if (rst.next()) {
@@ -164,13 +157,15 @@ public class DataSourceStore extends JDBCStore {
}
/**
- * Load the Session associated with the id <code>id</code>.
- * If no such session is found <code>null</code> is returned.
+ * Load the Session associated with the id <code>id</code>. If no such session is found <code>null</code> is
+ * returned.
*
* @param id a value of type <code>String</code>
+ *
* @return the stored <code>Session</code>
+ *
* @exception ClassNotFoundException if an error occurs
- * @exception IOException if an input/output error occurred
+ * @exception IOException if an input/output error occurred
*/
@Override
public Session load(String id) throws ClassNotFoundException, IOException {
@@ -179,10 +174,8 @@ public class DataSourceStore extends JDBCStore {
Log contextLog = context.getLogger();
int numberOfTries = 2;
- String loadSql = "SELECT " + sessionIdCol + ", "
- + sessionDataCol + " FROM " + sessionTable
- + " WHERE " + sessionIdCol + " = ? AND "
- + sessionAppCol + " = ?";
+ String loadSql = "SELECT " + sessionIdCol + ", " + sessionDataCol + " FROM " + sessionTable + " WHERE " +
+ sessionIdCol + " = ? AND " + sessionAppCol + " = ?";
while (numberOfTries > 0) {
Connection _conn = getConnection();
if (_conn == null) {
@@ -191,16 +184,14 @@ public class DataSourceStore extends JDBCStore {
ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, null);
- try (PreparedStatement preparedLoadSql = _conn.prepareStatement(loadSql)){
+ try (PreparedStatement preparedLoadSql = _conn.prepareStatement(loadSql)) {
preparedLoadSql.setString(1, id);
preparedLoadSql.setString(2, getName());
try (ResultSet rst = preparedLoadSql.executeQuery()) {
if (rst.next()) {
- try (ObjectInputStream ois =
- getObjectInputStream(rst.getBinaryStream(2))) {
+ try (ObjectInputStream ois = getObjectInputStream(rst.getBinaryStream(2))) {
if (contextLog.isDebugEnabled()) {
- contextLog.debug(sm.getString(
- getStoreName() + ".loading", id, sessionTable));
+ contextLog.debug(sm.getString(getStoreName() + ".loading", id, sessionTable));
}
_session = (StandardSession) manager.createEmptySession();
@@ -225,9 +216,8 @@ public class DataSourceStore extends JDBCStore {
}
/**
- * Remove the Session with the specified session identifier from
- * this Store, if present. If no such Session is present, this method
- * takes no action.
+ * Remove the Session with the specified session identifier from this Store, if present. If no such Session is
+ * present, this method takes no action.
*
* @param id Session identifier of the Session to be removed
*
@@ -262,18 +252,17 @@ public class DataSourceStore extends JDBCStore {
}
/**
- * Remove the Session with the specified session identifier from
- * this Store, if present. If no such Session is present, this method
- * takes no action.
+ * Remove the Session with the specified session identifier from this Store, if present. If no such Session is
+ * present, this method takes no action.
*
- * @param id Session identifier of the Session to be removed
+ * @param id Session identifier of the Session to be removed
* @param _conn open connection to be used
+ *
* @throws SQLException if an error occurs while talking to the database
*/
private void remove(String id, Connection _conn) throws SQLException {
- String removeSql = "DELETE FROM " + sessionTable
- + " WHERE " + sessionIdCol + " = ? AND "
- + sessionAppCol + " = ?";
+ String removeSql =
+ "DELETE FROM " + sessionTable + " WHERE " + sessionIdCol + " = ? AND " + sessionAppCol + " = ?";
try (PreparedStatement preparedRemoveSql = _conn.prepareStatement(removeSql)) {
preparedRemoveSql.setString(1, id);
preparedRemoveSql.setString(2, getName());
@@ -288,8 +277,7 @@ public class DataSourceStore extends JDBCStore {
*/
@Override
public void clear() throws IOException {
- String clearSql = "DELETE FROM " + sessionTable
- + " WHERE " + sessionAppCol + " = ?";
+ String clearSql = "DELETE FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
int numberOfTries = 2;
while (numberOfTries > 0) {
@@ -298,7 +286,7 @@ public class DataSourceStore extends JDBCStore {
return;
}
- try (PreparedStatement preparedClearSql = _conn.prepareStatement(clearSql)){
+ try (PreparedStatement preparedClearSql = _conn.prepareStatement(clearSql)) {
preparedClearSql.setString(1, getName());
preparedClearSql.execute();
// Break out after the finally block
@@ -316,17 +304,15 @@ public class DataSourceStore extends JDBCStore {
* Save a session to the Store.
*
* @param session the session to be stored
+ *
* @exception IOException if an input/output error occurs
*/
@Override
public void save(Session session) throws IOException {
ByteArrayOutputStream bos = null;
- String saveSql = "INSERT INTO " + sessionTable + " ("
- + sessionIdCol + ", " + sessionAppCol + ", "
- + sessionDataCol + ", " + sessionValidCol
- + ", " + sessionMaxInactiveCol + ", "
- + sessionLastAccessedCol
- + ") VALUES (?, ?, ?, ?, ?, ?)";
+ String saveSql = "INSERT INTO " + sessionTable + " (" + sessionIdCol + ", " + sessionAppCol + ", " +
+ sessionDataCol + ", " + sessionValidCol + ", " + sessionMaxInactiveCol + ", " + sessionLastAccessedCol +
+ ") VALUES (?, ?, ?, ?, ?, ?)";
synchronized (session) {
int numberOfTries = 2;
@@ -343,8 +329,7 @@ public class DataSourceStore extends JDBCStore {
remove(session.getIdInternal(), _conn);
bos = new ByteArrayOutputStream();
- try (ObjectOutputStream oos =
- new ObjectOutputStream(new BufferedOutputStream(bos))) {
+ try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos))) {
((StandardSession) session).writeObjectData(oos);
}
byte[] obs = bos.toByteArray();
@@ -374,8 +359,8 @@ public class DataSourceStore extends JDBCStore {
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".saving",
- session.getIdInternal(), sessionTable));
+ manager.getContext().getLogger()
+ .debug(sm.getString(getStoreName() + ".saving", session.getIdInternal(), sessionTable));
}
}
@@ -383,8 +368,7 @@ public class DataSourceStore extends JDBCStore {
// --------------------------------------------------------- Protected Methods
/**
- * Open (if necessary) and return a database connection for use by
- * this Store.
+ * Open (if necessary) and return a database connection for use by this Store.
*
* @return database connection ready to use
*
@@ -405,9 +389,7 @@ public class DataSourceStore extends JDBCStore {
Context envCtx = (Context) initCtx.lookup("java:comp/env");
this.dataSource = (DataSource) envCtx.lookup(this.dataSourceName);
} catch (NamingException e) {
- context.getLogger().error(
- sm.getString(getStoreName() + ".wrongDataSource",
- this.dataSourceName), e);
+ context.getLogger().error(sm.getString(getStoreName() + ".wrongDataSource", this.dataSourceName), e);
} finally {
if (getLocalDataSource()) {
context.unbind(Globals.IS_SECURITY_ENABLED, oldThreadContextCL);
@@ -448,7 +430,8 @@ public class DataSourceStore extends JDBCStore {
try {
dbConnection.close();
} catch (SQLException e) {
- manager.getContext().getLogger().error(sm.getString(getStoreName() + ".close", e.toString())); // Just log it here
+ manager.getContext().getLogger().error(sm.getString(getStoreName() + ".close", e.toString())); // Just log
+ // it here
}
}
diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java
index e42a72a4c8..6755bc75e7 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -37,9 +37,8 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.res.StringManager;
/**
- * Concrete implementation of the <b>Store</b> interface that utilizes
- * a file per saved Session in a configured directory. Sessions that are
- * saved are still subject to being expired based on inactivity.
+ * Concrete implementation of the <b>Store</b> interface that utilizes a file per saved Session in a configured
+ * directory. Sessions that are saved are still subject to being expired based on inactivity.
*
* @author Craig R. McClanahan
*/
@@ -60,9 +59,8 @@ public final class FileStore extends StoreBase {
// ----------------------------------------------------- Instance Variables
/**
- * The pathname of the directory in which Sessions are stored.
- * This may be an absolute pathname, or a relative path that is
- * resolved against the temporary work directory for this application.
+ * The pathname of the directory in which Sessions are stored. This may be an absolute pathname, or a relative path
+ * that is resolved against the temporary work directory for this application.
*/
private String directory = ".";
@@ -169,9 +167,8 @@ public final class FileStore extends StoreBase {
/**
- * Return an array containing the session identifiers of all Sessions
- * currently saved in this Store. If there are no such Sessions, a
- * zero-length array is returned.
+ * Return an array containing the session identifiers of all Sessions currently saved in this Store. If there are no
+ * such Sessions, a zero-length array is returned.
*
* @exception IOException if an input/output error occurred
*/
@@ -194,7 +191,7 @@ public final class FileStore extends StoreBase {
int n = FILE_EXT.length();
for (String file : files) {
if (file.endsWith(FILE_EXT)) {
- list.add (file.substring(0, file.length() - n));
+ list.add(file.substring(0, file.length() - n));
}
}
return list.toArray(new String[0]);
@@ -202,14 +199,13 @@ public final class FileStore extends StoreBase {
/**
- * Load and return the Session associated with the specified session
- * identifier from this Store, without removing it. If there is no
- * such stored Session, return <code>null</code>.
+ * Load and return the Session associated with the specified session identifier from this Store, without removing
+ * it. If there is no such stored Session, return <code>null</code>.
*
* @param id Session identifier of the session to load
*
* @exception ClassNotFoundException if a deserialization error occurs
- * @exception IOException if an input/output error occurs
+ * @exception IOException if an input/output error occurs
*/
@Override
public Session load(String id) throws ClassNotFoundException, IOException {
@@ -223,7 +219,7 @@ public final class FileStore extends StoreBase {
Log contextLog = context.getLogger();
if (contextLog.isDebugEnabled()) {
- contextLog.debug(sm.getString(getStoreName()+".loading", id, file.getAbsolutePath()));
+ contextLog.debug(sm.getString(getStoreName() + ".loading", id, file.getAbsolutePath()));
}
ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, null);
@@ -247,9 +243,8 @@ public final class FileStore extends StoreBase {
/**
- * Remove the Session with the specified session identifier from
- * this Store, if present. If no such Session is present, this method
- * takes no action.
+ * Remove the Session with the specified session identifier from this Store, if present. If no such Session is
+ * present, this method takes no action.
*
* @param id Session identifier of the Session to be removed
*
@@ -262,8 +257,8 @@ public final class FileStore extends StoreBase {
return;
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".removing",
- id, file.getAbsolutePath()));
+ manager.getContext().getLogger()
+ .debug(sm.getString(getStoreName() + ".removing", id, file.getAbsolutePath()));
}
if (file.exists() && !file.delete()) {
@@ -273,8 +268,8 @@ public final class FileStore extends StoreBase {
/**
- * Save the specified Session into this Store. Any previously saved
- * information for the associated session identifier is replaced.
+ * Save the specified Session into this Store. Any previously saved information for the associated session
+ * identifier is replaced.
*
* @param session Session to be saved
*
@@ -288,13 +283,13 @@ public final class FileStore extends StoreBase {
return;
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".saving",
- session.getIdInternal(), file.getAbsolutePath()));
+ manager.getContext().getLogger()
+ .debug(sm.getString(getStoreName() + ".saving", session.getIdInternal(), file.getAbsolutePath()));
}
try (FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos))) {
- ((StandardSession)session).writeObjectData(oos);
+ ((StandardSession) session).writeObjectData(oos);
}
}
@@ -302,16 +297,15 @@ public final class FileStore extends StoreBase {
// -------------------------------------------------------- Private Methods
/**
- * Return a File object representing the pathname to our
- * session persistence directory, if any. The directory will be
- * created if it does not already exist.
+ * Return a File object representing the pathname to our session persistence directory, if any. The directory will
+ * be created if it does not already exist.
*/
private File directory() throws IOException {
if (this.directory == null) {
return null;
}
if (this.directoryFile != null) {
- // NOTE: Race condition is harmless, so do not synchronize
+ // NOTE: Race condition is harmless, so do not synchronize
return this.directoryFile;
}
File file = new File(this.directory);
@@ -335,11 +329,9 @@ public final class FileStore extends StoreBase {
/**
- * Return a File object representing the pathname to our
- * session persistence file, if any.
+ * Return a File object representing the pathname to our session persistence file, if any.
*
- * @param id The ID of the Session to be retrieved. This is
- * used in the file naming.
+ * @param id The ID of the Session to be retrieved. This is used in the file naming.
*/
private File file(String id) throws IOException {
File storageDir = directory();
diff --git a/java/org/apache/catalina/session/JDBCStore.java b/java/org/apache/catalina/session/JDBCStore.java
index e0779095c5..b205b7234a 100644
--- a/java/org/apache/catalina/session/JDBCStore.java
+++ b/java/org/apache/catalina/session/JDBCStore.java
@@ -46,14 +46,12 @@ import org.apache.juli.logging.Log;
import org.apache.tomcat.util.ExceptionUtils;
/**
- * Implementation of the {@link org.apache.catalina.Store Store}
- * interface that stores serialized session objects in a database.
- * Sessions that are saved are still subject to being expired
- * based on inactivity.
+ * Implementation of the {@link org.apache.catalina.Store Store} interface that stores serialized session objects in a
+ * database. Sessions that are saved are still subject to being expired based on inactivity.
*
* @author Bip Thelin
- * @deprecated Removed in Tomcat 10 and replaced by DataSourceStore
- * with removal of legacy JDBC code
+ *
+ * @deprecated Removed in Tomcat 10 and replaced by DataSourceStore with removal of legacy JDBC code
*/
@Deprecated
public class JDBCStore extends StoreBase {
@@ -236,9 +234,7 @@ public class JDBCStore extends StoreBase {
public void setDriverName(String driverName) {
String oldDriverName = this.driverName;
this.driverName = driverName;
- support.firePropertyChange("driverName",
- oldDriverName,
- this.driverName);
+ support.firePropertyChange("driverName", oldDriverName, this.driverName);
this.driverName = driverName;
}
@@ -289,9 +285,7 @@ public class JDBCStore extends StoreBase {
public void setConnectionURL(String connectionURL) {
String oldConnString = this.connectionURL;
this.connectionURL = connectionURL;
- support.firePropertyChange("connectionURL",
- oldConnString,
- this.connectionURL);
+ support.firePropertyChange("connectionURL", oldConnString, this.connectionURL);
}
/**
@@ -309,9 +303,7 @@ public class JDBCStore extends StoreBase {
public void setSessionTable(String sessionTable) {
String oldSessionTable = this.sessionTable;
this.sessionTable = sessionTable;
- support.firePropertyChange("sessionTable",
- oldSessionTable,
- this.sessionTable);
+ support.firePropertyChange("sessionTable", oldSessionTable, this.sessionTable);
}
/**
@@ -329,9 +321,7 @@ public class JDBCStore extends StoreBase {
public void setSessionAppCol(String sessionAppCol) {
String oldSessionAppCol = this.sessionAppCol;
this.sessionAppCol = sessionAppCol;
- support.firePropertyChange("sessionAppCol",
- oldSessionAppCol,
- this.sessionAppCol);
+ support.firePropertyChange("sessionAppCol", oldSessionAppCol, this.sessionAppCol);
}
/**
@@ -349,9 +339,7 @@ public class JDBCStore extends StoreBase {
public void setSessionIdCol(String sessionIdCol) {
String oldSessionIdCol = this.sessionIdCol;
this.sessionIdCol = sessionIdCol;
- support.firePropertyChange("sessionIdCol",
- oldSessionIdCol,
- this.sessionIdCol);
+ support.firePropertyChange("sessionIdCol", oldSessionIdCol, this.sessionIdCol);
}
/**
@@ -369,9 +357,7 @@ public class JDBCStore extends StoreBase {
public void setSessionDataCol(String sessionDataCol) {
String oldSessionDataCol = this.sessionDataCol;
this.sessionDataCol = sessionDataCol;
- support.firePropertyChange("sessionDataCol",
- oldSessionDataCol,
- this.sessionDataCol);
+ support.firePropertyChange("sessionDataCol", oldSessionDataCol, this.sessionDataCol);
}
/**
@@ -389,9 +375,7 @@ public class JDBCStore extends StoreBase {
public void setSessionValidCol(String sessionValidCol) {
String oldSessionValidCol = this.sessionValidCol;
this.sessionValidCol = sessionValidCol;
- support.firePropertyChange("sessionValidCol",
- oldSessionValidCol,
- this.sessionValidCol);
+ support.firePropertyChange("sessionValidCol", oldSessionValidCol, this.sessionValidCol);
}
/**
@@ -409,9 +393,7 @@ public class JDBCStore extends StoreBase {
public void setSessionMaxInactiveCol(String sessionMaxInactiveCol) {
String oldSessionMaxInactiveCol = this.sessionMaxInactiveCol;
this.sessionMaxInactiveCol = sessionMaxInactiveCol;
- support.firePropertyChange("sessionMaxInactiveCol",
- oldSessionMaxInactiveCol,
- this.sessionMaxInactiveCol);
+ support.firePropertyChange("sessionMaxInactiveCol", oldSessionMaxInactiveCol, this.sessionMaxInactiveCol);
}
/**
@@ -429,9 +411,7 @@ public class JDBCStore extends StoreBase {
public void setSessionLastAccessedCol(String sessionLastAccessedCol) {
String oldSessionLastAccessedCol = this.sessionLastAccessedCol;
this.sessionLastAccessedCol = sessionLastAccessedCol;
- support.firePropertyChange("sessionLastAccessedCol",
- oldSessionLastAccessedCol,
- this.sessionLastAccessedCol);
+ support.firePropertyChange("sessionLastAccessedCol", oldSessionLastAccessedCol, this.sessionLastAccessedCol);
}
/**
@@ -448,8 +428,7 @@ public class JDBCStore extends StoreBase {
*/
public void setDataSourceName(String dataSourceName) {
if (dataSourceName == null || dataSourceName.trim().isEmpty()) {
- manager.getContext().getLogger().warn(
- sm.getString(getStoreName() + ".missingDataSourceName"));
+ manager.getContext().getLogger().warn(sm.getString(getStoreName() + ".missingDataSourceName"));
return;
}
this.dataSourceName = dataSourceName;
@@ -470,13 +449,12 @@ public class JDBCStore extends StoreBase {
}
/**
- * Set to {@code true} to cause the datasource to be looked up in the webapp
- * JNDI Context.
+ * Set to {@code true} to cause the datasource to be looked up in the webapp JNDI Context.
*
* @param localDataSource the new flag value
*/
public void setLocalDataSource(boolean localDataSource) {
- this.localDataSource = localDataSource;
+ this.localDataSource = localDataSource;
}
@@ -493,12 +471,11 @@ public class JDBCStore extends StoreBase {
}
/**
- * Return an array containing the session identifiers of all Sessions
- * currently saved in this Store. If there are no such Sessions, a
- * zero-length array is returned.
+ * Return an array containing the session identifiers of all Sessions currently saved in this Store. If there are no
+ * such Sessions, a zero-length array is returned.
+ *
+ * @param expiredOnly flag, whether only keys of expired sessions should be returned
*
- * @param expiredOnly flag, whether only keys of expired sessions should
- * be returned
* @return array containing the list of session IDs
*
* @exception IOException if an input/output error occurred
@@ -515,11 +492,10 @@ public class JDBCStore extends StoreBase {
}
try {
- String keysSql = "SELECT " + sessionIdCol + " FROM "
- + sessionTable + " WHERE " + sessionAppCol + " = ?";
+ String keysSql =
+ "SELECT " + sessionIdCol + " FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
if (expiredOnly) {
- keysSql += " AND (" + sessionLastAccessedCol + " + "
- + sessionMaxInactiveCol + " * 1000 < ?)";
+ keysSql += " AND (" + sessionLastAccessedCol + " + " + sessionMaxInactiveCol + " * 1000 < ?)";
}
try (PreparedStatement preparedKeysSql = _conn.prepareStatement(keysSql)) {
preparedKeysSql.setString(1, getName());
@@ -555,8 +531,7 @@ public class JDBCStore extends StoreBase {
}
/**
- * Return an integer containing a count of all Sessions
- * currently saved in this Store. If there are no Sessions,
+ * Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions,
* <code>0</code> is returned.
*
* @return the count of all sessions currently saved in this Store
@@ -578,9 +553,8 @@ public class JDBCStore extends StoreBase {
try {
if (preparedSizeSql == null) {
- String sizeSql = "SELECT COUNT(" + sessionIdCol
- + ") FROM " + sessionTable + " WHERE "
- + sessionAppCol + " = ?";
+ String sizeSql = "SELECT COUNT(" + sessionIdCol + ") FROM " + sessionTable + " WHERE " +
+ sessionAppCol + " = ?";
preparedSizeSql = _conn.prepareStatement(sizeSql);
}
@@ -607,13 +581,15 @@ public class JDBCStore extends StoreBase {
}
/**
- * Load the Session associated with the id <code>id</code>.
- * If no such session is found <code>null</code> is returned.
+ * Load the Session associated with the id <code>id</code>. If no such session is found <code>null</code> is
+ * returned.
*
* @param id a value of type <code>String</code>
+ *
* @return the stored <code>Session</code>
+ *
* @exception ClassNotFoundException if an error occurs
- * @exception IOException if an input/output error occurred
+ * @exception IOException if an input/output error occurred
*/
@Override
public Session load(String id) throws ClassNotFoundException, IOException {
@@ -633,10 +609,8 @@ public class JDBCStore extends StoreBase {
try {
if (preparedLoadSql == null) {
- String loadSql = "SELECT " + sessionIdCol + ", "
- + sessionDataCol + " FROM " + sessionTable
- + " WHERE " + sessionIdCol + " = ? AND "
- + sessionAppCol + " = ?";
+ String loadSql = "SELECT " + sessionIdCol + ", " + sessionDataCol + " FROM " + sessionTable +
+ " WHERE " + sessionIdCol + " = ? AND " + sessionAppCol + " = ?";
preparedLoadSql = _conn.prepareStatement(loadSql);
}
@@ -644,11 +618,9 @@ public class JDBCStore extends StoreBase {
preparedLoadSql.setString(2, getName());
try (ResultSet rst = preparedLoadSql.executeQuery()) {
if (rst.next()) {
- try (ObjectInputStream ois =
- getObjectInputStream(rst.getBinaryStream(2))) {
+ try (ObjectInputStream ois = getObjectInputStream(rst.getBinaryStream(2))) {
if (contextLog.isDebugEnabled()) {
- contextLog.debug(sm.getString(
- getStoreName() + ".loading", id, sessionTable));
+ contextLog.debug(sm.getString(getStoreName() + ".loading", id, sessionTable));
}
_session = (StandardSession) manager.createEmptySession();
@@ -678,9 +650,8 @@ public class JDBCStore extends StoreBase {
}
/**
- * Remove the Session with the specified session identifier from
- * this Store, if present. If no such Session is present, this method
- * takes no action.
+ * Remove the Session with the specified session identifier from this Store, if present. If no such Session is
+ * present, this method takes no action.
*
* @param id Session identifier of the Session to be removed
*
@@ -720,19 +691,18 @@ public class JDBCStore extends StoreBase {
}
/**
- * Remove the Session with the specified session identifier from
- * this Store, if present. If no such Session is present, this method
- * takes no action.
+ * Remove the Session with the specified session identifier from this Store, if present. If no such Session is
+ * present, this method takes no action.
*
- * @param id Session identifier of the Session to be removed
+ * @param id Session identifier of the Session to be removed
* @param _conn open connection to be used
+ *
* @throws SQLException if an error occurs while talking to the database
*/
private void remove(String id, Connection _conn) throws SQLException {
if (preparedRemoveSql == null) {
- String removeSql = "DELETE FROM " + sessionTable
- + " WHERE " + sessionIdCol + " = ? AND "
- + sessionAppCol + " = ?";
+ String removeSql =
+ "DELETE FROM " + sessionTable + " WHERE " + sessionIdCol + " = ? AND " + sessionAppCol + " = ?";
preparedRemoveSql = _conn.prepareStatement(removeSql);
}
@@ -759,8 +729,7 @@ public class JDBCStore extends StoreBase {
try {
if (preparedClearSql == null) {
- String clearSql = "DELETE FROM " + sessionTable
- + " WHERE " + sessionAppCol + " = ?";
+ String clearSql = "DELETE FROM " + sessionTable + " WHERE " + sessionAppCol + " = ?";
preparedClearSql = _conn.prepareStatement(clearSql);
}
@@ -785,6 +754,7 @@ public class JDBCStore extends StoreBase {
* Save a session to the Store.
*
* @param session the session to be stored
+ *
* @exception IOException if an input/output error occurs
*/
@Override
@@ -806,8 +776,7 @@ public class JDBCStore extends StoreBase {
remove(session.getIdInternal(), _conn);
bos = new ByteArrayOutputStream();
- try (ObjectOutputStream oos =
- new ObjectOutputStream(new BufferedOutputStream(bos))) {
+ try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos))) {
((StandardSession) session).writeObjectData(oos);
}
byte[] obs = bos.toByteArray();
@@ -815,13 +784,11 @@ public class JDBCStore extends StoreBase {
try (ByteArrayInputStream bis = new ByteArrayInputStream(obs, 0, size);
InputStream in = new BufferedInputStream(bis, size)) {
if (preparedSaveSql == null) {
- String saveSql = "INSERT INTO " + sessionTable + " ("
- + sessionIdCol + ", " + sessionAppCol + ", "
- + sessionDataCol + ", " + sessionValidCol
- + ", " + sessionMaxInactiveCol + ", "
- + sessionLastAccessedCol
- + ") VALUES (?, ?, ?, ?, ?, ?)";
- preparedSaveSql = _conn.prepareStatement(saveSql);
+ String saveSql =
+ "INSERT INTO " + sessionTable + " (" + sessionIdCol + ", " + sessionAppCol + ", " +
+ sessionDataCol + ", " + sessionValidCol + ", " + sessionMaxInactiveCol +
+ ", " + sessionLastAccessedCol + ") VALUES (?, ?, ?, ?, ?, ?)";
+ preparedSaveSql = _conn.prepareStatement(saveSql);
}
preparedSaveSql.setString(1, session.getIdInternal());
@@ -849,8 +816,8 @@ public class JDBCStore extends StoreBase {
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".saving",
- session.getIdInternal(), sessionTable));
+ manager.getContext().getLogger()
+ .debug(sm.getString(getStoreName() + ".saving", session.getIdInternal(), sessionTable));
}
}
@@ -858,9 +825,8 @@ public class JDBCStore extends StoreBase {
// --------------------------------------------------------- Protected Methods
/**
- * Check the connection associated with this store, if it's
- * <code>null</code> or closed try to reopen it.
- * Returns <code>null</code> if the connection could not be established.
+ * Check the connection associated with this store, if it's <code>null</code> or closed try to reopen it. Returns
+ * <code>null</code> if the connection could not be established.
*
* @return <code>Connection</code> if the connection succeeded
*/
@@ -872,20 +838,20 @@ public class JDBCStore extends StoreBase {
manager.getContext().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBClosed"));
conn = open();
if (conn == null || conn.isClosed()) {
- manager.getContext().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBReOpenFail"));
+ manager.getContext().getLogger()
+ .info(sm.getString(getStoreName() + ".checkConnectionDBReOpenFail"));
}
}
} catch (SQLException ex) {
- manager.getContext().getLogger().error(sm.getString(getStoreName() + ".checkConnectionSQLException",
- ex.toString()));
+ manager.getContext().getLogger()
+ .error(sm.getString(getStoreName() + ".checkConnectionSQLException", ex.toString()));
}
return conn;
}
/**
- * Open (if necessary) and return a database connection for use by
- * this Store.
+ * Open (if necessary) and return a database connection for use by this Store.
*
* @return database connection ready to use
*
@@ -911,9 +877,7 @@ public class JDBCStore extends StoreBase {
Context envCtx = (Context) initCtx.lookup("java:comp/env");
this.dataSource = (DataSource) envCtx.lookup(this.dataSourceName);
} catch (NamingException e) {
- context.getLogger().error(
- sm.getString(getStoreName() + ".wrongDataSource",
- this.dataSourceName), e);
+ context.getLogger().error(sm.getString(getStoreName() + ".wrongDataSource", this.dataSourceName), e);
} finally {
if (localDataSource) {
context.unbind(Globals.IS_SECURITY_ENABLED, oldThreadContextCL);
@@ -931,9 +895,8 @@ public class JDBCStore extends StoreBase {
Class<?> clazz = Class.forName(driverName);
driver = (Driver) clazz.getConstructor().newInstance();
} catch (ReflectiveOperationException e) {
- manager.getContext().getLogger().error(
- sm.getString(getStoreName() + ".checkConnectionClassNotFoundException",
- e.toString()));
+ manager.getContext().getLogger()
+ .error(sm.getString(getStoreName() + ".checkConnectionClassNotFoundException", e.toString()));
throw new SQLException(e);
}
}
@@ -1015,7 +978,8 @@ public class JDBCStore extends StoreBase {
try {
dbConnection.close();
} catch (SQLException e) {
- manager.getContext().getLogger().error(sm.getString(getStoreName() + ".close", e.toString())); // Just log it here
+ manager.getContext().getLogger().error(sm.getString(getStoreName() + ".close", e.toString())); // Just log
+ // it here
} finally {
this.dbConnection = null;
}
@@ -1023,8 +987,7 @@ public class JDBCStore extends StoreBase {
}
/**
- * Release the connection, if it
- * is associated with a connection pool.
+ * Release the connection, if it is associated with a connection pool.
*
* @param conn The connection to be released
*/
@@ -1035,11 +998,11 @@ public class JDBCStore extends StoreBase {
}
/**
- * Start this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
+ * Start this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
@@ -1053,11 +1016,11 @@ public class JDBCStore extends StoreBase {
}
/**
- * Stop this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
+ * Stop this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
diff --git a/java/org/apache/catalina/session/ManagerBase.java b/java/org/apache/catalina/session/ManagerBase.java
index d0af97df23..129c4f842a 100644
--- a/java/org/apache/catalina/session/ManagerBase.java
+++ b/java/org/apache/catalina/session/ManagerBase.java
@@ -53,9 +53,8 @@ import org.apache.tomcat.util.res.StringManager;
/**
- * Minimal implementation of the <b>Manager</b> interface that supports
- * no session persistence or distributable capabilities. This class may
- * be subclassed to create more sophisticated Manager implementations.
+ * Minimal implementation of the <b>Manager</b> interface that supports no session persistence or distributable
+ * capabilities. This class may be subclassed to create more sophisticated Manager implementations.
*
* @author Craig R. McClanahan
*/
@@ -78,33 +77,26 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * The Java class name of the secure random number generator class to be
- * used when generating session identifiers. The random number generator
- * class must be self-seeding and have a zero-argument constructor. If not
- * specified, an instance of {@link java.security.SecureRandom} will be
- * generated.
+ * The Java class name of the secure random number generator class to be used when generating session identifiers.
+ * The random number generator class must be self-seeding and have a zero-argument constructor. If not specified, an
+ * instance of {@link java.security.SecureRandom} will be generated.
*/
protected String secureRandomClass = null;
/**
- * The name of the algorithm to use to create instances of
- * {@link java.security.SecureRandom} which are used to generate session
- * IDs. If no algorithm is specified, SHA1PRNG is used. If SHA1PRNG is not
- * available, the platform default will be used. To use the platform default
- * (which may be SHA1PRNG), specify the empty string. If an invalid
- * algorithm and/or provider is specified the SecureRandom instances will be
- * created using the defaults. If that fails, the SecureRandom instances
- * will be created using platform defaults.
+ * The name of the algorithm to use to create instances of {@link java.security.SecureRandom} which are used to
+ * generate session IDs. If no algorithm is specified, SHA1PRNG is used. If SHA1PRNG is not available, the platform
+ * default will be used. To use the platform default (which may be SHA1PRNG), specify the empty string. If an
+ * invalid algorithm and/or provider is specified the SecureRandom instances will be created using the defaults. If
+ * that fails, the SecureRandom instances will be created using platform defaults.
*/
protected String secureRandomAlgorithm = SessionIdGeneratorBase.DEFAULT_SECURE_RANDOM_ALGORITHM;
/**
- * The name of the provider to use to create instances of
- * {@link java.security.SecureRandom} which are used to generate session
- * IDs. If no provider is specified the platform default is used. If an
- * invalid algorithm and/or provider is specified the SecureRandom instances
- * will be created using the defaults. If that fails, the SecureRandom
- * instances will be created using platform defaults.
+ * The name of the provider to use to create instances of {@link java.security.SecureRandom} which are used to
+ * generate session IDs. If no provider is specified the platform default is used. If an invalid algorithm and/or
+ * provider is specified the SecureRandom instances will be created using the defaults. If that fails, the
+ * SecureRandom instances will be created using platform defaults.
*/
protected String secureRandomProvider = null;
@@ -131,15 +123,14 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * The set of currently active Sessions for this Manager, keyed by
- * session identifier.
+ * The set of currently active Sessions for this Manager, keyed by session identifier.
*/
- protected Map<String, Session> sessions = new ConcurrentHashMap<>();
+ protected Map<String,Session> sessions = new ConcurrentHashMap<>();
// Number of sessions created by this manager
- protected long sessionCounter=0;
+ protected long sessionCounter = 0;
- protected volatile int maxActive=0;
+ protected volatile int maxActive = 0;
private final Object maxActiveUpdateLock = new Object();
@@ -154,7 +145,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
protected int rejectedSessions = 0;
// number of duplicated session ids - anything >0 means we have problems
- protected volatile int duplicates=0;
+ protected volatile int duplicates = 0;
/**
* Processing time during session expiration.
@@ -168,10 +159,8 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Frequency of the session expiration, and related manager operations.
- * Manager operations will be done once for the specified amount of
- * backgroundProcess calls (ie, the lower the amount, the most often the
- * checks will occur).
+ * Frequency of the session expiration, and related manager operations. Manager operations will be done once for the
+ * specified amount of backgroundProcess calls (ie, the lower the amount, the most often the checks will occur).
*/
protected int processExpiresFrequency = 6;
@@ -183,8 +172,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* The property change support for this component.
*/
- protected final PropertyChangeSupport support =
- new PropertyChangeSupport(this);
+ protected final PropertyChangeSupport support = new PropertyChangeSupport(this);
private Pattern sessionAttributeNamePattern;
@@ -197,14 +185,13 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
private boolean notifyAttributeListenerOnUnchangedValue = true;
/**
- * Determines whether sessions managed by this manager shall persist (serialize)
- * authentication information or not.
+ * Determines whether sessions managed by this manager shall persist (serialize) authentication information or not.
*/
private boolean persistAuthentication = false;
/**
- * Determines if the session notes required by the FORM authentication
- * process are persisted (or replicated for clusters) by this Manager.
+ * Determines if the session notes required by the FORM authentication process are persisted (or replicated for
+ * clusters) by this Manager.
*/
private boolean persistAuthenticationNotes = false;
@@ -216,10 +203,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
// Minimum set required for default distribution/persistence to work
// plus String
// plus SerializablePrincipal and String[] (required for authentication persistence)
- setSessionAttributeValueClassNameFilter(
- "java\\.lang\\.(?:Boolean|Integer|Long|Number|String)"
- + "|org\\.apache\\.catalina\\.realm\\.GenericPrincipal\\$SerializablePrincipal"
- + "|\\[Ljava.lang.String;");
+ setSessionAttributeValueClassNameFilter("java\\.lang\\.(?:Boolean|Integer|Long|Number|String)" +
+ "|org\\.apache\\.catalina\\.realm\\.GenericPrincipal\\$SerializablePrincipal" +
+ "|\\[Ljava.lang.String;");
setWarnOnSessionAttributeFilterFailure(true);
}
}
@@ -233,7 +219,6 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
-
@Override
public void setNotifyAttributeListenerOnUnchangedValue(boolean notifyAttributeListenerOnUnchangedValue) {
this.notifyAttributeListenerOnUnchangedValue = notifyAttributeListenerOnUnchangedValue;
@@ -253,14 +238,12 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Obtain the regular expression used to filter session attribute based on
- * attribute name. The regular expression is anchored so it must match the
- * entire name
+ * Obtain the regular expression used to filter session attribute based on attribute name. The regular expression is
+ * anchored so it must match the entire name
*
- * @return The regular expression currently used to filter attribute names.
- * {@code null} means no filter is applied. If an empty string is
- * specified then no names will match the filter and all attributes
- * will be blocked.
+ * @return The regular expression currently used to filter attribute names. {@code null} means no filter is applied.
+ * If an empty string is specified then no names will match the filter and all attributes will be
+ * blocked.
*/
public String getSessionAttributeNameFilter() {
if (sessionAttributeNamePattern == null) {
@@ -271,19 +254,17 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Set the regular expression to use to filter session attributes based on
- * attribute name. The regular expression is anchored so it must match the
- * entire name.
+ * Set the regular expression to use to filter session attributes based on attribute name. The regular expression is
+ * anchored so it must match the entire name.
*
- * @param sessionAttributeNameFilter The regular expression to use to filter
- * session attributes based on attribute name. Use {@code null} if no
- * filtering is required. If an empty string is specified then no
- * names will match the filter and all attributes will be blocked.
+ * @param sessionAttributeNameFilter The regular expression to use to filter session attributes based on attribute
+ * name. Use {@code null} if no filtering is required. If an empty string is
+ * specified then no names will match the filter and all attributes will be
+ * blocked.
*
* @throws PatternSyntaxException If the expression is not valid
*/
- public void setSessionAttributeNameFilter(String sessionAttributeNameFilter)
- throws PatternSyntaxException {
+ public void setSessionAttributeNameFilter(String sessionAttributeNameFilter) throws PatternSyntaxException {
if (sessionAttributeNameFilter == null || sessionAttributeNameFilter.length() == 0) {
sessionAttributeNamePattern = null;
} else {
@@ -293,11 +274,10 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Provides {@link #getSessionAttributeNameFilter()} as a pre-compiled
- * regular expression pattern.
+ * Provides {@link #getSessionAttributeNameFilter()} as a pre-compiled regular expression pattern.
*
- * @return The pre-compiled pattern used to filter session attributes based
- * on attribute name. {@code null} means no filter is applied.
+ * @return The pre-compiled pattern used to filter session attributes based on attribute name. {@code null} means no
+ * filter is applied.
*/
protected Pattern getSessionAttributeNamePattern() {
return sessionAttributeNamePattern;
@@ -305,14 +285,11 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Obtain the regular expression used to filter session attribute based on
- * the implementation class of the value. The regular expression is anchored
- * and must match the fully qualified class name.
+ * Obtain the regular expression used to filter session attribute based on the implementation class of the value.
+ * The regular expression is anchored and must match the fully qualified class name.
*
- * @return The regular expression currently used to filter class names.
- * {@code null} means no filter is applied. If an empty string is
- * specified then no names will match the filter and all attributes
- * will be blocked.
+ * @return The regular expression currently used to filter class names. {@code null} means no filter is applied. If
+ * an empty string is specified then no names will match the filter and all attributes will be blocked.
*/
public String getSessionAttributeValueClassNameFilter() {
if (sessionAttributeValueClassNamePattern == null) {
@@ -323,12 +300,10 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Provides {@link #getSessionAttributeValueClassNameFilter()} as a
- * pre-compiled regular expression pattern.
+ * Provides {@link #getSessionAttributeValueClassNameFilter()} as a pre-compiled regular expression pattern.
*
- * @return The pre-compiled pattern used to filter session attributes based
- * on the implementation class name of the value. {@code null} means
- * no filter is applied.
+ * @return The pre-compiled pattern used to filter session attributes based on the implementation class name of the
+ * value. {@code null} means no filter is applied.
*/
protected Pattern getSessionAttributeValueClassNamePattern() {
return sessionAttributeValueClassNamePattern;
@@ -336,33 +311,28 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Set the regular expression to use to filter classes used for session
- * attributes. The regular expression is anchored and must match the fully
- * qualified class name.
+ * Set the regular expression to use to filter classes used for session attributes. The regular expression is
+ * anchored and must match the fully qualified class name.
*
- * @param sessionAttributeValueClassNameFilter The regular expression to use
- * to filter session attributes based on class name. Use {@code
- * null} if no filtering is required. If an empty string is
- * specified then no names will match the filter and all
- * attributes will be blocked.
+ * @param sessionAttributeValueClassNameFilter The regular expression to use to filter session attributes based on
+ * class name. Use {@code
+ * null} if no filtering is required. If an empty string is specified then no
+ * names will match the filter and all attributes will be blocked.
*
* @throws PatternSyntaxException If the expression is not valid
*/
public void setSessionAttributeValueClassNameFilter(String sessionAttributeValueClassNameFilter)
throws PatternSyntaxException {
- if (sessionAttributeValueClassNameFilter == null ||
- sessionAttributeValueClassNameFilter.length() == 0) {
+ if (sessionAttributeValueClassNameFilter == null || sessionAttributeValueClassNameFilter.length() == 0) {
sessionAttributeValueClassNamePattern = null;
} else {
- sessionAttributeValueClassNamePattern =
- Pattern.compile(sessionAttributeValueClassNameFilter);
+ sessionAttributeValueClassNamePattern = Pattern.compile(sessionAttributeValueClassNameFilter);
}
}
/**
- * Should a warn level log message be generated if a session attribute is
- * not persisted / replicated / restored.
+ * Should a warn level log message be generated if a session attribute is not persisted / replicated / restored.
*
* @return {@code true} if a warn level log message should be generated
*/
@@ -372,15 +342,12 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Configure whether or not a warn level log message should be generated if
- * a session attribute is not persisted / replicated / restored.
- *
- * @param warnOnSessionAttributeFilterFailure {@code true} if the
- * warn level message should be generated
+ * Configure whether or not a warn level log message should be generated if a session attribute is not persisted /
+ * replicated / restored.
*
+ * @param warnOnSessionAttributeFilterFailure {@code true} if the warn level message should be generated
*/
- public void setWarnOnSessionAttributeFilterFailure(
- boolean warnOnSessionAttributeFilterFailure) {
+ public void setWarnOnSessionAttributeFilterFailure(boolean warnOnSessionAttributeFilterFailure) {
this.warnOnSessionAttributeFilterFailure = warnOnSessionAttributeFilterFailure;
}
@@ -422,7 +389,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
try {
sessionIdGenerator = sessionIdGeneratorClass.getConstructor().newInstance();
return sessionIdGenerator;
- } catch(ReflectiveOperationException ex) {
+ } catch (ReflectiveOperationException ex) {
// Ignore
}
}
@@ -455,15 +422,13 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Set the secure random number generator class name.
*
- * @param secureRandomClass The new secure random number generator class
- * name
+ * @param secureRandomClass The new secure random number generator class name
*/
public void setSecureRandomClass(String secureRandomClass) {
String oldSecureRandomClass = this.secureRandomClass;
this.secureRandomClass = secureRandomClass;
- support.firePropertyChange("secureRandomClass", oldSecureRandomClass,
- this.secureRandomClass);
+ support.firePropertyChange("secureRandomClass", oldSecureRandomClass, this.secureRandomClass);
}
@@ -479,8 +444,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Set the secure random number generator algorithm name.
*
- * @param secureRandomAlgorithm The new secure random number generator
- * algorithm name
+ * @param secureRandomAlgorithm The new secure random number generator algorithm name
*/
public void setSecureRandomAlgorithm(String secureRandomAlgorithm) {
this.secureRandomAlgorithm = secureRandomAlgorithm;
@@ -498,8 +462,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Set the secure random number generator provider name.
*
- * @param secureRandomProvider The new secure random number generator
- * provider name
+ * @param secureRandomProvider The new secure random number generator provider name
*/
public void setSecureRandomProvider(String secureRandomProvider) {
this.secureRandomProvider = secureRandomProvider;
@@ -552,30 +515,27 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
int oldProcessExpiresFrequency = this.processExpiresFrequency;
this.processExpiresFrequency = processExpiresFrequency;
- support.firePropertyChange("processExpiresFrequency",
- Integer.valueOf(oldProcessExpiresFrequency),
- Integer.valueOf(this.processExpiresFrequency));
+ support.firePropertyChange("processExpiresFrequency", Integer.valueOf(oldProcessExpiresFrequency),
+ Integer.valueOf(this.processExpiresFrequency));
}
/**
- * Return whether sessions managed by this manager shall persist authentication
- * information or not.
+ * Return whether sessions managed by this manager shall persist authentication information or not.
*
- * @return {@code true}, sessions managed by this manager shall persist
- * authentication information; {@code false} otherwise
+ * @return {@code true}, sessions managed by this manager shall persist authentication information; {@code false}
+ * otherwise
*/
public boolean getPersistAuthentication() {
return this.persistAuthentication;
}
/**
- * Set whether sessions managed by this manager shall persist authentication
- * information or not.
+ * Set whether sessions managed by this manager shall persist authentication information or not.
*
- * @param persistAuthentication if {@code true}, sessions managed by this manager
- * shall persist authentication information
+ * @param persistAuthentication if {@code true}, sessions managed by this manager shall persist authentication
+ * information
*/
public void setPersistAuthentication(boolean persistAuthentication) {
this.persistAuthentication = persistAuthentication;
@@ -583,15 +543,13 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Return whether sessions managed by this manager shall persist
- * authentication notes used by FORM authentication or not.
+ * Return whether sessions managed by this manager shall persist authentication notes used by FORM authentication or
+ * not.
*
- * @return {@code true}, sessions managed by this manager shall persist
- * authentication notes used by FORM authentication; {@code false}
- * otherwise
+ * @return {@code true}, sessions managed by this manager shall persist authentication notes used by FORM
+ * authentication; {@code false} otherwise
*
- * @deprecated Will be removed in Tomcat 10.1.x where it is effectively
- * hard-coded to <code>true</code>
+ * @deprecated Will be removed in Tomcat 10.1.x where it is effectively hard-coded to <code>true</code>
*/
@Deprecated
public boolean getPersistAuthenticationNotes() {
@@ -599,16 +557,13 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
/**
- * Set whether sessions managed by this manager shall persist authentication
- * notes used by FORM authentication or not.
+ * Set whether sessions managed by this manager shall persist authentication notes used by FORM authentication or
+ * not.
*
- * @param persistAuthenticationNotes if {@code true}, sessions managed by
- * this manager shall persist
- * authentication notes used by FORM
- * authentication
+ * @param persistAuthenticationNotes if {@code true}, sessions managed by this manager shall persist authentication
+ * notes used by FORM authentication
*
- * @deprecated Will be removed in Tomcat 10.1.x where it is effectively
- * hard-coded to <code>true</code>
+ * @deprecated Will be removed in Tomcat 10.1.x where it is effectively hard-coded to <code>true</code>
*/
@Deprecated
public void setPersistAuthenticationNotes(boolean persistAuthenticationNotes) {
@@ -638,9 +593,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
long timeNow = System.currentTimeMillis();
Session sessions[] = findSessions();
- int expireHere = 0 ;
+ int expireHere = 0;
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("Start expire sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
}
for (Session session : sessions) {
@@ -649,10 +604,11 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
}
long timeEnd = System.currentTimeMillis();
- if(log.isDebugEnabled()) {
- log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) + " expired sessions: " + expireHere);
+ if (log.isDebugEnabled()) {
+ log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) +
+ " expired sessions: " + expireHere);
}
- processingTime += ( timeEnd - timeNow );
+ processingTime += (timeEnd - timeNow);
}
@@ -688,7 +644,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
sessionIdGenerator.setJvmRoute(getJvmRoute());
if (sessionIdGenerator instanceof SessionIdGeneratorBase) {
- SessionIdGeneratorBase sig = (SessionIdGeneratorBase)sessionIdGenerator;
+ SessionIdGeneratorBase sig = (SessionIdGeneratorBase) sessionIdGenerator;
sig.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
sig.setSecureRandomClass(getSecureRandomClass());
sig.setSecureRandomProvider(getSecureRandomProvider());
@@ -721,9 +677,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
public void add(Session session) {
sessions.put(session.getIdInternal(), session);
int size = getActiveSessions();
- if( size > maxActive ) {
- synchronized(maxActiveUpdateLock) {
- if( size > maxActive ) {
+ if (size > maxActive) {
+ synchronized (maxActiveUpdateLock) {
+ if (size > maxActive) {
maxActive = size;
}
}
@@ -740,12 +696,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
@Override
public Session createSession(String sessionId) {
- if ((maxActiveSessions >= 0) &&
- (getActiveSessions() >= maxActiveSessions)) {
+ if ((maxActiveSessions >= 0) && (getActiveSessions() >= maxActiveSessions)) {
rejectedSessions++;
- throw new TooManyActiveSessionsException(
- sm.getString("managerBase.createSession.ise"),
- maxActiveSessions);
+ throw new TooManyActiveSessionsException(sm.getString("managerBase.createSession.ise"), maxActiveSessions);
}
// Recycle or create a Session instance
@@ -805,8 +758,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
// the manager because it is being persisted - update the expired stats
if (update) {
long timeNow = System.currentTimeMillis();
- int timeAlive =
- (int) (timeNow - session.getCreationTimeInternal())/1000;
+ int timeAlive = (int) (timeNow - session.getCreationTimeInternal()) / 1000;
updateSessionMaxAliveTime(timeAlive);
expiredSessions.incrementAndGet();
SessionTiming timing = new SessionTiming(timeNow, timeAlive);
@@ -848,12 +800,11 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
- protected void changeSessionId(Session session, String newId,
- boolean notifySessionListeners, boolean notifyContainerListeners) {
+ protected void changeSessionId(Session session, String newId, boolean notifySessionListeners,
+ boolean notifyContainerListeners) {
String oldId = session.getIdInternal();
session.setId(newId, false);
- session.tellChangedSessionId(newId, oldId,
- notifySessionListeners, notifyContainerListeners);
+ session.tellChangedSessionId(newId, oldId, notifySessionListeners, notifyContainerListeners);
}
@@ -871,8 +822,8 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
if (sessionAttributeNamePattern != null) {
if (!sessionAttributeNamePattern.matcher(name).matches()) {
if (getWarnOnSessionAttributeFilterFailure() || log.isDebugEnabled()) {
- String msg = sm.getString("managerBase.sessionAttributeNameFilter",
- name, sessionAttributeNamePattern);
+ String msg =
+ sm.getString("managerBase.sessionAttributeNameFilter", name, sessionAttributeNamePattern);
if (getWarnOnSessionAttributeFilterFailure()) {
log.warn(msg);
} else {
@@ -885,11 +836,10 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
Pattern sessionAttributeValueClassNamePattern = getSessionAttributeValueClassNamePattern();
if (value != null && sessionAttributeValueClassNamePattern != null) {
- if (!sessionAttributeValueClassNamePattern.matcher(
- value.getClass().getName()).matches()) {
+ if (!sessionAttributeValueClassNamePattern.matcher(value.getClass().getName()).matches()) {
if (getWarnOnSessionAttributeFilterFailure() || log.isDebugEnabled()) {
- String msg = sm.getString("managerBase.sessionAttributeValueClassNameFilter",
- name, value.getClass().getName(), sessionAttributeValueClassNamePattern);
+ String msg = sm.getString("managerBase.sessionAttributeValueClassNameFilter", name,
+ value.getClass().getName(), sessionAttributeValueClassNamePattern);
if (getWarnOnSessionAttributeFilterFailure()) {
log.warn(msg);
} else {
@@ -909,6 +859,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Get new session class to be used in the doLoad() method.
+ *
* @return a new session for use with this manager
*/
protected StandardSession getNewSession() {
@@ -918,6 +869,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Generate and return a new session identifier.
+ *
* @return a new session id
*/
protected String generateSessionId() {
@@ -950,9 +902,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
*/
public Engine getEngine() {
Engine e = null;
- for (Container c = getContext(); e == null && c != null ; c = c.getParent()) {
+ for (Container c = getContext(); e == null && c != null; c = c.getParent()) {
if (c instanceof Engine) {
- e = (Engine)c;
+ e = (Engine) c;
}
}
return e;
@@ -961,6 +913,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Retrieve the JvmRoute for the enclosing Engine.
+ *
* @return the JvmRoute or null.
*/
public String getJvmRoute() {
@@ -985,8 +938,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Number of duplicated session IDs generated by the random source.
- * Anything bigger than 0 means problems.
+ * Number of duplicated session IDs generated by the random source. Anything bigger than 0 means problems.
*
* @return The count of duplicates
*/
@@ -1021,8 +973,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * @return The maximum number of active Sessions allowed, or -1 for no
- * limit.
+ * @return The maximum number of active Sessions allowed, or -1 for no limit.
*/
public int getMaxActiveSessions() {
return this.maxActiveSessions;
@@ -1030,8 +981,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Set the maximum number of active Sessions allowed, or -1 for
- * no limit.
+ * Set the maximum number of active Sessions allowed, or -1 for no limit.
*
* @param max The new maximum number of sessions
*/
@@ -1039,9 +989,8 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
int oldMaxActiveSessions = this.maxActiveSessions;
this.maxActiveSessions = max;
- support.firePropertyChange("maxActiveSessions",
- Integer.valueOf(oldMaxActiveSessions),
- Integer.valueOf(this.maxActiveSessions));
+ support.firePropertyChange("maxActiveSessions", Integer.valueOf(oldMaxActiveSessions),
+ Integer.valueOf(this.maxActiveSessions));
}
@@ -1061,11 +1010,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * Updates the sessionMaxAliveTime attribute if the candidate value is
- * larger than the current value.
+ * Updates the sessionMaxAliveTime attribute if the candidate value is larger than the current value.
*
- * @param sessionAliveTime The candidate value (in seconds) for the new
- * sessionMaxAliveTime value.
+ * @param sessionAliveTime The candidate value (in seconds) for the new sessionMaxAliveTime value.
*/
public void updateSessionMaxAliveTime(int sessionAliveTime) {
if (sessionAliveTime > this.sessionMaxAliveTime) {
@@ -1080,8 +1027,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* {@inheritDoc}
* <p>
- * Based on the last 100 sessions to expire. If less than 100 sessions have
- * expired then all available data is used.
+ * Based on the last 100 sessions to expire. If less than 100 sessions have expired then all available data is used.
*/
@Override
public int getSessionAverageAliveTime() {
@@ -1101,8 +1047,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
int timeAlive = timing.getDuration();
counter++;
// Very careful not to overflow - probably not necessary
- result =
- (result * ((counter - 1)/counter)) + (timeAlive/counter);
+ result = (result * ((counter - 1) / counter)) + (timeAlive / counter);
}
}
return result;
@@ -1110,9 +1055,10 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
- * {@inheritDoc}<p>
- * Based on the creation time of the previous 100 sessions created. If less
- * than 100 sessions have been created then all available data is used.
+ * {@inheritDoc}
+ * <p>
+ * Based on the creation time of the previous 100 sessions created. If less than 100 sessions have been created then
+ * all available data is used.
*/
@Override
public int getSessionCreateRate() {
@@ -1129,10 +1075,10 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* {@inheritDoc}
* <p>
- * Based on the expiry time of the previous 100 sessions expired. If less
- * than 100 sessions have expired then all available data is used.
+ * Based on the expiry time of the previous 100 sessions expired. If less than 100 sessions have expired then all
+ * available data is used.
*
- * @return The current rate (in sessions per minute) of session expiration
+ * @return The current rate (in sessions per minute) of session expiration
*/
@Override
public int getSessionExpireRate() {
@@ -1164,7 +1110,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
if (counter > 0) {
if (oldest < now) {
- result = (1000*60*counter)/(int) (now - oldest);
+ result = (1000 * 60 * counter) / (int) (now - oldest);
} else {
// Better than reporting zero
result = Integer.MAX_VALUE;
@@ -1194,10 +1140,9 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
* @param sessionId The ID for the session of interest
* @param key The key for the attribute to obtain
*
- * @return The attribute value for the specified session, if found, null
- * otherwise
+ * @return The attribute value for the specified session, if found, null otherwise
*/
- public String getSessionAttribute( String sessionId, String key ) {
+ public String getSessionAttribute(String sessionId, String key) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1205,8 +1150,8 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
return null;
}
- Object o=s.getSession().getAttribute(key);
- if( o==null ) {
+ Object o = s.getSession().getAttribute(key);
+ if (o == null) {
return null;
}
return o.toString();
@@ -1215,17 +1160,16 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
/**
* Returns information about the session with the given session id.
- *
- * <p>The session information is organized as a HashMap, mapping
- * session attribute names to the String representation of their values.
+ * <p>
+ * The session information is organized as a HashMap, mapping session attribute names to the String representation
+ * of their values.
*
* @param sessionId Session id
*
- * @return HashMap mapping session attribute names to the String
- * representation of their values, or null if no session with the
- * specified id exists, or if the session does not have any attributes
+ * @return HashMap mapping session attribute names to the String representation of their values, or null if no
+ * session with the specified id exists, or if the session does not have any attributes
*/
- public HashMap<String, String> getSession(String sessionId) {
+ public HashMap<String,String> getSession(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1239,7 +1183,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return null;
}
- HashMap<String, String> map = new HashMap<>();
+ HashMap<String,String> map = new HashMap<>();
while (ee.hasMoreElements()) {
String attrName = ee.nextElement();
map.put(attrName, getSessionAttribute(sessionId, attrName));
@@ -1249,7 +1193,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
- public void expireSession( String sessionId ) {
+ public void expireSession(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1260,7 +1204,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
s.expire();
}
- public long getThisAccessedTimestamp( String sessionId ) {
+ public long getThisAccessedTimestamp(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1271,7 +1215,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return s.getThisAccessedTime();
}
- public String getThisAccessedTime( String sessionId ) {
+ public String getThisAccessedTime(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1282,7 +1226,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return new Date(s.getThisAccessedTime()).toString();
}
- public long getLastAccessedTimestamp( String sessionId ) {
+ public long getLastAccessedTimestamp(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1293,7 +1237,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return s.getLastAccessedTime();
}
- public String getLastAccessedTime( String sessionId ) {
+ public String getLastAccessedTime(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1304,7 +1248,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return new Date(s.getLastAccessedTime()).toString();
}
- public String getCreationTime( String sessionId ) {
+ public String getCreationTime(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1315,7 +1259,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
return new Date(s.getCreationTime()).toString();
}
- public long getCreationTimestamp( String sessionId ) {
+ public long getCreationTimestamp(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
@@ -1333,7 +1277,7 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
- // -------------------- JMX and Registration --------------------
+ // -------------------- JMX and Registration --------------------
@Override
public String getObjectNameKeyProperties() {
@@ -1370,16 +1314,14 @@ public abstract class ManagerBase extends LifecycleMBeanBase implements Manager
}
/**
- * @return Time stamp associated with this piece of timing information
- * in milliseconds.
+ * @return Time stamp associated with this piece of timing information in milliseconds.
*/
public long getTimestamp() {
return timestamp;
}
/**
- * @return Duration associated with this piece of timing information in
- * seconds.
+ * @return Duration associated with this piece of timing information in seconds.
*/
public int getDuration() {
return duration;
diff --git a/java/org/apache/catalina/session/PersistentManager.java b/java/org/apache/catalina/session/PersistentManager.java
index 09f9a43424..5fd7cd8ea2 100644
--- a/java/org/apache/catalina/session/PersistentManager.java
+++ b/java/org/apache/catalina/session/PersistentManager.java
@@ -17,16 +17,12 @@
package org.apache.catalina.session;
/**
- * Implementation of the <b>Manager</b> interface that makes use of
- * a Store to swap active Sessions to disk. It can be configured to
- * achieve several different goals:
- *
+ * Implementation of the <b>Manager</b> interface that makes use of a Store to swap active Sessions to disk. It can be
+ * configured to achieve several different goals:
* <ul>
* <li>Persist sessions across restarts of the Container</li>
- * <li>Fault tolerance, keep sessions backed up on disk to allow
- * recovery in the event of unplanned restarts.</li>
- * <li>Limit the number of active sessions kept in memory by
- * swapping less active sessions out to disk.</li>
+ * <li>Fault tolerance, keep sessions backed up on disk to allow recovery in the event of unplanned restarts.</li>
+ * <li>Limit the number of active sessions kept in memory by swapping less active sessions out to disk.</li>
* </ul>
*
* @author Kief Morris (kief@kief.com)
@@ -47,5 +43,5 @@ public final class PersistentManager extends PersistentManagerBase {
public String getName() {
return name;
}
- }
+}
diff --git a/java/org/apache/catalina/session/PersistentManagerBase.java b/java/org/apache/catalina/session/PersistentManagerBase.java
index 2c5b01deb9..0bf00c343f 100644
--- a/java/org/apache/catalina/session/PersistentManagerBase.java
+++ b/java/org/apache/catalina/session/PersistentManagerBase.java
@@ -35,41 +35,36 @@ import org.apache.catalina.StoreManager;
import org.apache.catalina.security.SecurityUtil;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+
/**
- * Extends the {@link ManagerBase} class to implement most of the
- * functionality required by a Manager which supports any kind of
- * persistence, even if only for restarts.
+ * Extends the {@link ManagerBase} class to implement most of the functionality required by a Manager which supports any
+ * kind of persistence, even if only for restarts.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: Correct behavior of session storing and
- * reloading depends upon external calls to the {@link Lifecycle#start()}
- * and {@link Lifecycle#stop()} methods of this class
- * at the correct times.
+ * <b>IMPLEMENTATION NOTE</b>: Correct behavior of session storing and reloading depends upon external calls to the
+ * {@link Lifecycle#start()} and {@link Lifecycle#stop()} methods of this class at the correct times.
*
* @author Craig R. McClanahan
*/
-public abstract class PersistentManagerBase extends ManagerBase
- implements StoreManager {
+public abstract class PersistentManagerBase extends ManagerBase implements StoreManager {
private final Log log = LogFactory.getLog(PersistentManagerBase.class); // must not be static
// ---------------------------------------------------- Security Classes
- private class PrivilegedStoreClear
- implements PrivilegedExceptionAction<Void> {
+ private class PrivilegedStoreClear implements PrivilegedExceptionAction<Void> {
PrivilegedStoreClear() {
// NOOP
}
@Override
- public Void run() throws Exception{
- store.clear();
- return null;
+ public Void run() throws Exception {
+ store.clear();
+ return null;
}
}
- private class PrivilegedStoreRemove
- implements PrivilegedExceptionAction<Void> {
+ private class PrivilegedStoreRemove implements PrivilegedExceptionAction<Void> {
private String id;
@@ -78,14 +73,13 @@ public abstract class PersistentManagerBase extends ManagerBase
}
@Override
- public Void run() throws Exception{
- store.remove(id);
- return null;
+ public Void run() throws Exception {
+ store.remove(id);
+ return null;
}
}
- private class PrivilegedStoreLoad
- implements PrivilegedExceptionAction<Session> {
+ private class PrivilegedStoreLoad implements PrivilegedExceptionAction<Session> {
private String id;
@@ -94,13 +88,12 @@ public abstract class PersistentManagerBase extends ManagerBase
}
@Override
- public Session run() throws Exception{
- return store.load(id);
+ public Session run() throws Exception {
+ return store.load(id);
}
}
- private class PrivilegedStoreSave
- implements PrivilegedExceptionAction<Void> {
+ private class PrivilegedStoreSave implements PrivilegedExceptionAction<Void> {
private Session session;
@@ -109,22 +102,21 @@ public abstract class PersistentManagerBase extends ManagerBase
}
@Override
- public Void run() throws Exception{
- store.save(session);
- return null;
+ public Void run() throws Exception {
+ store.save(session);
+ return null;
}
}
- private class PrivilegedStoreKeys
- implements PrivilegedExceptionAction<String[]> {
+ private class PrivilegedStoreKeys implements PrivilegedExceptionAction<String[]> {
PrivilegedStoreKeys() {
// NOOP
}
@Override
- public String[] run() throws Exception{
- return store.keys();
+ public String[] run() throws Exception {
+ return store.keys();
}
}
@@ -149,32 +141,29 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Whether to save and reload sessions when the Manager <code>unload</code>
- * and <code>load</code> methods are called.
+ * Whether to save and reload sessions when the Manager <code>unload</code> and <code>load</code> methods are
+ * called.
*/
protected boolean saveOnRestart = true;
/**
- * How long a session must be idle before it should be backed up.
- * {@code -1} means sessions won't be backed up.
+ * How long a session must be idle before it should be backed up. {@code -1} means sessions won't be backed up.
*/
protected int maxIdleBackup = -1;
/**
- * The minimum time in seconds a session must be idle before it is eligible
- * to be swapped to disk to keep the active session count below
- * maxActiveSessions. Setting to {@code -1} means sessions will not be
- * swapped out to keep the active session count down.
+ * The minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the active
+ * session count below maxActiveSessions. Setting to {@code -1} means sessions will not be swapped out to keep the
+ * active session count down.
*/
protected int minIdleSwap = -1;
/**
- * The maximum time in seconds a session may be idle before it is eligible
- * to be swapped to disk due to inactivity. Setting this to {@code -1} means
- * sessions should not be swapped out just because of inactivity.
+ * The maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to inactivity.
+ * Setting this to {@code -1} means sessions should not be swapped out just because of inactivity.
*/
protected int maxIdleSwap = -1;
@@ -185,8 +174,7 @@ public abstract class PersistentManagerBase extends ManagerBase
private final Map<String,Object> sessionSwapInLocks = new HashMap<>();
/*
- * Session that is currently getting swapped in to prevent loading it more
- * than once concurrently
+ * Session that is currently getting swapped in to prevent loading it more than once concurrently
*/
private final ThreadLocal<Session> sessionToSwapIn = new ThreadLocal<>();
@@ -195,9 +183,8 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * 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. {@code -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. {@code -1} means sessions are not backed up.
*
* @return the timeout after which sessions are ripe for back up
*/
@@ -209,43 +196,37 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Sets the option to back sessions up to the Store after they
- * are used in a request. Sessions remain available in memory
- * after being backed up, so they are not passivated as they are
- * when swapped out. The value set indicates how old a session
- * may get (since its last use) before it must be backed up: {@code -1}
- * means sessions are not backed up.
+ * Sets the option to back sessions up to the Store after they are used in a request. Sessions remain available in
+ * memory after being backed up, so they are not passivated as they are when swapped out. The value set indicates
+ * how old a session may get (since its last use) before it must be backed up: {@code -1} 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 {@code processExpiresFrequency}.
- * This value should be considered to indicate when a session is
- * ripe for backing up.
+ * Note that this is not a hard limit: sessions are checked against this age limit periodically according to
+ * {@code processExpiresFrequency}. 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 {@code maxIdleBackup +
* 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
- * time when they should be written to the Store.
+ * @param backup The number of seconds after their last accessed time when they should be written to the Store.
*/
- public void setMaxIdleBackup (int backup) {
+ public void setMaxIdleBackup(int backup) {
if (backup == this.maxIdleBackup) {
return;
}
int oldBackup = this.maxIdleBackup;
this.maxIdleBackup = backup;
- support.firePropertyChange("maxIdleBackup",
- Integer.valueOf(oldBackup),
- Integer.valueOf(this.maxIdleBackup));
+ support.firePropertyChange("maxIdleBackup", Integer.valueOf(oldBackup), Integer.valueOf(this.maxIdleBackup));
}
/**
- * @return The maximum time in seconds a session may be idle before it is
- * eligible to be swapped to disk due to inactivity. A value of {@code -1}
- * means sessions should not be swapped out just because of inactivity.
+ * @return The maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to
+ * inactivity. A value of {@code -1} means sessions should not be swapped out just because of
+ * inactivity.
*/
public int getMaxIdleSwap() {
return maxIdleSwap;
@@ -253,10 +234,8 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Sets the maximum time in seconds a session may be idle before it is
- * eligible to be swapped to disk due to inactivity. Setting this to
- * {@code -1} means sessions should not be swapped out just because of
- * inactivity.
+ * Sets the maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to
+ * inactivity. Setting this to {@code -1} means sessions should not be swapped out just because of inactivity.
*
* @param max time in seconds to wait for possible swap out
*/
@@ -267,17 +246,14 @@ public abstract class PersistentManagerBase extends ManagerBase
}
int oldMaxIdleSwap = this.maxIdleSwap;
this.maxIdleSwap = max;
- support.firePropertyChange("maxIdleSwap",
- Integer.valueOf(oldMaxIdleSwap),
- Integer.valueOf(this.maxIdleSwap));
+ support.firePropertyChange("maxIdleSwap", Integer.valueOf(oldMaxIdleSwap), Integer.valueOf(this.maxIdleSwap));
}
/**
- * @return The minimum time in seconds a session must be idle before it is
- * eligible to be swapped to disk to keep the active session count below
- * maxActiveSessions. A value of {@code -1} means sessions will not be
- * swapped out to keep the active session count down.
+ * @return The minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep
+ * the active session count below maxActiveSessions. A value of {@code -1} means sessions will not be
+ * swapped out to keep the active session count down.
*/
public int getMinIdleSwap() {
return minIdleSwap;
@@ -285,10 +261,9 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Sets the minimum time in seconds a session must be idle before it is
- * eligible to be swapped to disk to keep the active session count below
- * maxActiveSessions. Setting to {@code -1} means sessions will not be
- * swapped out to keep the active session count down.
+ * Sets the minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the
+ * active session count below maxActiveSessions. Setting to {@code -1} means sessions will not be swapped out to
+ * keep the active session count down.
*
* @param min time in seconds before a possible swap out
*/
@@ -299,9 +274,7 @@ public abstract class PersistentManagerBase extends ManagerBase
}
int oldMinIdleSwap = this.minIdleSwap;
this.minIdleSwap = min;
- support.firePropertyChange("minIdleSwap",
- Integer.valueOf(oldMinIdleSwap),
- Integer.valueOf(this.minIdleSwap));
+ support.firePropertyChange("minIdleSwap", Integer.valueOf(oldMinIdleSwap), Integer.valueOf(this.minIdleSwap));
}
@@ -310,8 +283,8 @@ public abstract class PersistentManagerBase extends ManagerBase
* Check, whether a session is loaded in memory
*
* @param id The session id for the session to be searched for
- * @return {@code true}, if the session id is loaded in memory
- * otherwise {@code false} is returned
+ *
+ * @return {@code true}, if the session id is loaded in memory otherwise {@code false} is returned
*/
public boolean isLoaded(String id) {
try {
@@ -332,8 +305,7 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Set the Store object which will manage persistent Session
- * storage for this Manager.
+ * Set the Store object which will manage persistent Session storage for this Manager.
*
* @param store the associated Store
*/
@@ -344,8 +316,7 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * @return the Store object which manages persistent Session
- * storage for this Manager.
+ * @return the Store object which manages persistent Session storage for this Manager.
*/
@Override
public Store getStore() {
@@ -354,11 +325,10 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Indicates whether sessions are saved when the Manager is shut down
- * properly. This requires the {@link #unload()} method to be called.
+ * Indicates whether sessions are saved when the Manager is shut down properly. This requires the {@link #unload()}
+ * method to be called.
*
- * @return {@code true}, when sessions should be saved on restart,
- * {code false} otherwise
+ * @return {@code true}, when sessions should be saved on restart, {code false} otherwise
*/
public boolean getSaveOnRestart() {
@@ -368,13 +338,11 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Set the option to save sessions to the Store when the Manager is
- * shut down, then loaded when the Manager starts again. If set to
- * false, any sessions found in the Store may still be picked up when
- * the Manager is started again.
+ * Set the option to save sessions to the Store when the Manager is shut down, then loaded when the Manager starts
+ * again. If set to false, any sessions found in the Store may still be picked up when the Manager is started again.
*
- * @param saveOnRestart {@code true} if sessions should be saved on restart, {@code false} if
- * they should be ignored.
+ * @param saveOnRestart {@code true} if sessions should be saved on restart, {@code false} if they should be
+ * ignored.
*/
public void setSaveOnRestart(boolean saveOnRestart) {
@@ -384,9 +352,8 @@ public abstract class PersistentManagerBase extends ManagerBase
boolean oldSaveOnRestart = this.saveOnRestart;
this.saveOnRestart = saveOnRestart;
- support.firePropertyChange("saveOnRestart",
- Boolean.valueOf(oldSaveOnRestart),
- Boolean.valueOf(this.saveOnRestart));
+ support.firePropertyChange("saveOnRestart", Boolean.valueOf(oldSaveOnRestart),
+ Boolean.valueOf(this.saveOnRestart));
}
@@ -430,8 +397,8 @@ public abstract class PersistentManagerBase extends ManagerBase
long timeNow = System.currentTimeMillis();
Session sessions[] = findSessions();
- int expireHere = 0 ;
- if(log.isDebugEnabled()) {
+ int expireHere = 0;
+ if (log.isDebugEnabled()) {
log.debug("Start expire sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
}
for (Session session : sessions) {
@@ -446,8 +413,9 @@ public abstract class PersistentManagerBase extends ManagerBase
}
long timeEnd = System.currentTimeMillis();
- if(log.isDebugEnabled()) {
- log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) + " expired sessions: " + expireHere);
+ if (log.isDebugEnabled()) {
+ log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) +
+ " expired sessions: " + expireHere);
}
processingTime += (timeEnd - timeNow);
@@ -455,8 +423,8 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * 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() {
@@ -470,8 +438,8 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
* {@inheritDoc}
* <p>
- * This method checks the persistence store if persistence is enabled,
- * otherwise just uses the functionality from ManagerBase.
+ * This method checks the persistence store if persistence is enabled, otherwise just uses the functionality from
+ * ManagerBase.
*/
@Override
public Session findSession(String id) throws IOException {
@@ -483,14 +451,14 @@ public abstract class PersistentManagerBase extends ManagerBase
// the other code ran swapOut, then we should get a null back during
// this run, and if not, we lock it out so we can access the session
// safely.
- if(session != null) {
- synchronized(session){
+ if (session != null) {
+ synchronized (session) {
session = super.findSession(session.getIdInternal());
- if(session != null){
- // To keep any external calling code from messing up the
- // concurrency.
- session.access();
- session.endAccess();
+ if (session != null) {
+ // To keep any external calling code from messing up the
+ // concurrency.
+ session.access();
+ session.endAccess();
}
}
}
@@ -504,8 +472,8 @@ public abstract class PersistentManagerBase extends ManagerBase
}
/**
- * Remove this Session from the active Sessions for this Manager,
- * but not from the Store. (Used by the PersistentValve)
+ * Remove this Session from the active Sessions for this Manager, but not from the Store. (Used by the
+ * PersistentValve)
*
* @param session Session to be removed
*/
@@ -515,14 +483,11 @@ public abstract class PersistentManagerBase extends ManagerBase
}
/**
- * Load all sessions found in the persistence mechanism, assuming
- * they are marked as valid and have not passed their expiration
- * limit. If persistence is not supported, this method returns
- * without doing anything.
+ * Load all sessions found in the persistence mechanism, assuming they are marked as valid and have not passed their
+ * expiration limit. If persistence is not supported, this method returns without doing anything.
* <p>
- * Note that by default, this method is not called by the MiddleManager
- * class. In order to use it, a subclass must specifically call it,
- * for example in the start() and/or processPersistenceChecks() methods.
+ * Note that by default, this method is not called by the MiddleManager class. In order to use it, a subclass must
+ * specifically call it, for example in the start() and/or processPersistenceChecks() methods.
*/
@Override
public void load() {
@@ -540,8 +505,7 @@ public abstract class PersistentManagerBase extends ManagerBase
try {
ids = AccessController.doPrivileged(new PrivilegedStoreKeys());
} catch (PrivilegedActionException e) {
- log.error(sm.getString("persistentManager.storeLoadKeysError"),
- e.getException());
+ log.error(sm.getString("persistentManager.storeLoadKeysError"), e.getException());
return;
}
} else {
@@ -580,21 +544,20 @@ public abstract class PersistentManagerBase extends ManagerBase
@Override
public void remove(Session session, boolean update) {
- super.remove (session, update);
+ super.remove(session, update);
- if (store != null){
+ if (store != null) {
removeSession(session.getIdInternal());
}
}
/**
- * Remove this Session from the active Sessions for this Manager,
- * and from the Store.
+ * Remove this Session from the active Sessions for this Manager, and from the Store.
*
* @param id Session's id to be removed
*/
- protected void removeSession(String id){
+ protected void removeSession(String id) {
try {
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
@@ -611,13 +574,11 @@ public abstract class PersistentManagerBase extends ManagerBase
}
/**
- * Save all currently active sessions in the appropriate persistence
- * mechanism, if any. If persistence is not supported, this method
- * returns without doing anything.
+ * Save all currently active sessions in the appropriate persistence mechanism, if any. If persistence is not
+ * supported, this method returns without doing anything.
* <p>
- * Note that by default, this method is not called by the MiddleManager
- * class. In order to use it, a subclass must specifically call it,
- * for example in the stop() and/or processPersistenceChecks() methods.
+ * Note that by default, this method is not called by the MiddleManager class. In order to use it, a subclass must
+ * specifically call it, for example in the stop() and/or processPersistenceChecks() methods.
*/
@Override
public void unload() {
@@ -633,8 +594,7 @@ public abstract class PersistentManagerBase extends ManagerBase
}
if (log.isDebugEnabled()) {
- log.debug(sm.getString("persistentManager.unloading",
- String.valueOf(n)));
+ log.debug(sm.getString("persistentManager.unloading", String.valueOf(n)));
}
for (Session session : sessions) {
@@ -679,14 +639,14 @@ public abstract class PersistentManagerBase extends ManagerBase
// ------------------------------------------------------ Protected Methods
/**
- * Look for a session in the Store and, if found, restore
- * it in the Manager's list of active sessions if appropriate.
- * The session will be removed from the Store after swapping
- * in, but will not be added to the active session list if it
- * is invalid or past its expiration.
+ * Look for a session in the Store and, if found, restore it in the Manager's list of active sessions if
+ * appropriate. The session will be removed from the Store after swapping in, but will not be added to the active
+ * session list if it is invalid or past its expiration.
*
* @param id The id of the session that should be swapped in
+ *
* @return restored session, or {@code null}, if none is found
+ *
* @throws IOException an IO error occurred
*/
protected Session swapIn(String id) throws IOException {
@@ -698,12 +658,10 @@ public abstract class PersistentManagerBase extends ManagerBase
Object swapInLock = null;
/*
- * The purpose of this sync and these locks is to make sure that a
- * session is only loaded once. It doesn't matter if the lock is removed
- * and then another thread enters this method and tries to load the same
- * session. That thread will re-create a swapIn lock for that session,
- * quickly find that the session is already in sessions, use it and
- * carry on.
+ * The purpose of this sync and these locks is to make sure that a session is only loaded once. It doesn't
+ * matter if the lock is removed and then another thread enters this method and tries to load the same session.
+ * That thread will re-create a swapIn lock for that session, quickly find that the session is already in
+ * sessions, use it and carry on.
*/
synchronized (this) {
swapInLock = sessionSwapInLocks.computeIfAbsent(id, k -> new Object());
@@ -750,15 +708,15 @@ public abstract class PersistentManagerBase extends ManagerBase
}
private void reactivateLoadedSession(String id, Session session) {
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug(sm.getString("persistentManager.swapIn", id));
}
session.setManager(this);
// make sure the listeners know about it.
- ((StandardSession)session).tellNew();
+ ((StandardSession) session).tellNew();
add(session);
- ((StandardSession)session).activate();
+ ((StandardSession) session).activate();
// endAccess() to ensure timeouts happen correctly.
// access() to keep access count correct or it will end up
// negative
@@ -768,14 +726,13 @@ public abstract class PersistentManagerBase extends ManagerBase
private Session loadSessionFromStore(String id) throws IOException {
try {
- if (SecurityUtil.isPackageProtectionEnabled()){
+ if (SecurityUtil.isPackageProtectionEnabled()) {
return securedStoreLoad(id);
} else {
- return store.load(id);
+ return store.load(id);
}
} catch (ClassNotFoundException e) {
- String msg = sm.getString(
- "persistentManager.deserializeError", id);
+ String msg = sm.getString("persistentManager.deserializeError", id);
log.error(msg, e);
throw new IllegalStateException(msg, e);
}
@@ -784,17 +741,14 @@ public abstract class PersistentManagerBase extends ManagerBase
private Session securedStoreLoad(String id) throws IOException, ClassNotFoundException {
try {
- return AccessController.doPrivileged(
- new PrivilegedStoreLoad(id));
+ return AccessController.doPrivileged(new PrivilegedStoreLoad(id));
} catch (PrivilegedActionException ex) {
Exception e = ex.getException();
- log.error(sm.getString(
- "persistentManager.swapInException", id),
- e);
- if (e instanceof IOException){
- throw (IOException)e;
+ log.error(sm.getString("persistentManager.swapInException", id), e);
+ if (e instanceof IOException) {
+ throw (IOException) e;
} else if (e instanceof ClassNotFoundException) {
- throw (ClassNotFoundException)e;
+ throw (ClassNotFoundException) e;
}
}
return null;
@@ -802,12 +756,11 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Remove the session from the Manager's list of active
- * sessions and write it out to the Store. If the session
- * is past its expiration or invalid, this method does
- * nothing.
+ * Remove the session from the Manager's list of active sessions and write it out to the Store. If the session is
+ * past its expiration or invalid, this method does nothing.
*
* @param session The Session to write out
+ *
* @throws IOException an IO error occurred
*/
protected void swapOut(Session session) throws IOException {
@@ -816,7 +769,7 @@ public abstract class PersistentManagerBase extends ManagerBase
return;
}
- ((StandardSession)session).passivate();
+ ((StandardSession) session).passivate();
writeSession(session);
super.remove(session, true);
session.recycle();
@@ -825,10 +778,11 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Write the provided session to the Store without modifying
- * the copy in memory or triggering passivation events. Does
- * nothing if the session is invalid or past its expiration.
+ * Write the provided session to the Store without modifying the copy in memory or triggering passivation events.
+ * Does nothing if the session is invalid or past its expiration.
+ *
* @param session The session that should be written
+ *
* @throws IOException an IO error occurred
*/
protected void writeSession(Session session) throws IOException {
@@ -838,19 +792,18 @@ public abstract class PersistentManagerBase extends ManagerBase
}
try {
- if (SecurityUtil.isPackageProtectionEnabled()){
- try{
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ try {
AccessController.doPrivileged(new PrivilegedStoreSave(session));
- }catch(PrivilegedActionException ex){
+ } catch (PrivilegedActionException ex) {
Exception exception = ex.getException();
if (exception instanceof IOException) {
throw (IOException) exception;
}
- log.error(sm.getString("persistentManager.serializeError",
- session.getIdInternal(), exception));
+ log.error(sm.getString("persistentManager.serializeError", session.getIdInternal(), exception));
}
} else {
- store.save(session);
+ store.save(session);
}
} catch (IOException e) {
log.error(sm.getString("persistentManager.serializeError", session.getIdInternal(), e));
@@ -861,11 +814,11 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Start this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
+ * Start this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
@@ -875,7 +828,7 @@ public abstract class PersistentManagerBase extends ManagerBase
if (store == null) {
log.error("No Store configured, persistence disabled");
} else if (store instanceof Lifecycle) {
- ((Lifecycle)store).start();
+ ((Lifecycle) store).start();
}
setState(LifecycleState.STARTING);
@@ -883,11 +836,11 @@ public abstract class PersistentManagerBase extends ManagerBase
/**
- * Stop this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
+ * Stop this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
@@ -913,7 +866,7 @@ public abstract class PersistentManagerBase extends ManagerBase
}
if (getStore() instanceof Lifecycle) {
- ((Lifecycle)getStore()).stop();
+ ((Lifecycle) getStore()).stop();
}
// Require a new random number generator if we are restarted
@@ -945,16 +898,13 @@ public abstract class PersistentManagerBase extends ManagerBase
}
int timeIdle = (int) (session.getIdleTimeInternal() / 1000L);
if (timeIdle >= maxIdleSwap && timeIdle >= minIdleSwap) {
- if (session.accessCount != null &&
- session.accessCount.get() > 0) {
+ if (session.accessCount != null && session.accessCount.get() > 0) {
// Session is currently being accessed - skip it
continue;
}
if (log.isDebugEnabled()) {
- log.debug(sm.getString
- ("persistentManager.swapMaxIdle",
- session.getIdInternal(),
- Integer.valueOf(timeIdle)));
+ log.debug(sm.getString("persistentManager.swapMaxIdle", session.getIdInternal(),
+ Integer.valueOf(timeIdle)));
}
try {
swapOut(session);
@@ -987,29 +937,24 @@ public abstract class PersistentManagerBase extends ManagerBase
return;
}
- if(log.isDebugEnabled()) {
- log.debug(sm.getString
- ("persistentManager.tooManyActive",
- Integer.valueOf(sessions.length)));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("persistentManager.tooManyActive", Integer.valueOf(sessions.length)));
}
int toswap = sessions.length - limit;
for (int i = 0; i < sessions.length && toswap > 0; i++) {
- StandardSession session = (StandardSession) sessions[i];
+ StandardSession session = (StandardSession) sessions[i];
synchronized (session) {
int timeIdle = (int) (session.getIdleTimeInternal() / 1000L);
if (timeIdle >= minIdleSwap) {
- if (session.accessCount != null &&
- session.accessCount.get() > 0) {
+ if (session.accessCount != null && session.accessCount.get() > 0) {
// Session is currently being accessed - skip it
continue;
}
- if(log.isDebugEnabled()) {
- log.debug(sm.getString
- ("persistentManager.swapTooManyActive",
- session.getIdInternal(),
- Integer.valueOf(timeIdle)));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("persistentManager.swapTooManyActive", session.getIdInternal(),
+ Integer.valueOf(timeIdle)));
}
try {
swapOut(session);
@@ -1044,8 +989,7 @@ public abstract class PersistentManagerBase extends ManagerBase
continue;
}
long lastAccessedTime = session.getLastAccessedTimeInternal();
- Long persistedLastAccessedTime =
- (Long) session.getNote(PERSISTED_LAST_ACCESSED_TIME);
+ Long persistedLastAccessedTime = (Long) session.getNote(PERSISTED_LAST_ACCESSED_TIME);
if (persistedLastAccessedTime != null &&
lastAccessedTime == persistedLastAccessedTime.longValue()) {
continue;
@@ -1053,10 +997,8 @@ public abstract class PersistentManagerBase extends ManagerBase
int timeIdle = (int) (session.getIdleTimeInternal() / 1000L);
if (timeIdle >= maxIdleBackup) {
if (log.isDebugEnabled()) {
- log.debug(sm.getString
- ("persistentManager.backupMaxIdle",
- session.getIdInternal(),
- Integer.valueOf(timeIdle)));
+ log.debug(sm.getString("persistentManager.backupMaxIdle", session.getIdInternal(),
+ Integer.valueOf(timeIdle)));
}
try {
@@ -1064,8 +1006,7 @@ public abstract class PersistentManagerBase extends ManagerBase
} catch (IOException e) {
// This is logged in writeSession()
}
- session.setNote(PERSISTED_LAST_ACCESSED_TIME,
- Long.valueOf(lastAccessedTime));
+ session.setNote(PERSISTED_LAST_ACCESSED_TIME, Long.valueOf(lastAccessedTime));
}
}
}
diff --git a/java/org/apache/catalina/session/StandardManager.java b/java/org/apache/catalina/session/StandardManager.java
index 7850305942..714bdd0e71 100644
--- a/java/org/apache/catalina/session/StandardManager.java
+++ b/java/org/apache/catalina/session/StandardManager.java
@@ -45,14 +45,12 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
/**
- * Standard implementation of the <b>Manager</b> interface that provides
- * simple session persistence across restarts of this component (such as
- * when the entire server is shut down and restarted, or when a particular
- * web application is reloaded.
+ * Standard implementation of the <b>Manager</b> interface that provides simple session persistence across restarts of
+ * this component (such as when the entire server is shut down and restarted, or when a particular web application is
+ * reloaded.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: Correct behavior of session storing and
- * reloading depends upon external calls to the <code>start()</code> and
- * <code>stop()</code> methods of this class at the correct times.
+ * <b>IMPLEMENTATION NOTE</b>: Correct behavior of session storing and reloading depends upon external calls to the
+ * <code>start()</code> and <code>stop()</code> methods of this class at the correct times.
*
* @author Craig R. McClanahan
*/
@@ -62,29 +60,27 @@ public class StandardManager extends ManagerBase {
// ---------------------------------------------------- Security Classes
- private class PrivilegedDoLoad
- implements PrivilegedExceptionAction<Void> {
+ private class PrivilegedDoLoad implements PrivilegedExceptionAction<Void> {
PrivilegedDoLoad() {
// NOOP
}
@Override
- public Void run() throws Exception{
- doLoad();
- return null;
+ public Void run() throws Exception {
+ doLoad();
+ return null;
}
}
- private class PrivilegedDoUnload
- implements PrivilegedExceptionAction<Void> {
+ private class PrivilegedDoUnload implements PrivilegedExceptionAction<Void> {
PrivilegedDoUnload() {
// NOOP
}
@Override
- public Void run() throws Exception{
+ public Void run() throws Exception {
doUnload();
return null;
}
@@ -101,12 +97,10 @@ public class StandardManager extends ManagerBase {
/**
- * Path name of the disk file in which active sessions are saved
- * when we stop, and from which these sessions are loaded when we start.
- * A <code>null</code> value indicates that no persistence is desired.
- * If this pathname is relative, it will be resolved against the
- * temporary working directory provided by our context, available via
- * the <code>javax.servlet.context.tempdir</code> context attribute.
+ * Path name of the disk file in which active sessions are saved when we stop, and from which these sessions are
+ * loaded when we start. A <code>null</code> value indicates that no persistence is desired. If this pathname is
+ * relative, it will be resolved against the temporary working directory provided by our context, available via the
+ * <code>javax.servlet.context.tempdir</code> context attribute.
*/
protected String pathname = "SESSIONS.ser";
@@ -128,8 +122,8 @@ public class StandardManager extends ManagerBase {
/**
- * Set the session persistence pathname to the specified value. If no
- * persistence support is desired, set the pathname to <code>null</code>.
+ * Set the session persistence pathname to the specified value. If no persistence support is desired, set the
+ * pathname to <code>null</code>.
*
* @param pathname New session persistence pathname
*/
@@ -144,15 +138,15 @@ public class StandardManager extends ManagerBase {
@Override
public void load() throws ClassNotFoundException, IOException {
- if (SecurityUtil.isPackageProtectionEnabled()){
- try{
- AccessController.doPrivileged( new PrivilegedDoLoad() );
- } catch (PrivilegedActionException ex){
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ try {
+ AccessController.doPrivileged(new PrivilegedDoLoad());
+ } catch (PrivilegedActionException ex) {
Exception exception = ex.getException();
if (exception instanceof ClassNotFoundException) {
- throw (ClassNotFoundException)exception;
+ throw (ClassNotFoundException) exception;
} else if (exception instanceof IOException) {
- throw (IOException)exception;
+ throw (IOException) exception;
}
if (log.isDebugEnabled()) {
log.debug("Unreported exception in load() ", exception);
@@ -165,13 +159,11 @@ public class StandardManager extends ManagerBase {
/**
- * Load any currently active sessions that were previously unloaded
- * to the appropriate persistence mechanism, if any. If persistence is not
- * supported, this method returns without doing anything.
+ * Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if
+ * any. If persistence is not supported, this method returns without doing anything.
*
- * @exception ClassNotFoundException if a serialized class cannot be
- * found during the reload
- * @exception IOException if an input/output error occurs
+ * @exception ClassNotFoundException if a serialized class cannot be found during the reload
+ * @exception IOException if an input/output error occurs
*/
protected void doLoad() throws ClassNotFoundException, IOException {
if (log.isDebugEnabled()) {
@@ -207,8 +199,7 @@ public class StandardManager extends ManagerBase {
// Load the previously unloaded active sessions
synchronized (sessions) {
try (ObjectInputStream ois = new CustomObjectInputStream(bis, classLoader, logger,
- getSessionAttributeValueClassNamePattern(),
- getWarnOnSessionAttributeFilterFailure())) {
+ getSessionAttributeValueClassNamePattern(), getWarnOnSessionAttributeFilterFailure())) {
Integer count = (Integer) ois.readObject();
int n = count.intValue();
if (log.isDebugEnabled()) {
@@ -255,10 +246,10 @@ public class StandardManager extends ManagerBase {
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
AccessController.doPrivileged(new PrivilegedDoUnload());
- } catch (PrivilegedActionException ex){
+ } catch (PrivilegedActionException ex) {
Exception exception = ex.getException();
if (exception instanceof IOException) {
- throw (IOException)exception;
+ throw (IOException) exception;
}
if (log.isDebugEnabled()) {
log.debug("Unreported exception in unLoad()", exception);
@@ -271,9 +262,8 @@ public class StandardManager extends ManagerBase {
/**
- * Save any currently active sessions in the appropriate persistence
- * mechanism, if any. If persistence is not supported, this method
- * returns without doing anything.
+ * Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not
+ * supported, this method returns without doing anything.
*
* @exception IOException if an input/output error occurs
*/
@@ -340,11 +330,11 @@ public class StandardManager extends ManagerBase {
/**
- * Start this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
+ * Start this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
@@ -364,11 +354,11 @@ public class StandardManager extends ManagerBase {
/**
- * Stop this component and implement the requirements
- * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
+ * Stop this component and implement the requirements of
+ * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
@@ -411,8 +401,8 @@ public class StandardManager extends ManagerBase {
// ------------------------------------------------------ Protected Methods
/**
- * Return a File object representing the pathname to our
- * persistence file, if any.
+ * Return a File object representing the pathname to our persistence file, if any.
+ *
* @return the file
*/
protected File file() {
diff --git a/java/org/apache/catalina/session/StandardSession.java b/java/org/apache/catalina/session/StandardSession.java
index 616579736a..f6c529a20c 100644
--- a/java/org/apache/catalina/session/StandardSession.java
+++ b/java/org/apache/catalina/session/StandardSession.java
@@ -62,19 +62,16 @@ import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
/**
- * Standard implementation of the <b>Session</b> interface. This object is
- * serializable, so that it can be stored in persistent storage or transferred
- * to a different JVM for distributable session support.
+ * Standard implementation of the <b>Session</b> interface. This object is serializable, so that it can be stored in
+ * persistent storage or transferred to a different JVM for distributable session support.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: An instance of this class represents both the
- * internal (Session) and application level (HttpSession) view of the session.
- * However, because the class itself is not declared public, Java logic outside
- * of the <code>org.apache.catalina.session</code> package cannot cast an
- * HttpSession view of this instance back to a Session view.
+ * <b>IMPLEMENTATION NOTE</b>: An instance of this class represents both the internal (Session) and application level
+ * (HttpSession) view of the session. However, because the class itself is not declared public, Java logic outside of
+ * the <code>org.apache.catalina.session</code> package cannot cast an HttpSession view of this instance back to a
+ * Session view.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: If you add fields to this class, you must
- * make sure that you carry them over in the read/writeObject methods so
- * that this class is properly serialized.
+ * <b>IMPLEMENTATION NOTE</b>: If you add fields to this class, you must make sure that you carry them over in the
+ * read/writeObject methods so that this class is properly serialized.
*
* @author Craig R. McClanahan
* @author Sean Legassick
@@ -93,16 +90,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
static {
STRICT_SERVLET_COMPLIANCE = Globals.STRICT_SERVLET_COMPLIANCE;
- String activityCheck = System.getProperty(
- "org.apache.catalina.session.StandardSession.ACTIVITY_CHECK");
+ String activityCheck = System.getProperty("org.apache.catalina.session.StandardSession.ACTIVITY_CHECK");
if (activityCheck == null) {
ACTIVITY_CHECK = STRICT_SERVLET_COMPLIANCE;
} else {
ACTIVITY_CHECK = Boolean.parseBoolean(activityCheck);
}
- String lastAccessAtStart = System.getProperty(
- "org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START");
+ String lastAccessAtStart =
+ System.getProperty("org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START");
if (lastAccessAtStart == null) {
LAST_ACCESS_AT_START = STRICT_SERVLET_COMPLIANCE;
} else {
@@ -144,35 +140,32 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* The collection of user data attributes associated with this Session.
*/
- protected ConcurrentMap<String, Object> attributes = new ConcurrentHashMap<>();
+ protected ConcurrentMap<String,Object> attributes = new ConcurrentHashMap<>();
/**
- * The authentication type used to authenticate our cached Principal,
- * if any. NOTE: This value is not included in the serialized
- * version of this object.
+ * The authentication type used to authenticate our cached Principal, if any. NOTE: This value is not included in
+ * the serialized version of this object.
*/
protected transient String authType = null;
/**
- * The time this session was created, in milliseconds since midnight,
- * January 1, 1970 GMT.
+ * The time this session was created, in milliseconds since midnight, January 1, 1970 GMT.
*/
protected long creationTime = 0L;
/**
- * We are currently processing a session expiration, so bypass
- * certain IllegalStateException tests. NOTE: This value is not
- * included in the serialized version of this object.
+ * We are currently processing a session expiration, so bypass certain IllegalStateException tests. NOTE: This value
+ * is not included in the serialized version of this object.
*/
protected transient volatile boolean expiring = false;
/**
- * The facade associated with this session. NOTE: This value is not
- * included in the serialized version of this object.
+ * The facade associated with this session. NOTE: This value is not included in the serialized version of this
+ * object.
*/
protected transient StandardSessionFacade facade = null;
@@ -202,9 +195,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * The maximum time interval, in seconds, between client requests before
- * the servlet container may invalidate this session. A negative time
- * indicates that the session should never time out.
+ * The maximum time interval, in seconds, between client requests before the servlet container may invalidate this
+ * session. A negative time indicates that the session should never time out.
*/
protected volatile int maxInactiveInterval = -1;
@@ -222,17 +214,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Internal notes associated with this session by Catalina components
- * and event listeners. <b>IMPLEMENTATION NOTE:</b> This object is
- * <em>not</em> saved and restored across session serializations!
+ * Internal notes associated with this session by Catalina components and event listeners. <b>IMPLEMENTATION
+ * NOTE:</b> This object is <em>not</em> saved and restored across session serializations!
*/
- protected transient Map<String, Object> notes = new ConcurrentHashMap<>();
+ protected transient Map<String,Object> notes = new ConcurrentHashMap<>();
/**
- * The authenticated Principal associated with this session, if any.
- * <b>IMPLEMENTATION NOTE:</b> This object is <i>not</i> saved and
- * restored across session serializations!
+ * The authenticated Principal associated with this session, if any. <b>IMPLEMENTATION NOTE:</b> This object is
+ * <i>not</i> saved and restored across session serializations!
*/
protected transient Principal principal = null;
@@ -247,16 +237,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
* The HTTP session context associated with this session.
*/
@Deprecated
- protected static volatile
- javax.servlet.http.HttpSessionContext sessionContext = null;
+ protected static volatile javax.servlet.http.HttpSessionContext sessionContext = null;
/**
- * The property change support for this component. NOTE: This value
- * is not included in the serialized version of this object.
+ * The property change support for this component. NOTE: This value is not included in the serialized version of
+ * this object.
*/
- protected final transient PropertyChangeSupport support =
- new PropertyChangeSupport(this);
+ protected final transient PropertyChangeSupport support = new PropertyChangeSupport(this);
/**
@@ -275,8 +263,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the authentication type used to authenticate our cached
- * Principal, if any.
+ * Return the authentication type used to authenticate our cached Principal, if any.
*/
@Override
public String getAuthType() {
@@ -285,8 +272,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Set the authentication type used to authenticate our cached
- * Principal, if any.
+ * Set the authentication type used to authenticate our cached Principal, if any.
*
* @param authType The new cached authentication type
*/
@@ -299,8 +285,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Set the creation time for this session. This method is called by the
- * Manager when an existing Session instance is reused.
+ * Set the creation time for this session. This method is called by the Manager when an existing Session instance is
+ * reused.
*
* @param time The new creation time
*/
@@ -367,7 +353,6 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Inform the listeners about the new session.
- *
*/
public void tellNew() {
@@ -378,8 +363,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
Context context = manager.getContext();
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null && listeners.length > 0) {
- HttpSessionEvent event =
- new HttpSessionEvent(getSession());
+ HttpSessionEvent event = new HttpSessionEvent(getSession());
for (Object o : listeners) {
if (!(o instanceof HttpSessionListener)) {
continue;
@@ -396,7 +380,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
} catch (Exception e) {
// Ignore
}
- manager.getContext().getLogger().error (sm.getString("standardSession.sessionEvent"), t);
+ manager.getContext().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
}
}
}
@@ -406,42 +390,38 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Inform the listeners about the change session ID.
*
- * @param newId new session ID
- * @param oldId old session ID
- * @param notifySessionListeners Should any associated sessionListeners be
- * notified that session ID has been changed?
- * @param notifyContainerListeners Should any associated ContainerListeners
- * be notified that session ID has been changed?
+ * @param newId new session ID
+ * @param oldId old session ID
+ * @param notifySessionListeners Should any associated sessionListeners be notified that session ID has been
+ * changed?
+ * @param notifyContainerListeners Should any associated ContainerListeners be notified that session ID has been
+ * changed?
*/
@Override
- public void tellChangedSessionId(String newId, String oldId,
- boolean notifySessionListeners, boolean notifyContainerListeners) {
+ public void tellChangedSessionId(String newId, String oldId, boolean notifySessionListeners,
+ boolean notifyContainerListeners) {
Context context = manager.getContext();
- // notify ContainerListeners
+ // notify ContainerListeners
if (notifyContainerListeners) {
- context.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
- new String[] {oldId, newId});
+ context.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT, new String[] { oldId, newId });
}
// notify HttpSessionIdListener
if (notifySessionListeners) {
Object listeners[] = context.getApplicationEventListeners();
if (listeners != null && listeners.length > 0) {
- HttpSessionEvent event =
- new HttpSessionEvent(getSession());
+ HttpSessionEvent event = new HttpSessionEvent(getSession());
- for(Object listener : listeners) {
+ for (Object listener : listeners) {
if (!(listener instanceof HttpSessionIdListener)) {
continue;
}
- HttpSessionIdListener idListener =
- (HttpSessionIdListener)listener;
+ HttpSessionIdListener idListener = (HttpSessionIdListener) listener;
try {
idListener.sessionIdChanged(event, oldId);
} catch (Throwable t) {
- manager.getContext().getLogger().error
- (sm.getString("standardSession.sessionEvent"), t);
+ manager.getContext().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
}
}
}
@@ -450,18 +430,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the last time the client sent a request associated with this
- * session, as the number of milliseconds since midnight, January 1, 1970
- * GMT. Actions that your application takes, such as getting or setting
- * a value associated with the session, do not affect the access time.
- * This one gets updated whenever a request starts.
+ * Return the last time the client sent a request associated with this session, as the number of milliseconds since
+ * midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated
+ * with the session, do not affect the access time. This one gets updated whenever a request starts.
*/
@Override
public long getThisAccessedTime() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getThisAccessedTime.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getThisAccessedTime.ise"));
}
return this.thisAccessedTime;
@@ -469,6 +446,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Return the last client access time without invalidation check
+ *
* @see #getThisAccessedTime()
*/
@Override
@@ -477,18 +455,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
}
/**
- * Return the last time the client sent a request associated with this
- * session, as the number of milliseconds since midnight, January 1, 1970
- * GMT. Actions that your application takes, such as getting or setting
- * a value associated with the session, do not affect the access time.
- * This one gets updated whenever a request finishes.
+ * Return the last time the client sent a request associated with this session, as the number of milliseconds since
+ * midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated
+ * with the session, do not affect the access time. This one gets updated whenever a request finishes.
*/
@Override
public long getLastAccessedTime() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getLastAccessedTime.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getLastAccessedTime.ise"));
}
return this.lastAccessedTime;
@@ -496,6 +471,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Return the last client access time without invalidation check
+ *
* @see #getLastAccessedTime()
*/
@Override
@@ -510,8 +486,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
public long getIdleTime() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getIdleTime.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getIdleTime.ise"));
}
return getIdleTimeInternal();
@@ -519,6 +494,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Return the idle time from last client access time without invalidation check
+ *
* @see #getIdleTime()
*/
@Override
@@ -554,9 +530,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the maximum time interval, in seconds, between client requests
- * before the servlet container will invalidate the session. A negative
- * time indicates that the session should never time out.
+ * Return the maximum time interval, in seconds, between client requests before the servlet container will
+ * invalidate the session. A negative time indicates that the session should never time out.
*/
@Override
public int getMaxInactiveInterval() {
@@ -565,9 +540,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Set the maximum time interval, in seconds, between client requests
- * before the servlet container will invalidate the session. A zero or
- * negative time indicates that the session should never time out.
+ * Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate
+ * the session. A zero or negative time indicates that the session should never time out.
*
* @param interval The new maximum interval
*/
@@ -589,11 +563,10 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the authenticated Principal that is associated with this Session.
- * This provides an <code>Authenticator</code> with a means to cache a
- * previously authenticated Principal, and avoid potentially expensive
- * <code>Realm.authenticate()</code> calls on every request. If there
- * is no current associated Principal, return <code>null</code>.
+ * Return the authenticated Principal that is associated with this Session. This provides an
+ * <code>Authenticator</code> with a means to cache a previously authenticated Principal, and avoid potentially
+ * expensive <code>Realm.authenticate()</code> calls on every request. If there is no current associated Principal,
+ * return <code>null</code>.
*/
@Override
public Principal getPrincipal() {
@@ -602,9 +575,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Set the authenticated Principal that is associated with this Session.
- * This provides an <code>Authenticator</code> with a means to cache a
- * previously authenticated Principal, and avoid potentially expensive
+ * Set the authenticated Principal that is associated with this Session. This provides an <code>Authenticator</code>
+ * with a means to cache a previously authenticated Principal, and avoid potentially expensive
* <code>Realm.authenticate()</code> calls on every request.
*
* @param principal The new Principal, or <code>null</code> if none
@@ -620,8 +592,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the <code>HttpSession</code> for which this object
- * is the facade.
+ * Return the <code>HttpSession</code> for which this object is the facade.
*/
@Override
public HttpSession getSession() {
@@ -680,9 +651,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Update the accessed time information for this session. This method
- * should be called by the context when a request comes in for a particular
- * session, even if the application does not reference it.
+ * Update the accessed time information for this session. This method should be called by the context when a request
+ * comes in for a particular session, even if the application does not reference it.
*/
@Override
public void access() {
@@ -705,8 +675,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
isNew = false;
/*
- * The servlet spec mandates to ignore request handling time
- * in lastAccessedTime.
+ * The servlet spec mandates to ignore request handling time in lastAccessedTime.
*/
if (LAST_ACCESS_AT_START) {
this.lastAccessedTime = this.thisAccessedTime;
@@ -735,8 +704,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Perform the internal processing required to invalidate this session,
- * without triggering an exception if the session has already expired.
+ * Perform the internal processing required to invalidate this session, without triggering an exception if the
+ * session has already expired.
*/
@Override
public void expire() {
@@ -747,11 +716,10 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Perform the internal processing required to invalidate this session,
- * without triggering an exception if the session has already expired.
+ * Perform the internal processing required to invalidate this session, without triggering an exception if the
+ * session has already expired.
*
- * @param notify Should we notify listeners about the demise of
- * this session?
+ * @param notify Should we notify listeners about the demise of this session?
*/
public void expire(boolean notify) {
@@ -791,31 +759,25 @@ public class StandardSession implements HttpSession, Session, Serializable {
oldContextClassLoader = context.bind(Globals.IS_SECURITY_ENABLED, null);
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null && listeners.length > 0) {
- HttpSessionEvent event =
- new HttpSessionEvent(getSession());
+ HttpSessionEvent event = new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
int j = (listeners.length - 1) - i;
if (!(listeners[j] instanceof HttpSessionListener)) {
continue;
}
- HttpSessionListener listener =
- (HttpSessionListener) listeners[j];
+ HttpSessionListener listener = (HttpSessionListener) listeners[j];
try {
- context.fireContainerEvent("beforeSessionDestroyed",
- listener);
+ context.fireContainerEvent("beforeSessionDestroyed", listener);
listener.sessionDestroyed(event);
- context.fireContainerEvent("afterSessionDestroyed",
- listener);
+ context.fireContainerEvent("afterSessionDestroyed", listener);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
- context.fireContainerEvent(
- "afterSessionDestroyed", listener);
+ context.fireContainerEvent("afterSessionDestroyed", listener);
} catch (Exception e) {
// Ignore
}
- manager.getContext().getLogger().error
- (sm.getString("standardSession.sessionEvent"), t);
+ manager.getContext().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
}
}
}
@@ -842,9 +804,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
try {
gp.logout();
} catch (Exception e) {
- manager.getContext().getLogger().error(
- sm.getString("standardSession.logoutfail"),
- e);
+ manager.getContext().getLogger().error(sm.getString("standardSession.logoutfail"), e);
}
}
@@ -869,8 +829,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Perform the internal processing required to passivate
- * this session.
+ * Perform the internal processing required to passivate this session.
*/
public void passivate() {
@@ -899,8 +858,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Perform internal processing required to activate this
- * session.
+ * Perform internal processing required to activate this session.
*/
public void activate() {
@@ -933,8 +891,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the object bound with the specified name to the internal notes
- * for this session, or <code>null</code> if no such binding exists.
+ * Return the object bound with the specified name to the internal notes for this session, or <code>null</code> if
+ * no such binding exists.
*
* @param name Name of the note to be returned
*/
@@ -945,8 +903,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return an Iterator containing the String names of all notes bindings
- * that exist for this session.
+ * Return an Iterator containing the String names of all notes bindings that exist for this session.
*/
@Override
public Iterator<String> getNoteNames() {
@@ -955,8 +912,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Release all object references, and initialize instance variables, in
- * preparation for reuse of this object.
+ * Release all object references, and initialize instance variables, in preparation for reuse of this object.
*/
@Override
public void recycle() {
@@ -979,8 +935,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Remove any object bound to the specified name in the internal notes
- * for this session.
+ * Remove any object bound to the specified name in the internal notes for this session.
*
* @param name Name of the note to be removed
*/
@@ -1004,10 +959,10 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Bind an object to a specified name in the internal notes associated
- * with this session, replacing any existing binding for this name.
+ * Bind an object to a specified name in the internal notes associated with this session, replacing any existing
+ * binding for this name.
*
- * @param name Name to which the object should be bound
+ * @param name Name to which the object should be bound
* @param value Object to be bound to the specified name
*/
@Override
@@ -1035,17 +990,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Read a serialized version of the contents of this session object from
- * the specified object input stream, without requiring that the
- * StandardSession itself have been serialized.
+ * Read a serialized version of the contents of this session object from the specified object input stream, without
+ * requiring that the StandardSession itself have been serialized.
*
* @param stream The object input stream to read from
*
* @exception ClassNotFoundException if an unknown class is specified
- * @exception IOException if an input/output error occurs
+ * @exception IOException if an input/output error occurs
*/
- public void readObjectData(ObjectInputStream stream)
- throws ClassNotFoundException, IOException {
+ public void readObjectData(ObjectInputStream stream) throws ClassNotFoundException, IOException {
doReadObject(stream);
@@ -1053,16 +1006,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Write a serialized version of the contents of this session object to
- * the specified object output stream, without requiring that the
- * StandardSession itself have been serialized.
+ * Write a serialized version of the contents of this session object to the specified object output stream, without
+ * requiring that the StandardSession itself have been serialized.
*
* @param stream The object output stream to write to
*
* @exception IOException if an input/output error occurs
*/
- public void writeObjectData(ObjectOutputStream stream)
- throws IOException {
+ public void writeObjectData(ObjectOutputStream stream) throws IOException {
doWriteObject(stream);
@@ -1073,17 +1024,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the time when this session was created, in milliseconds since
- * midnight, January 1, 1970 GMT.
+ * Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public long getCreationTime() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getCreationTime.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getCreationTime.ise"));
}
return this.creationTime;
@@ -1091,8 +1039,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the time when this session was created, in milliseconds since
- * midnight, January 1, 1970 GMT, bypassing the session validation checks.
+ * Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT, bypassing the
+ * session validation checks.
*/
@Override
public long getCreationTimeInternal() {
@@ -1116,9 +1064,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Return the session context with which this session is associated.
*
- * @deprecated As of Version 2.1, this method is deprecated and has no
- * replacement. It will be removed in a future version of the
- * Java Servlet API.
+ * @deprecated As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future
+ * version of the Java Servlet API.
*/
@Override
@Deprecated
@@ -1133,19 +1080,17 @@ public class StandardSession implements HttpSession, Session, Serializable {
// ----------------------------------------------HttpSession Public Methods
/**
- * Return the object bound with the specified name in this session, or
- * <code>null</code> if no object is bound with that name.
+ * Return the object bound with the specified name in this session, or <code>null</code> if no object is bound with
+ * that name.
*
* @param name Name of the attribute to be returned
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public Object getAttribute(String name) {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getAttribute.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
@@ -1157,18 +1102,16 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return an <code>Enumeration</code> of <code>String</code> objects
- * containing the names of the objects bound to this session.
+ * Return an <code>Enumeration</code> of <code>String</code> objects containing the names of the objects bound to
+ * this session.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public Enumeration<String> getAttributeNames() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getAttributeNames.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> names = new HashSet<>(attributes.keySet());
@@ -1177,16 +1120,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the object bound with the specified name in this session, or
- * <code>null</code> if no object is bound with that name.
+ * Return the object bound with the specified name in this session, or <code>null</code> if no object is bound with
+ * that name.
*
* @param name Name of the value to be returned
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*
- * @deprecated As of Version 2.2, this method is replaced by
- * <code>getAttribute()</code>
+ * @deprecated As of Version 2.2, this method is replaced by <code>getAttribute()</code>
*/
@Override
@Deprecated
@@ -1198,21 +1139,18 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return the set of names of objects bound to this session. If there
- * are no such objects, a zero-length array is returned.
+ * Return the set of names of objects bound to this session. If there are no such objects, a zero-length array is
+ * returned.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*
- * @deprecated As of Version 2.2, this method is replaced by
- * <code>getAttributeNames()</code>
+ * @deprecated As of Version 2.2, this method is replaced by <code>getAttributeNames()</code>
*/
@Override
@Deprecated
public String[] getValueNames() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.getValueNames.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.getValueNames.ise"));
}
return keys();
@@ -1222,15 +1160,13 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Invalidates this session and unbinds any objects bound to it.
*
- * @exception IllegalStateException if this method is called on
- * an invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public void invalidate() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.invalidate.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.invalidate.ise"));
}
// Cause this session to expire
@@ -1240,20 +1176,16 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Return <code>true</code> if the client does not yet know about the
- * session, or if the client chooses not to join the session. For
- * example, if the server used only cookie-based sessions, and the client
- * has disabled the use of cookies, then a session would be new on each
- * request.
+ * Return <code>true</code> if the client does not yet know about the session, or if the client chooses not to join
+ * the session. For example, if the server used only cookie-based sessions, and the client has disabled the use of
+ * cookies, then a session would be new on each request.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public boolean isNew() {
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.isNew.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.isNew.ise"));
}
return this.isNew;
@@ -1261,22 +1193,18 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Bind an object to this session, using the specified name. If an object
- * of the same name is already bound to this session, the object is
- * replaced.
+ * Bind an object to this session, using the specified name. If an object of the same name is already bound to this
+ * session, the object is replaced.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueBound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueBound()</code> on the object.
*
- * @param name Name to which the object is bound, cannot be null
+ * @param name Name to which the object is bound, cannot be null
* @param value Object to be bound, cannot be null
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*
- * @deprecated As of Version 2.2, this method is replaced by
- * <code>setAttribute()</code>
+ * @deprecated As of Version 2.2, this method is replaced by <code>setAttribute()</code>
*/
@Override
@Deprecated
@@ -1288,18 +1216,15 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Remove the object bound with the specified name from this session. If
- * the session does not have an object bound with this name, this method
- * does nothing.
+ * Remove the object bound with the specified name from this session. If the session does not have an object bound
+ * with this name, this method does nothing.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueUnbound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueUnbound()</code> on the object.
*
* @param name Name of the object to remove from this session.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public void removeAttribute(String name) {
@@ -1310,27 +1235,22 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Remove the object bound with the specified name from this session. If
- * the session does not have an object bound with this name, this method
- * does nothing.
+ * Remove the object bound with the specified name from this session. If the session does not have an object bound
+ * with this name, this method does nothing.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueUnbound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueUnbound()</code> on the object.
*
- * @param name Name of the object to remove from this session.
- * @param notify Should we notify interested listeners that this
- * attribute is being removed?
+ * @param name Name of the object to remove from this session.
+ * @param notify Should we notify interested listeners that this attribute is being removed?
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
public void removeAttribute(String name, boolean notify) {
// Validate our current state
if (!isValidInternal()) {
- throw new IllegalStateException
- (sm.getString("standardSession.removeAttribute.ise"));
+ throw new IllegalStateException(sm.getString("standardSession.removeAttribute.ise"));
}
removeAttributeInternal(name, notify);
@@ -1339,21 +1259,17 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Remove the object bound with the specified name from this session. If
- * the session does not have an object bound with this name, this method
- * does nothing.
+ * Remove the object bound with the specified name from this session. If the session does not have an object bound
+ * with this name, this method does nothing.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueUnbound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueUnbound()</code> on the object.
*
* @param name Name of the object to remove from this session.
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an invalidated session
*
- * @deprecated As of Version 2.2, this method is replaced by
- * <code>removeAttribute()</code>
+ * @deprecated As of Version 2.2, this method is replaced by <code>removeAttribute()</code>
*/
@Override
@Deprecated
@@ -1365,51 +1281,45 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Bind an object to this session, using the specified name. If an object
- * of the same name is already bound to this session, the object is
- * replaced.
+ * Bind an object to this session, using the specified name. If an object of the same name is already bound to this
+ * session, the object is replaced.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueBound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueBound()</code> on the object.
*
- * @param name Name to which the object is bound, cannot be null
+ * @param name Name to which the object is bound, cannot be null
* @param value Object to be bound, cannot be null
*
- * @exception IllegalArgumentException if an attempt is made to add a
- * non-serializable object in an environment marked distributable.
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalArgumentException if an attempt is made to add a non-serializable object in an environment
+ * marked distributable.
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
@Override
public void setAttribute(String name, Object value) {
- setAttribute(name,value,true);
+ setAttribute(name, value, true);
}
/**
- * Bind an object to this session, using the specified name. If an object
- * of the same name is already bound to this session, the object is
- * replaced.
+ * Bind an object to this session, using the specified name. If an object of the same name is already bound to this
+ * session, the object is replaced.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueBound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueBound()</code> on the object.
*
- * @param name Name to which the object is bound, cannot be null
- * @param value Object to be bound, cannot be null
+ * @param name Name to which the object is bound, cannot be null
+ * @param value Object to be bound, cannot be null
* @param notify whether to notify session listeners
- * @exception IllegalArgumentException if an attempt is made to add a
- * non-serializable object in an environment marked distributable.
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ *
+ * @exception IllegalArgumentException if an attempt is made to add a non-serializable object in an environment
+ * marked distributable.
+ * @exception IllegalStateException if this method is called on an invalidated session
*/
public void setAttribute(String name, Object value, boolean notify) {
// Name cannot be null
if (name == null) {
- throw new IllegalArgumentException(
- sm.getString("standardSession.setAttribute.namenull"));
+ throw new IllegalArgumentException(sm.getString("standardSession.setAttribute.namenull"));
}
// Null value is the same as removeAttribute()
@@ -1420,8 +1330,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
// Validate our current state
if (!isValidInternal()) {
- throw new IllegalStateException(
- sm.getString("standardSession.setAttribute.ise", getIdInternal()));
+ throw new IllegalStateException(sm.getString("standardSession.setAttribute.ise", getIdInternal()));
}
Context context = manager.getContext();
@@ -1441,9 +1350,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
event = new HttpSessionBindingEvent(getSession(), name, value);
try {
((HttpSessionBindingListener) value).valueBound(event);
- } catch (Throwable t){
- manager.getContext().getLogger().error(
- sm.getString("standardSession.bindingEvent"), t);
+ } catch (Throwable t) {
+ manager.getContext().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
}
}
}
@@ -1457,12 +1365,11 @@ public class StandardSession implements HttpSession, Session, Serializable {
// unless configured to do so
if (unbound != value || manager.getNotifyBindingListenerOnUnchangedValue()) {
try {
- ((HttpSessionBindingListener) unbound).valueUnbound
- (new HttpSessionBindingEvent(getSession(), name));
+ ((HttpSessionBindingListener) unbound)
+ .valueUnbound(new HttpSessionBindingEvent(getSession(), name));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
- manager.getContext().getLogger().error
- (sm.getString("standardSession.bindingEvent"), t);
+ manager.getContext().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
}
}
}
@@ -1503,8 +1410,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
ExceptionUtils.handleThrowable(t);
try {
if (unbound != null) {
- if (unbound != value ||
- manager.getNotifyAttributeListenerOnUnchangedValue()) {
+ if (unbound != value || manager.getNotifyAttributeListenerOnUnchangedValue()) {
context.fireContainerEvent("afterSessionAttributeReplaced", listener);
}
} else {
@@ -1513,8 +1419,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
} catch (Exception e) {
// Ignore
}
- manager.getContext().getLogger().error(
- sm.getString("standardSession.attributeEvent"), t);
+ manager.getContext().getLogger().error(sm.getString("standardSession.attributeEvent"), t);
}
}
}
@@ -1523,8 +1428,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
// ------------------------------------------ HttpSession Protected Methods
/**
- * @return the <code>isValid</code> flag for this session without any expiration
- * check.
+ * @return the <code>isValid</code> flag for this session without any expiration check.
*/
protected boolean isValidInternal() {
return this.isValid;
@@ -1533,9 +1437,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* {@inheritDoc}
* <p>
- * This implementation simply checks the value for serializability.
- * Sub-classes might use other distribution technology not based on
- * serialization and can override this check.
+ * This implementation simply checks the value for serializability. Sub-classes might use other distribution
+ * technology not based on serialization and can override this check.
*/
@Override
public boolean isAttributeDistributable(String name, Object value) {
@@ -1544,46 +1447,41 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Read a serialized version of this session object from the specified
- * object input stream.
+ * Read a serialized version of this session object from the specified object input stream.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: The reference to the owning Manager
- * is not restored by this method, and must be set explicitly.
+ * <b>IMPLEMENTATION NOTE</b>: The reference to the owning Manager is not restored by this method, and must be set
+ * explicitly.
*
* @param stream The input stream to read from
*
* @exception ClassNotFoundException if an unknown class is specified
- * @exception IOException if an input/output error occurs
+ * @exception IOException if an input/output error occurs
*/
- protected void doReadObject(ObjectInputStream stream)
- throws ClassNotFoundException, IOException {
+ protected void doReadObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
// Deserialize the scalar instance variables (except Manager)
- authType = null; // Transient (may be set later)
+ authType = null; // Transient (may be set later)
creationTime = ((Long) stream.readObject()).longValue();
lastAccessedTime = ((Long) stream.readObject()).longValue();
maxInactiveInterval = ((Integer) stream.readObject()).intValue();
isNew = ((Boolean) stream.readObject()).booleanValue();
isValid = ((Boolean) stream.readObject()).booleanValue();
thisAccessedTime = ((Long) stream.readObject()).longValue();
- principal = null; // Transient (may be set later)
- // setId((String) stream.readObject());
+ principal = null; // Transient (may be set later)
+ // setId((String) stream.readObject());
id = (String) stream.readObject();
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug
- ("readObject() loading session " + id);
+ manager.getContext().getLogger().debug("readObject() loading session " + id);
}
if (notes == null) {
notes = new ConcurrentHashMap<>();
}
/*
- * The next object read could either be the number of attributes
- * (Integer) or if authentication information is persisted then:
- * - authType (String) - always present
- * - Principal object - always present
- * - expected session ID - present if persistAuthenticationNotes == true
- * - saved request - present if persistAuthenticationNotes == true
+ * The next object read could either be the number of attributes (Integer) or if authentication information is
+ * persisted then: - authType (String) - always present - Principal object - always present - expected session
+ * ID - present if persistAuthenticationNotes == true - saved request - present if persistAuthenticationNotes ==
+ * true
*
* Note: Some, all or none of the above objects may be null
*/
@@ -1647,8 +1545,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
throw wae;
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(" loading attribute '" + name +
- "' with value '" + value + "'");
+ manager.getContext().getLogger().debug(" loading attribute '" + name + "' with value '" + value + "'");
}
// Handle the case where the filter configuration was changed while
// the web application was stopped.
@@ -1656,7 +1553,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
continue;
}
// ConcurrentHashMap does not allow null keys or values
- if(null != value) {
+ if (null != value) {
attributes.put(name, value);
}
}
@@ -1669,19 +1566,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Write a serialized version of this session object to the specified
- * object output stream.
+ * Write a serialized version of this session object to the specified object output stream.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: The owning Manager will not be stored
- * in the serialized representation of this Session. After calling
- * <code>readObject()</code>, you must set the associated Manager
- * explicitly.
+ * <b>IMPLEMENTATION NOTE</b>: The owning Manager will not be stored in the serialized representation of this
+ * Session. After calling <code>readObject()</code>, you must set the associated Manager explicitly.
* <p>
- * <b>IMPLEMENTATION NOTE</b>: Any attribute that is not Serializable
- * will be unbound from the session, with appropriate actions if it
- * implements HttpSessionBindingListener. If you do not want any such
- * attributes, be sure the <code>distributable</code> property of the
- * associated Manager is set to <code>true</code>.
+ * <b>IMPLEMENTATION NOTE</b>: Any attribute that is not Serializable will be unbound from the session, with
+ * appropriate actions if it implements HttpSessionBindingListener. If you do not want any such attributes, be sure
+ * the <code>distributable</code> property of the associated Manager is set to <code>true</code>.
*
* @param stream The output stream to write to
*
@@ -1699,8 +1591,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
stream.writeObject(Long.valueOf(thisAccessedTime));
stream.writeObject(id);
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug
- ("writeObject() storing session " + id);
+ manager.getContext().getLogger().debug("writeObject() storing session " + id);
}
// Gather authentication information (if configured)
@@ -1713,8 +1604,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
sessionPrincipal = getPrincipal();
if (!(sessionPrincipal instanceof Serializable)) {
sessionPrincipal = null;
- manager.getContext().getLogger().warn(
- sm.getString("standardSession.principalNotSerializable", id));
+ manager.getContext().getLogger().warn(sm.getString("standardSession.principalNotSerializable", id));
}
expectedSessionId = (String) notes.get(org.apache.catalina.authenticator.Constants.SESSION_ID_NOTE);
savedRequest = (SavedRequest) notes.get(org.apache.catalina.authenticator.Constants.FORM_REQUEST_NOTE);
@@ -1725,8 +1615,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
try {
stream.writeObject(sessionPrincipal);
} catch (NotSerializableException e) {
- manager.getContext().getLogger().warn(
- sm.getString("standardSession.principalNotSerializable", id), e);
+ manager.getContext().getLogger().warn(sm.getString("standardSession.principalNotSerializable", id), e);
}
if (manager instanceof ManagerBase && ((ManagerBase) manager).getPersistAuthenticationNotes()) {
// Write the notes associated with authentication. Without these,
@@ -1764,8 +1653,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
" storing attribute '" + saveNames.get(i) + "' with value '" + saveValues.get(i) + "'");
}
} catch (NotSerializableException e) {
- manager.getContext().getLogger().warn(
- sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
+ manager.getContext().getLogger()
+ .warn(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
}
}
@@ -1774,8 +1663,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
* Return whether authentication information shall be persisted or not.
*
- * @return {@code true}, if authentication information shall be persisted;
- * {@code false} otherwise
+ * @return {@code true}, if authentication information shall be persisted; {@code false} otherwise
*/
private boolean getPersistAuthentication() {
if (manager instanceof ManagerBase) {
@@ -1785,22 +1673,18 @@ public class StandardSession implements HttpSession, Session, Serializable {
}
/**
- * Should the given session attribute be excluded? This implementation
- * checks:
+ * Should the given session attribute be excluded? This implementation checks:
* <ul>
* <li>{@link Constants#excludedAttributeNames}</li>
* <li>{@link Manager#willAttributeDistribute(String, Object)}</li>
* </ul>
- * Note: This method deliberately does not check
- * {@link #isAttributeDistributable(String, Object)} which is kept
- * separate to support the checks required in
- * {@link #setAttribute(String, Object, boolean)}
+ * Note: This method deliberately does not check {@link #isAttributeDistributable(String, Object)} which is kept
+ * separate to support the checks required in {@link #setAttribute(String, Object, boolean)}
*
* @param name The attribute name
* @param value The attribute value
*
- * @return {@code true} if the attribute should be excluded from
- * distribution, otherwise {@code false}
+ * @return {@code true} if the attribute should be excluded from distribution, otherwise {@code false}
*/
protected boolean exclude(String name, Object value) {
if (Constants.excludedAttributeNames.contains(name)) {
@@ -1823,9 +1707,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
// ------------------------------------------------------ Protected Methods
/**
- * Notify all session event listeners that a particular event has
- * occurred for this Session. The default implementation performs
- * this notification synchronously using the calling thread.
+ * Notify all session event listeners that a particular event has occurred for this Session. The default
+ * implementation performs this notification synchronously using the calling thread.
*
* @param type Event type
* @param data Event data
@@ -1848,9 +1731,8 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * @return the names of all currently defined session attributes
- * as an array of Strings. If there are no defined attributes, a
- * zero-length array is returned.
+ * @return the names of all currently defined session attributes as an array of Strings. If there are no defined
+ * attributes, a zero-length array is returned.
*/
protected String[] keys() {
@@ -1860,17 +1742,14 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * Remove the object bound with the specified name from this session. If
- * the session does not have an object bound with this name, this method
- * does nothing.
+ * Remove the object bound with the specified name from this session. If the session does not have an object bound
+ * with this name, this method does nothing.
* <p>
- * After this method executes, and if the object implements
- * <code>HttpSessionBindingListener</code>, the container calls
- * <code>valueUnbound()</code> on the object.
+ * After this method executes, and if the object implements <code>HttpSessionBindingListener</code>, the container
+ * calls <code>valueUnbound()</code> on the object.
*
- * @param name Name of the object to remove from this session.
- * @param notify Should we notify interested listeners that this
- * attribute is being removed?
+ * @param name Name of the object to remove from this session.
+ * @param notify Should we notify interested listeners that this attribute is being removed?
*/
protected void removeAttributeInternal(String name, boolean notify) {
@@ -1925,8 +1804,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
}
- private static class PrivilegedNewSessionFacade implements
- PrivilegedAction<StandardSessionFacade> {
+ private static class PrivilegedNewSessionFacade implements PrivilegedAction<StandardSessionFacade> {
private final HttpSession session;
@@ -1935,7 +1813,7 @@ public class StandardSession implements HttpSession, Session, Serializable {
}
@Override
- public StandardSessionFacade run(){
+ public StandardSessionFacade run() {
return new StandardSessionFacade(session);
}
}
@@ -1946,29 +1824,25 @@ public class StandardSession implements HttpSession, Session, Serializable {
/**
- * This class is a dummy implementation of the <code>HttpSessionContext</code>
- * interface, to conform to the requirement that such an object be returned
- * when <code>HttpSession.getSessionContext()</code> is called.
+ * This class is a dummy implementation of the <code>HttpSessionContext</code> interface, to conform to the requirement
+ * that such an object be returned when <code>HttpSession.getSessionContext()</code> is called.
*
* @author Craig R. McClanahan
*
- * @deprecated As of Java Servlet API 2.1 with no replacement. The
- * interface will be removed in a future version of this API.
+ * @deprecated As of Java Servlet API 2.1 with no replacement. The interface will be removed in a future version of this
+ * API.
*/
@Deprecated
-final class StandardSessionContext
- implements javax.servlet.http.HttpSessionContext {
+final class StandardSessionContext implements javax.servlet.http.HttpSessionContext {
private static final List<String> emptyString = Collections.emptyList();
/**
- * Return the session identifiers of all sessions defined
- * within this context.
+ * Return the session identifiers of all sessions defined within this context.
*
- * @deprecated As of Java Servlet API 2.1 with no replacement.
- * This method must return an empty <code>Enumeration</code>
- * and will be removed in a future version of the API.
+ * @deprecated As of Java Servlet API 2.1 with no replacement. This method must return an empty
+ * <code>Enumeration</code> and will be removed in a future version of the API.
*/
@Override
@Deprecated
@@ -1978,14 +1852,12 @@ final class StandardSessionContext
/**
- * Return the <code>HttpSession</code> associated with the
- * specified session identifier.
+ * Return the <code>HttpSession</code> associated with the specified session identifier.
*
* @param id Session identifier for which to look up a session
*
- * @deprecated As of Java Servlet API 2.1 with no replacement.
- * This method must return null and will be removed in a
- * future version of the API.
+ * @deprecated As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a
+ * future version of the API.
*/
@Override
@Deprecated
diff --git a/java/org/apache/catalina/session/StandardSessionFacade.java b/java/org/apache/catalina/session/StandardSessionFacade.java
index 6efa146d22..efa7623693 100644
--- a/java/org/apache/catalina/session/StandardSessionFacade.java
+++ b/java/org/apache/catalina/session/StandardSessionFacade.java
@@ -87,8 +87,7 @@ public class StandardSessionFacade implements HttpSession {
/**
- * @deprecated As of Version 2.1, this method is deprecated and has no
- * replacement.
+ * @deprecated As of Version 2.1, this method is deprecated and has no replacement.
*/
@Override
@Deprecated
@@ -104,8 +103,7 @@ public class StandardSessionFacade implements HttpSession {
/**
- * @deprecated As of Version 2.2, this method is replaced by
- * {@link #getAttribute}.
+ * @deprecated As of Version 2.2, this method is replaced by {@link #getAttribute}.
*/
@Override
@Deprecated
@@ -121,8 +119,7 @@ public class StandardSessionFacade implements HttpSession {
/**
- * @deprecated As of Version 2.2, this method is replaced by
- * {@link #getAttributeNames}
+ * @deprecated As of Version 2.2, this method is replaced by {@link #getAttributeNames}
*/
@Override
@Deprecated
@@ -138,8 +135,7 @@ public class StandardSessionFacade implements HttpSession {
/**
- * @deprecated As of Version 2.2, this method is replaced by
- * {@link #setAttribute}
+ * @deprecated As of Version 2.2, this method is replaced by {@link #setAttribute}
*/
@Override
@Deprecated
@@ -155,8 +151,7 @@ public class StandardSessionFacade implements HttpSession {
/**
- * @deprecated As of Version 2.2, this method is replaced by
- * {@link #removeAttribute}
+ * @deprecated As of Version 2.2, this method is replaced by {@link #removeAttribute}
*/
@Override
@Deprecated
diff --git a/java/org/apache/catalina/session/StoreBase.java b/java/org/apache/catalina/session/StoreBase.java
index 3438d013b8..222864a6d6 100644
--- a/java/org/apache/catalina/session/StoreBase.java
+++ b/java/org/apache/catalina/session/StoreBase.java
@@ -33,8 +33,8 @@ import org.apache.catalina.util.ToStringUtil;
import org.apache.tomcat.util.res.StringManager;
/**
- * Abstract implementation of the {@link Store} interface to
- * support most of the functionality required by a {@link Store}.
+ * Abstract implementation of the {@link Store} interface to support most of the functionality required by a
+ * {@link Store}.
*
* @author Bip Thelin
*/
@@ -117,27 +117,24 @@ public abstract class StoreBase extends LifecycleBase implements Store {
}
/**
- * Get only those keys of sessions, that are saved in the Store and are to
- * be expired.
+ * Get only those keys of sessions, that are saved in the Store and are to be expired.
*
* @return list of session keys, that are to be expired
- * @throws IOException
- * if an input-/output error occurred
+ *
+ * @throws IOException if an input-/output error occurred
*/
public String[] expiredKeys() throws IOException {
return keys();
}
/**
- * Called by our background reaper thread to check if Sessions
- * saved in our store are subject of being expired. If so expire
- * the Session and remove it from the Store.
- *
+ * Called by our background reaper thread to check if Sessions saved in our store are subject of being expired. If
+ * so expire the Session and remove it from the Store.
*/
public void processExpires() {
String[] keys = null;
- if(!getState().isAvailable()) {
+ if (!getState().isAvailable()) {
return;
}
@@ -148,7 +145,8 @@ public abstract class StoreBase extends LifecycleBase implements Store {
return;
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(getStoreName()+ ": processExpires check number of " + keys.length + " sessions" );
+ manager.getContext().getLogger()
+ .debug(getStoreName() + ": processExpires check number of " + keys.length + " sessions");
}
long timeNow = System.currentTimeMillis();
@@ -164,7 +162,8 @@ public abstract class StoreBase extends LifecycleBase implements Store {
continue;
}
if (manager.getContext().getLogger().isDebugEnabled()) {
- manager.getContext().getLogger().debug(getStoreName() + ": processExpires expire store session " + key);
+ manager.getContext().getLogger()
+ .debug(getStoreName() + ": processExpires expire store session " + key);
}
boolean isLoaded = false;
if (manager instanceof PersistentManagerBase) {
@@ -201,15 +200,12 @@ public abstract class StoreBase extends LifecycleBase implements Store {
// --------------------------------------------------------- Protected Methods
/**
- * Create the object input stream to use to read a session from the store.
- * Sub-classes <b>must</b> have set the thread context class loader before
- * calling this method.
+ * Create the object input stream to use to read a session from the store. Sub-classes <b>must</b> have set the
+ * thread context class loader before calling this method.
*
- * @param is The input stream provided by the sub-class that will provide
- * the data for a session
+ * @param is The input stream provided by the sub-class that will provide the data for a session
*
- * @return An appropriately configured ObjectInputStream from which the
- * session can be read.
+ * @return An appropriately configured ObjectInputStream from which the session can be read.
*
* @throws IOException if a problem occurs creating the ObjectInputStream
*/
@@ -239,11 +235,10 @@ public abstract class StoreBase extends LifecycleBase implements Store {
/**
- * Start this component and implement the requirements
- * of {@link LifecycleBase#startInternal()}.
+ * Start this component and implement the requirements of {@link LifecycleBase#startInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
@@ -253,11 +248,10 @@ public abstract class StoreBase extends LifecycleBase implements Store {
/**
- * Stop this component and implement the requirements
- * of {@link LifecycleBase#stopInternal()}.
+ * Stop this component and implement the requirements of {@link LifecycleBase#stopInternal()}.
*
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
+ * @exception LifecycleException if this component detects a fatal error that prevents this component from being
+ * used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
diff --git a/java/org/apache/catalina/session/TooManyActiveSessionsException.java b/java/org/apache/catalina/session/TooManyActiveSessionsException.java
index 33d8e15aea..25e23fd234 100644
--- a/java/org/apache/catalina/session/TooManyActiveSessionsException.java
+++ b/java/org/apache/catalina/session/TooManyActiveSessionsException.java
@@ -17,8 +17,8 @@
package org.apache.catalina.session;
/**
- * An exception that indicates the maximum number of active sessions has been
- * reached and the server is refusing to create any new sessions.
+ * An exception that indicates the maximum number of active sessions has been reached and the server is refusing to
+ * create any new sessions.
*/
public class TooManyActiveSessionsException extends IllegalStateException {
@@ -32,9 +32,8 @@ public class TooManyActiveSessionsException extends IllegalStateException {
/**
* Creates a new TooManyActiveSessionsException.
*
- * @param message A description for the exception.
- * @param maxActive The maximum number of active sessions allowed by the
- * session manager.
+ * @param message A description for the exception.
+ * @param maxActive The maximum number of active sessions allowed by the session manager.
*/
public TooManyActiveSessionsException(String message, int maxActive) {
super(message);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org