Refactor session implementation: rename SessionStore impls.
This commit is contained in:
parent
728e0a7d57
commit
70a665d3e7
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<String, Session> _sessions = new ConcurrentHashMap<String, Session>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -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());
|
||||
|
|
|
@ -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 ();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue