From 70a665d3e767f7bbd8e91ef2da6a86a6889bf5d4 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 28 Apr 2016 16:17:13 +1000 Subject: [PATCH] Refactor session implementation: rename SessionStore impls. --- .../server/session/CachingSessionStore.java | 3 +- .../server/session/DefaultSessionCache.java | 49 ++++++++----------- ...onDataStore.java => FileSessionStore.java} | 4 +- .../session/FileSessionStoreFactory.java | 2 +- ...onDataStore.java => JDBCSessionStore.java} | 6 +-- .../session/JDBCSessionStoreFactory.java | 6 +-- .../session/FileSessionManagerTest.java | 6 +-- .../jetty/server/session/FileTestServer.java | 2 +- .../jetty/server/session/JdbcTestServer.java | 4 +- .../session/AbstractLastAccessTimeTest.java | 4 +- .../session/AbstractRemoveSessionTest.java | 4 +- .../java/org/eclipse/jetty/TestServer.java | 4 +- 12 files changed, 43 insertions(+), 51 deletions(-) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{FileSessionDataStore.java => FileSessionStore.java} (99%) rename jetty-server/src/main/java/org/eclipse/jetty/server/session/{JDBCSessionDataStore.java => JDBCSessionStore.java} (99%) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java index 2bbc07224fc..68d00f0fbd3 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/CachingSessionStore.java @@ -32,7 +32,8 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle; * delegate SessionStore to improve performance: accessing most persistent store * technology can be expensive time-wise, so introducing a fronting cache * can increase performance. The cache implementation can either be a local cache, - * a remote cache, or a clustered cache. + * a remote cache, or a clustered cache. If the cache is cluster-wide then this can + * help with deployments without a sticky load balancer (but this is not ideal). */ public class CachingSessionStore extends AbstractLifeCycle implements SessionStore { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java index d1b8c8b0aa2..d1d42903d26 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java @@ -37,62 +37,53 @@ public class DefaultSessionCache extends AbstractSessionCache private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); + /** + * The cache of sessions in a hashmap + */ protected ConcurrentHashMap _sessions = new ConcurrentHashMap(); private final CounterStatistic _stats = new CounterStatistic(); + /** - * MemorySession - * - * + * @param manager */ - public class MemorySession extends Session - { - /** - * @param request the request associated with the new session - * @param data the info for the session - */ - public MemorySession(HttpServletRequest request, SessionData data) - { - super(request, data); - } - - - /** - * @param data the info for the restored session object - */ - public MemorySession(SessionData data) - { - super(data); - } - } - - - public DefaultSessionCache (SessionHandler manager) { super (manager); } - public long getSessions () + /** + * @return the number of sessions in the cache + */ + public long getSessionsCurrent () { return _stats.getCurrent(); } + /** + * @return the max number of sessions in the cache + */ public long getSessionsMax() { return _stats.getMax(); } + /** + * @return a running total of sessions in the cache + */ public long getSessionsTotal() { return _stats.getTotal(); } + /** + * + */ public void resetStats() { _stats.reset(); @@ -195,7 +186,7 @@ public class DefaultSessionCache extends AbstractSessionCache @Override public Session newSession(HttpServletRequest request, SessionData data) { - MemorySession s = new MemorySession(request,data); + Session s = new Session(request,data); return s; } @@ -208,7 +199,7 @@ public class DefaultSessionCache extends AbstractSessionCache @Override public Session newSession(SessionData data) { - MemorySession s = new MemorySession (data); + Session s = new Session (data); return s; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java similarity index 99% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java index b0650d6d128..b094b337033 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStore.java @@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * FileSessionDataStore + * FileSessionStore * * A file-based store of session data. */ -public class FileSessionDataStore extends AbstractSessionStore +public class FileSessionStore extends AbstractSessionStore { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); private File _storeDir; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java index 1a3f97150b2..136f5b9f0fd 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionStoreFactory.java @@ -74,7 +74,7 @@ public class FileSessionStoreFactory extends AbstractSessionStoreFactory @Override public SessionStore getSessionStore(SessionHandler handler) { - FileSessionDataStore fsds = new FileSessionDataStore(); + FileSessionStore fsds = new FileSessionStore(); fsds.setDeleteUnrestorableFiles(isDeleteUnrestorableFiles()); fsds.setStoreDir(getStoreDir()); fsds.setGracePeriodSec(getGracePeriodSec()); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java similarity index 99% rename from jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java index 75dd16cb54a..f732dbe7d9a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStore.java @@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - * JDBCSessionDataStore + * JDBCSessionStore * * Session data stored in database */ -public class JDBCSessionDataStore extends AbstractSessionStore +public class JDBCSessionStore extends AbstractSessionStore { final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -610,7 +610,7 @@ public class JDBCSessionDataStore extends AbstractSessionStore - public JDBCSessionDataStore () + public JDBCSessionStore () { super (); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java index 6746020a7ae..0731c32cfb0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionStoreFactory.java @@ -28,7 +28,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory { DatabaseAdaptor _adaptor; - JDBCSessionDataStore.SessionTableSchema _schema; + JDBCSessionStore.SessionTableSchema _schema; boolean _deleteUnloadableSessions; int _loadAttempts; @@ -39,7 +39,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory @Override public SessionStore getSessionStore(SessionHandler handler) { - JDBCSessionDataStore ds = new JDBCSessionDataStore(); + JDBCSessionStore ds = new JDBCSessionStore(); ds.setDatabaseAdaptor(_adaptor); ds.setSessionTableSchema(_schema); ds.setDeleteUnloadableSessions(_deleteUnloadableSessions); @@ -61,7 +61,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory /** * @param schema */ - public void setSessionTableSchema (JDBCSessionDataStore.SessionTableSchema schema) + public void setSessionTableSchema (JDBCSessionStore.SessionTableSchema schema) { _schema = schema; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java index fd5c97d54e0..9b938c803b8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java @@ -65,7 +65,7 @@ public class FileSessionManagerTest idmgr.setServer(server); server.setSessionIdManager(idmgr); - FileSessionDataStore ds = new FileSessionDataStore(); + FileSessionStore ds = new FileSessionStore(); ds.setDeleteUnrestorableFiles(true); DefaultSessionCache ss = new DefaultSessionCache(handler); handler.setSessionStore(ss); @@ -101,7 +101,7 @@ public class FileSessionManagerTest server.setSessionIdManager(idmgr); DefaultSessionCache ss = new DefaultSessionCache(handler); - FileSessionDataStore ds = new FileSessionDataStore(); + FileSessionStore ds = new FileSessionStore(); ss.setSessionStore(ds); handler.setSessionStore(ss); ds.setDeleteUnrestorableFiles(true); @@ -136,7 +136,7 @@ public class FileSessionManagerTest handler.setServer(server); DefaultSessionCache ss = new DefaultSessionCache(handler); - FileSessionDataStore ds = new FileSessionDataStore(); + FileSessionStore ds = new FileSessionStore(); ss.setSessionStore(ds); handler.setSessionStore(ss); ds.setStoreDir(testDir); diff --git a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java index fc972aeddb1..b5891a69eeb 100644 --- a/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java +++ b/tests/test-sessions/test-file-sessions/src/test/java/org/eclipse/jetty/server/session/FileTestServer.java @@ -144,7 +144,7 @@ public class FileTestServer extends AbstractTestServer SessionHandler handler = new SessionHandler(); DefaultSessionCache ss = new DefaultSessionCache(handler); handler.setSessionStore(ss); - FileSessionDataStore ds = new FileSessionDataStore(); + FileSessionStore ds = new FileSessionStore(); ds.setStoreDir(_tmpDir); ss.setSessionStore(ds); return handler; diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java index 2aee647e27f..7537bad4876 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/JdbcTestServer.java @@ -104,13 +104,13 @@ public class JdbcTestServer extends AbstractTestServer SessionHandler handler = new SessionHandler(); DefaultSessionCache sessionStore = new DefaultSessionCache(handler); handler.setSessionStore(sessionStore); - JDBCSessionDataStore ds = new JDBCSessionDataStore(); + JDBCSessionStore ds = new JDBCSessionStore(); sessionStore.setSessionStore(ds); ds.setGracePeriodSec(_scavengePeriod); DatabaseAdaptor da = new DatabaseAdaptor(); da.setDriverInfo(DRIVER_CLASS, (_config==null?DEFAULT_CONNECTION_URL:(String)_config)); ds.setDatabaseAdaptor(da); - JDBCSessionDataStore.SessionTableSchema sessionTableSchema = new JDBCSessionDataStore.SessionTableSchema(); + JDBCSessionStore.SessionTableSchema sessionTableSchema = new JDBCSessionStore.SessionTableSchema(); sessionTableSchema.setTableName(TABLE); sessionTableSchema.setIdColumn(ID_COL); sessionTableSchema.setAccessTimeColumn(ACCESS_COL); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java index acaa34e6ee2..2dd5fcb63f7 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractLastAccessTimeTest.java @@ -100,7 +100,7 @@ public abstract class AbstractLastAccessTimeTest assertEquals("test", response1.getContentAsString()); String sessionCookie = response1.getHeaders().get("Set-Cookie"); assertTrue( sessionCookie != null ); - assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessions()); + assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsCurrent()); assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsMax()); assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsTotal()); // Mangle the cookie, replacing Path with $Path, etc. @@ -164,7 +164,7 @@ public abstract class AbstractLastAccessTimeTest public void assertSessionCounts (int current, int max, int total, SessionHandler manager) { - assertEquals(current, ((DefaultSessionCache)manager.getSessionStore()).getSessions()); + assertEquals(current, ((DefaultSessionCache)manager.getSessionStore()).getSessionsCurrent()); assertEquals(max, ((DefaultSessionCache)manager.getSessionStore()).getSessionsMax()); assertEquals(total, ((DefaultSessionCache)manager.getSessionStore()).getSessionsTotal()); } diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java index 84dbc368718..f1d514bccb0 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/AbstractRemoveSessionTest.java @@ -91,7 +91,7 @@ public abstract class AbstractRemoveSessionTest assertEquals(HttpServletResponse.SC_OK,response.getStatus()); //ensure sessionDestroyed listener is called assertTrue(testListener.isDestroyed()); - assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessions()); + assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessionsCurrent()); assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax()); assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal()); @@ -100,7 +100,7 @@ public abstract class AbstractRemoveSessionTest request.header("Cookie", sessionCookie); response = request.send(); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); - assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessions()); + assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessionsCurrent()); assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax()); assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal()); } diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index efebd6bbeaa..8ffbe4bfe6c 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -44,7 +44,7 @@ import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.server.session.FileSessionDataStore; +import org.eclipse.jetty.server.session.FileSessionStore; import org.eclipse.jetty.server.session.DefaultSessionCache; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -133,7 +133,7 @@ public class TestServer sessiondir.mkdir(); sessiondir.deleteOnExit(); DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler()); - FileSessionDataStore sds = new FileSessionDataStore(); + FileSessionStore sds = new FileSessionStore(); ss.setSessionStore(sds); sds.setStoreDir(sessiondir); webapp.getSessionHandler().setSessionStore(ss);