Merge remote-tracking branch 'origin/jetty-9.4.x'
This commit is contained in:
commit
2e2b8e1a13
|
@ -42,7 +42,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.session.AbstractSessionStore;
|
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.SessionContext;
|
import org.eclipse.jetty.server.session.SessionContext;
|
||||||
import org.eclipse.jetty.server.session.SessionData;
|
import org.eclipse.jetty.server.session.SessionData;
|
||||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
||||||
|
@ -51,11 +51,11 @@ import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GCloudSessionStore
|
* GCloudSessionDataStore
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GCloudSessionStore extends AbstractSessionStore
|
public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStart()
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStart()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws Exception
|
protected void doStart() throws Exception
|
||||||
|
@ -138,7 +138,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -159,7 +159,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -170,7 +170,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(Set<String> candidates)
|
public Set<String> doGetExpired(Set<String> candidates)
|
||||||
|
@ -221,7 +221,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//reconcile against ids that the SessionStore thinks are expired
|
//reconcile against ids that the SessionDataStore thinks are expired
|
||||||
Set<String> tmp = new HashSet<String>(candidates);
|
Set<String> tmp = new HashSet<String>(candidates);
|
||||||
tmp.removeAll(expired);
|
tmp.removeAll(expired);
|
||||||
if (!tmp.isEmpty())
|
if (!tmp.isEmpty())
|
||||||
|
@ -264,7 +264,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id) throws Exception
|
public boolean exists(String id) throws Exception
|
||||||
|
@ -290,7 +290,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -431,7 +431,7 @@ public class GCloudSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
|
@ -59,11 +59,11 @@ public class GCloudSessionTester
|
||||||
webapp.setContextPath("/");
|
webapp.setContextPath("/");
|
||||||
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
|
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
|
||||||
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
|
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
|
||||||
GCloudSessionStore ds = new GCloudSessionStore();
|
GCloudSessionDataStore ds = new GCloudSessionDataStore();
|
||||||
ds.setGCloudConfiguration(config);
|
ds.setGCloudConfiguration(config);
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
|
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
|
||||||
webapp.getSessionHandler().setSessionStore(ss);
|
webapp.getSessionHandler().setSessionCache(ss);
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
webapp.getSessionHandler().setSessionIdManager(idmgr);
|
webapp.getSessionHandler().setSessionIdManager(idmgr);
|
||||||
|
|
||||||
// A WebAppContext is a ContextHandler as well so it needs to be set to
|
// A WebAppContext is a ContextHandler as well so it needs to be set to
|
||||||
|
|
|
@ -25,18 +25,18 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.SessionIdManager;
|
import org.eclipse.jetty.server.SessionIdManager;
|
||||||
import org.eclipse.jetty.server.session.AbstractSessionStore;
|
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.SessionData;
|
import org.eclipse.jetty.server.session.SessionData;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.infinispan.commons.api.BasicCache;
|
import org.infinispan.commons.api.BasicCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InfinispanSessionStore
|
* InfinispanSessionDataStore
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InfinispanSessionStore extends AbstractSessionStore
|
public class InfinispanSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -114,7 +114,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -125,7 +125,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(Set<String> candidates)
|
public Set<String> doGetExpired(Set<String> candidates)
|
||||||
|
@ -138,7 +138,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
Set<String> expired = new HashSet<String>();
|
Set<String> expired = new HashSet<String>();
|
||||||
|
|
||||||
//TODO if there is NOT an idle timeout set on entries in infinispan, need to check other sessions
|
//TODO if there is NOT an idle timeout set on entries in infinispan, need to check other sessions
|
||||||
//that are not currently in the SessionStore (eg they've been passivated)
|
//that are not currently in the SessionDataStore (eg they've been passivated)
|
||||||
|
|
||||||
for (String candidate:candidates)
|
for (String candidate:candidates)
|
||||||
{
|
{
|
||||||
|
@ -196,7 +196,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -224,7 +224,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
||||||
|
@ -248,7 +248,7 @@ public class InfinispanSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id) throws Exception
|
public boolean exists(String id) throws Exception
|
|
@ -19,17 +19,17 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.session.infinispan;
|
package org.eclipse.jetty.session.infinispan;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.session.AbstractSessionStoreFactory;
|
import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory;
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
import org.eclipse.jetty.server.session.SessionStore;
|
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||||
import org.infinispan.commons.api.BasicCache;
|
import org.infinispan.commons.api.BasicCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InfinispanSessionStoreFactory
|
* InfinispanSessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InfinispanSessionStoreFactory extends AbstractSessionStoreFactory
|
public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
int _infinispanIdleTimeoutSec;
|
int _infinispanIdleTimeoutSec;
|
||||||
BasicCache<String, Object> _cache;
|
BasicCache<String, Object> _cache;
|
||||||
|
@ -52,12 +52,12 @@ public class InfinispanSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionStore getSessionStore (SessionHandler handler) throws Exception
|
public SessionDataStore getSessionDataStore (SessionHandler handler) throws Exception
|
||||||
{
|
{
|
||||||
InfinispanSessionStore store = new InfinispanSessionStore();
|
InfinispanSessionDataStore store = new InfinispanSessionDataStore();
|
||||||
store.setGracePeriodSec(getGracePeriodSec());
|
store.setGracePeriodSec(getGracePeriodSec());
|
||||||
store.setInfinispanIdleTimeoutSec(getInfinispanIdleTimeoutSec());
|
store.setInfinispanIdleTimeoutSec(getInfinispanIdleTimeoutSec());
|
||||||
store.setCache(getCache());
|
store.setCache(getCache());
|
|
@ -426,18 +426,18 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump
|
||||||
public void onClose(final EndPoint endPoint)
|
public void onClose(final EndPoint endPoint)
|
||||||
{
|
{
|
||||||
final Connection connection = endPoint.getConnection();
|
final Connection connection = endPoint.getConnection();
|
||||||
submit(new Product()
|
if (connection!=null)
|
||||||
{
|
submit(new Product()
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
@Override
|
||||||
LOG.debug("Destroyed {}", endPoint);
|
public void run()
|
||||||
if (connection != null)
|
{
|
||||||
_selectorManager.connectionClosed(connection);
|
if (LOG.isDebugEnabled())
|
||||||
_selectorManager.endPointClosed(endPoint);
|
LOG.debug("Destroyed {}", endPoint);
|
||||||
}
|
if (connection != null)
|
||||||
});
|
_selectorManager.connectionClosed(connection);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,16 +22,16 @@ package org.eclipse.jetty.nosql;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.session.AbstractSessionStore;
|
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.SessionData;
|
import org.eclipse.jetty.server.session.SessionData;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NoSqlSessionStore
|
* NoSqlSessionDataStore
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class NoSqlSessionStore extends AbstractSessionStore
|
public abstract class NoSqlSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
|
|
||||||
public class NoSqlSessionData extends SessionData
|
public class NoSqlSessionData extends SessionData
|
|
@ -24,6 +24,7 @@ import com.mongodb.DBCollection;
|
||||||
import com.mongodb.DBCursor;
|
import com.mongodb.DBCursor;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import com.mongodb.WriteConcern;
|
import com.mongodb.WriteConcern;
|
||||||
|
import com.mongodb.WriteResult;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -36,14 +37,14 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.eclipse.jetty.nosql.NoSqlSessionStore;
|
import org.eclipse.jetty.nosql.NoSqlSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.SessionData;
|
import org.eclipse.jetty.server.session.SessionData;
|
||||||
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MongoSessionStore
|
* MongoSessionDataStore
|
||||||
*
|
*
|
||||||
* The document model is an outer object that contains the elements:
|
* The document model is an outer object that contains the elements:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
@ -88,7 +89,7 @@ import org.eclipse.jetty.util.log.Logger;
|
||||||
* <code>"context".unique_context_name.attribute_name</code>
|
* <code>"context".unique_context_name.attribute_name</code>
|
||||||
* Eg <code>"context"."::/contextA"."A"</code>
|
* Eg <code>"context"."::/contextA"."A"</code>
|
||||||
*/
|
*/
|
||||||
public class MongoSessionStore extends NoSqlSessionStore
|
public class MongoSessionDataStore extends NoSqlSessionDataStore
|
||||||
{
|
{
|
||||||
|
|
||||||
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
|
@ -166,7 +167,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -258,7 +259,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -272,7 +273,8 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
*/
|
*/
|
||||||
BasicDBObject mongoKey = new BasicDBObject(__ID, id);
|
BasicDBObject mongoKey = new BasicDBObject(__ID, id);
|
||||||
|
|
||||||
DBObject sessionDocument = _dbSessions.findOne(mongoKey,_version_1);
|
//DBObject sessionDocument = _dbSessions.findOne(mongoKey,_version_1);
|
||||||
|
DBObject sessionDocument = _dbSessions.findOne(new BasicDBObject(__ID, id));
|
||||||
|
|
||||||
if (sessionDocument != null)
|
if (sessionDocument != null)
|
||||||
{
|
{
|
||||||
|
@ -280,7 +282,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
//delete whole doc
|
//delete whole doc
|
||||||
_dbSessions.remove(mongoKey);
|
_dbSessions.remove(mongoKey, WriteConcern.SAFE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,14 +290,14 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
if (contexts.isEmpty())
|
if (contexts.isEmpty())
|
||||||
{
|
{
|
||||||
//delete whole doc
|
//delete whole doc
|
||||||
_dbSessions.remove(mongoKey);
|
_dbSessions.remove(mongoKey, WriteConcern.SAFE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contexts.size() == 1 && contexts.iterator().next().equals(getCanonicalContextId()))
|
if (contexts.size() == 1 && contexts.iterator().next().equals(getCanonicalContextId()))
|
||||||
{
|
{
|
||||||
//delete whole doc
|
//delete whole doc
|
||||||
_dbSessions.remove(mongoKey);
|
_dbSessions.remove(new BasicDBObject(__ID, id), WriteConcern.SAFE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,8 +306,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
BasicDBObject unsets = new BasicDBObject();
|
BasicDBObject unsets = new BasicDBObject();
|
||||||
unsets.put(getContextField(),1);
|
unsets.put(getContextField(),1);
|
||||||
remove.put("$unset",unsets);
|
remove.put("$unset",unsets);
|
||||||
_dbSessions.update(mongoKey,remove,false,false,WriteConcern.SAFE);
|
WriteResult result = _dbSessions.update(mongoKey,remove,false,false,WriteConcern.SAFE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -318,7 +319,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id) throws Exception
|
public boolean exists(String id) throws Exception
|
||||||
|
@ -345,7 +346,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(Set<String> candidates)
|
public Set<String> doGetExpired(Set<String> candidates)
|
||||||
|
@ -409,7 +410,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -492,12 +493,9 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
update.put("$set",sets);
|
update.put("$set",sets);
|
||||||
if (!unsets.isEmpty())
|
if (!unsets.isEmpty())
|
||||||
update.put("$unset",unsets);
|
update.put("$unset",unsets);
|
||||||
|
WriteResult res = _dbSessions.update(key,update,upsert,false,WriteConcern.SAFE);
|
||||||
_dbSessions.update(key,update,upsert,false,WriteConcern.SAFE);
|
|
||||||
|
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Save:db.sessions.update( {}, {} )", key, update);
|
LOG.debug("Save:db.sessions.update( {}, {},{} )", key, update, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +646,7 @@ public class MongoSessionStore extends NoSqlSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
|
@ -21,20 +21,20 @@ package org.eclipse.jetty.nosql.mongodb;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.session.AbstractSessionStoreFactory;
|
import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory;
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
import org.eclipse.jetty.server.session.SessionStore;
|
import org.eclipse.jetty.server.session.SessionDataStore;
|
||||||
|
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
import com.mongodb.Mongo;
|
||||||
import com.mongodb.MongoException;
|
import com.mongodb.MongoException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MongoSessionStoreFactory
|
* MongoSessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MongoSessionStoreFactory extends AbstractSessionStoreFactory
|
public class MongoSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
String _dbName;
|
String _dbName;
|
||||||
String _collectionName;
|
String _collectionName;
|
||||||
|
@ -76,12 +76,12 @@ public class MongoSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
/**
|
/**
|
||||||
* @throws MongoException
|
* @throws MongoException
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionStore getSessionStore(SessionHandler handler) throws Exception
|
public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception
|
||||||
{
|
{
|
||||||
MongoSessionStore store = new MongoSessionStore();
|
MongoSessionDataStore store = new MongoSessionDataStore();
|
||||||
store.setGracePeriodSec(getGracePeriodSec());
|
store.setGracePeriodSec(getGracePeriodSec());
|
||||||
store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName()));
|
store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName()));
|
||||||
return store;
|
return store;
|
|
@ -9,7 +9,7 @@
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
<Call name="addBean">
|
<Call name="addBean">
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.server.session.FileSessionStoreFactory">
|
<New class="org.eclipse.jetty.server.session.FileSessionDataStoreFactory">
|
||||||
<Set name="deleteUnrestorableFiles"><Property name="jetty.session.deleteUnrestorableFiles" default="false" /></Set>
|
<Set name="deleteUnrestorableFiles"><Property name="jetty.session.deleteUnrestorableFiles" default="false" /></Set>
|
||||||
<Set name="storeDir"><Property name="jetty.session.storeDir"/></Set>
|
<Set name="storeDir"><Property name="jetty.session.storeDir"/></Set>
|
||||||
</New>
|
</New>
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
<Call name="addBean">
|
<Call name="addBean">
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.server.session.JDBCSessionStoreFactory">
|
<New class="org.eclipse.jetty.server.session.JDBCSessionDataStoreFactory">
|
||||||
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
|
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
|
||||||
<Set name="loadAttempts"><Property name="jetty.session.loadAttempts" default="-1" /></Set>
|
<Set name="loadAttempts"><Property name="jetty.session.loadAttempts" default="-1" /></Set>
|
||||||
<Set name="deleteUnloadables"><Property name="jetty.session.deleteUnloadables" default="false" /></Set>
|
<Set name="deleteUnloadables"><Property name="jetty.session.deleteUnloadables" default="false" /></Set>
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
</Set>
|
</Set>
|
||||||
<Set name="sessionTableSchema">
|
<Set name="sessionTableSchema">
|
||||||
<New
|
<New
|
||||||
class="org.eclipse.jetty.server.session.JDBCSessionStore.SessionTableSchema">
|
class="org.eclipse.jetty.server.session.JDBCSessionDataStore.SessionTableSchema">
|
||||||
<Set name="accessTimeColumn">
|
<Set name="accessTimeColumn">
|
||||||
<Property name="jetty.sessionTableSchema.accessTimeColumn" default="accessTime" />
|
<Property name="jetty.sessionTableSchema.accessTimeColumn" default="accessTime" />
|
||||||
</Set>
|
</Set>
|
||||||
|
|
|
@ -361,7 +361,11 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque
|
||||||
|
|
||||||
// Should we delay dispatch until we have some content?
|
// Should we delay dispatch until we have some content?
|
||||||
// We should not delay if there is no content expect or client is expecting 100 or the response is already committed or the request buffer already has something in it to parse
|
// We should not delay if there is no content expect or client is expecting 100 or the response is already committed or the request buffer already has something in it to parse
|
||||||
_delayedForContent = (getHttpConfiguration().isDelayDispatchUntilContent() && _httpConnection.getParser().getContentLength()>0 && !isExpecting100Continue() && !isCommitted() && _httpConnection.isRequestBufferEmpty());
|
_delayedForContent = (getHttpConfiguration().isDelayDispatchUntilContent()
|
||||||
|
&& (_httpConnection.getParser().getContentLength()>0 || _httpConnection.getParser().isChunking() )
|
||||||
|
&& !isExpecting100Continue()
|
||||||
|
&& !isCommitted()
|
||||||
|
&& _httpConnection.isRequestBufferEmpty());
|
||||||
|
|
||||||
return !_delayedForContent;
|
return !_delayedForContent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,6 @@ public class Request implements HttpServletRequest
|
||||||
private String _readerEncoding;
|
private String _readerEncoding;
|
||||||
private InetSocketAddress _remote;
|
private InetSocketAddress _remote;
|
||||||
private String _requestedSessionId;
|
private String _requestedSessionId;
|
||||||
private Map<Object, HttpSession> _savedNewSessions;
|
|
||||||
private UserIdentity.Scope _scope;
|
private UserIdentity.Scope _scope;
|
||||||
private HttpSession _session;
|
private HttpSession _session;
|
||||||
private SessionHandler _sessionHandler;
|
private SessionHandler _sessionHandler;
|
||||||
|
@ -1716,13 +1715,6 @@ public class Request implements HttpServletRequest
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
|
||||||
public HttpSession recoverNewSession(Object key)
|
|
||||||
{
|
|
||||||
if (_savedNewSessions == null)
|
|
||||||
return null;
|
|
||||||
return _savedNewSessions.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
|
@ -1840,10 +1832,6 @@ public class Request implements HttpServletRequest
|
||||||
_parameters = null;
|
_parameters = null;
|
||||||
_paramsExtracted = false;
|
_paramsExtracted = false;
|
||||||
_inputState = __NONE;
|
_inputState = __NONE;
|
||||||
|
|
||||||
if (_savedNewSessions != null)
|
|
||||||
_savedNewSessions.clear();
|
|
||||||
_savedNewSessions=null;
|
|
||||||
_multiPartInputStream = null;
|
_multiPartInputStream = null;
|
||||||
_remote=null;
|
_remote=null;
|
||||||
_input.recycle();
|
_input.recycle();
|
||||||
|
@ -1875,13 +1863,6 @@ public class Request implements HttpServletRequest
|
||||||
_requestAttributeListeners.remove(listener);
|
_requestAttributeListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
|
||||||
public void saveNewSession(Object key, HttpSession session)
|
|
||||||
{
|
|
||||||
if (_savedNewSessions == null)
|
|
||||||
_savedNewSessions = new HashMap<>();
|
|
||||||
_savedNewSessions.put(key,session);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public void setAsyncSupported(boolean supported,String source)
|
public void setAsyncSupported(boolean supported,String source)
|
||||||
|
|
|
@ -33,19 +33,57 @@ import org.eclipse.jetty.util.thread.Locker.Lock;
|
||||||
/**
|
/**
|
||||||
* AbstractSessionCache
|
* AbstractSessionCache
|
||||||
*
|
*
|
||||||
* Basic behaviour for maintaining an in-memory store of Session objects and
|
* A base implementation of the SessionCache interface for managing a set of
|
||||||
* making sure that any backing SessionDataStore is kept in sync.
|
* Session objects pertaining to a context in memory.
|
||||||
|
*
|
||||||
|
* This implementation ensures that multiple requests for the same session id
|
||||||
|
* always return the same Session object.
|
||||||
|
*
|
||||||
|
* It will delay writing out a session to the SessionDataStore until the
|
||||||
|
* last request exists the session. If the SessionDataStore supports passivation
|
||||||
|
* then the session passivation and activation listeners are called appropriately as
|
||||||
|
* the session is written. Additionally the session can be evicted from the
|
||||||
|
* AbstractSessionCache after passivation on write.
|
||||||
|
*
|
||||||
|
* This implementation also supports evicting idle Session objects. An idle Session
|
||||||
|
* is one that is still valid, has not expired, but has not been accessed by a
|
||||||
|
* request for a configurable amount of time. An idle session will be first
|
||||||
|
* passivated before eviction from the cache.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionCache
|
public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionCache
|
||||||
{
|
{
|
||||||
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
|
|
||||||
protected SessionStore _sessionStore;
|
/**
|
||||||
protected final SessionHandler _handler;
|
* The authoritative source of session data
|
||||||
protected SessionContext _context;
|
*/
|
||||||
protected int _idlePassivationTimeoutSec;
|
protected SessionDataStore _sessionDataStore;
|
||||||
private boolean _passivateOnComplete;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The SessionHandler related to this SessionCache
|
||||||
|
*/
|
||||||
|
protected final SessionHandler _handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about the context to which this SessionCache pertains
|
||||||
|
*/
|
||||||
|
protected SessionContext _context;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs)
|
||||||
|
*/
|
||||||
|
protected int _evictionPolicy;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, a session that will be evicted from the cache because it has been
|
||||||
|
* inactive too long will be saved before being evicted.
|
||||||
|
*/
|
||||||
|
protected boolean _saveOnInactiveEviction;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Session object from pre-existing session data
|
* Create a new Session object from pre-existing session data
|
||||||
|
@ -115,7 +153,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
*/
|
*/
|
||||||
public PlaceHolderSession(SessionData data)
|
public PlaceHolderSession(SessionData data)
|
||||||
{
|
{
|
||||||
super(data);
|
super(null, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +162,9 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public AbstractSessionCache (SessionHandler manager)
|
public AbstractSessionCache (SessionHandler handler)
|
||||||
{
|
{
|
||||||
_handler = manager;
|
_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +195,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws Exception
|
protected void doStart() throws Exception
|
||||||
{
|
{
|
||||||
if (_sessionStore == null)
|
if (_sessionDataStore == null)
|
||||||
throw new IllegalStateException ("No session data store configured");
|
throw new IllegalStateException ("No session data store configured");
|
||||||
|
|
||||||
if (_handler == null)
|
if (_handler == null)
|
||||||
|
@ -166,8 +204,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
if (_context == null)
|
if (_context == null)
|
||||||
throw new IllegalStateException ("No ContextId");
|
throw new IllegalStateException ("No ContextId");
|
||||||
|
|
||||||
_sessionStore.initialize(_context);
|
_sessionDataStore.initialize(_context);
|
||||||
_sessionStore.start();
|
_sessionDataStore.start();
|
||||||
|
|
||||||
|
|
||||||
super.doStart();
|
super.doStart();
|
||||||
|
@ -179,50 +217,51 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws Exception
|
protected void doStop() throws Exception
|
||||||
{
|
{
|
||||||
_sessionStore.stop();
|
_sessionDataStore.stop();
|
||||||
super.doStop();
|
super.doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the SessionStore or null if there isn't one
|
* @return the SessionDataStore or null if there isn't one
|
||||||
*/
|
*/
|
||||||
public SessionStore getSessionStore()
|
public SessionDataStore getSessionDataStore()
|
||||||
{
|
{
|
||||||
return _sessionStore;
|
return _sessionDataStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionCache#setSessionStore(org.eclipse.jetty.server.session.SessionStore)
|
* @see org.eclipse.jetty.server.session.SessionCache#setSessionDataStore(org.eclipse.jetty.server.session.SessionDataStore)
|
||||||
*/
|
*/
|
||||||
public void setSessionStore(SessionStore sessionStore)
|
public void setSessionDataStore(SessionDataStore sessionStore)
|
||||||
{
|
{
|
||||||
_sessionStore = sessionStore;
|
_sessionDataStore = sessionStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.jetty.server.session.SessionCache#getIdlePassivationTimeoutSec()
|
|
||||||
*/
|
|
||||||
public int getIdlePassivationTimeoutSec()
|
|
||||||
{
|
|
||||||
return _idlePassivationTimeoutSec;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionCache#setIdlePassivationTimeoutSec(int)
|
* @see org.eclipse.jetty.server.session.SessionCache#getEvictionPolicy()
|
||||||
*/
|
*/
|
||||||
public void setIdlePassivationTimeoutSec(int idleTimeoutSec)
|
public int getEvictionPolicy()
|
||||||
{
|
{
|
||||||
_idlePassivationTimeoutSec = idleTimeoutSec;
|
return _evictionPolicy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -1 means we never evict inactive sessions.
|
||||||
|
* 0 means we evict a session after the last request for it exits
|
||||||
|
* >0 is the number of seconds after which we evict inactive sessions from the cache
|
||||||
|
*
|
||||||
|
* @see org.eclipse.jetty.server.session.SessionCache#setEvictionPolicy(int)
|
||||||
|
*/
|
||||||
|
public void setEvictionPolicy(int evictionTimeout)
|
||||||
|
{
|
||||||
|
_evictionPolicy = evictionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,14 +283,14 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
{
|
{
|
||||||
session = doGet(id);
|
session = doGet(id);
|
||||||
|
|
||||||
if (_sessionStore == null)
|
if (_sessionDataStore == null)
|
||||||
break; //can't load any session data so just return null or the session object
|
break; //can't load any session data so just return null or the session object
|
||||||
|
|
||||||
if (session == null)
|
if (session == null)
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Session not found locally, attempting to load");
|
LOG.debug("Session {} not found locally, attempting to load", id);
|
||||||
|
|
||||||
//didn't get a session, try and create one and put in a placeholder for it
|
//didn't get a session, try and create one and put in a placeholder for it
|
||||||
PlaceHolderSession phs = new PlaceHolderSession (new SessionData(id, null, null,0,0,0,0));
|
PlaceHolderSession phs = new PlaceHolderSession (new SessionData(id, null, null,0,0,0,0));
|
||||||
Lock phsLock = phs.lock();
|
Lock phsLock = phs.lock();
|
||||||
|
@ -286,7 +325,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//successfully swapped in the session
|
//successfully swapped in the session
|
||||||
session.setTimeout (); //TODO start the session timer
|
session.setResident(true);
|
||||||
|
session.updateInactivityTimer();
|
||||||
phsLock.close();
|
phsLock.close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -307,8 +347,8 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
phsLock.close();
|
phsLock.close();
|
||||||
try (Lock lock = s.lock())
|
try (Lock lock = s.lock())
|
||||||
{
|
{
|
||||||
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
|
//is it a placeholder? or is a non-resident session? In both cases, chuck it away and start again
|
||||||
if (s.isPassivated() || s instanceof PlaceHolderSession)
|
if (!s.isResident() || s instanceof PlaceHolderSession)
|
||||||
{
|
{
|
||||||
session = null;
|
session = null;
|
||||||
continue;
|
continue;
|
||||||
|
@ -323,14 +363,14 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
{
|
{
|
||||||
//check the session returned
|
//check the session returned
|
||||||
try (Lock lock = session.lock())
|
try (Lock lock = session.lock())
|
||||||
{
|
{
|
||||||
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
|
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
|
||||||
if (session.isPassivated() || session instanceof PlaceHolderSession)
|
if (!session.isResident()|| session instanceof PlaceHolderSession)
|
||||||
{
|
{
|
||||||
session = null;
|
session = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//got the session
|
//got the session
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -355,24 +395,23 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
SessionData data = null;
|
SessionData data = null;
|
||||||
Session session = null;
|
Session session = null;
|
||||||
|
|
||||||
if (_sessionStore == null)
|
if (_sessionDataStore == null)
|
||||||
return null; //can't load it
|
return null; //can't load it
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
data =_sessionStore.load(id);
|
data =_sessionDataStore.load(id);
|
||||||
|
|
||||||
if (data == null) //session doesn't exist
|
if (data == null) //session doesn't exist
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
session = newSession(data);
|
session = newSession(data);
|
||||||
session.setSessionHandler(_handler);
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
catch (UnreadableSessionDataException e)
|
catch (UnreadableSessionDataException e)
|
||||||
{
|
{
|
||||||
//can't load the session, delete it
|
//can't load the session, delete it
|
||||||
_sessionStore.delete(id);
|
_sessionDataStore.delete(id);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,10 +419,15 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
/**
|
/**
|
||||||
* Put the Session object back into the session store.
|
* Put the Session object back into the session store.
|
||||||
*
|
*
|
||||||
* This should be called by Session.complete when a request exists the session.
|
* This should be called when a request exists the session. Only when the last
|
||||||
|
* simultaneous request exists the session will any action be taken.
|
||||||
*
|
*
|
||||||
* If the session manager supports a session data store, write the
|
* If there is a SessionDataStore write the session data through to it.
|
||||||
* session data through to the session data store.
|
*
|
||||||
|
* If the SessionDataStore supports passivation, call the passivate/active listeners.
|
||||||
|
*
|
||||||
|
* If the evictionPolicy == SessionCache.EVICT_ON_SESSION_EXIT then after we have saved
|
||||||
|
* the session, we evict it from the cache.
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jetty.server.session.SessionCache#put(java.lang.String, org.eclipse.jetty.server.session.Session)
|
* @see org.eclipse.jetty.server.session.SessionCache#put(java.lang.String, org.eclipse.jetty.server.session.Session)
|
||||||
*/
|
*/
|
||||||
|
@ -393,55 +437,71 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
if (id == null || session == null)
|
if (id == null || session == null)
|
||||||
throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId()));
|
throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if the session is new or data has changed write it to any backing store
|
|
||||||
try (Lock lock = session.lock())
|
try (Lock lock = session.lock())
|
||||||
{
|
{
|
||||||
session.setSessionHandler(_handler);
|
if (session.getSessionHandler() == null)
|
||||||
|
throw new IllegalStateException("Session "+id+" is not managed");
|
||||||
if (session.isPassivated())
|
|
||||||
throw new IllegalStateException ("Session "+id+" is passivated and cannot be saved");
|
|
||||||
|
|
||||||
if (!session.isValid())
|
if (!session.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_sessionStore == null)
|
if (_sessionDataStore == null)
|
||||||
{
|
{
|
||||||
doPutIfAbsent(id, session); //ensure it is in our map
|
session.setResident(true);
|
||||||
|
if (doPutIfAbsent(id, session) == null) //ensure it is in our map
|
||||||
|
session.updateInactivityTimer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//don't do anything with the session until the last request for it has finished
|
||||||
if ((session.getRequests() <= 0))
|
if ((session.getRequests() <= 0))
|
||||||
{
|
{
|
||||||
//only save if all requests have finished
|
//save the session
|
||||||
if (!_sessionStore.isPassivating())
|
if (!_sessionDataStore.isPassivating())
|
||||||
{
|
{
|
||||||
//if our backing datastore isn't the passivating kind, just save the session
|
//if our backing datastore isn't the passivating kind, just save the session
|
||||||
_sessionStore.store(id, session.getSessionData());
|
_sessionDataStore.store(id, session.getSessionData());
|
||||||
|
//if we evict on session exit, boot it from the cache
|
||||||
|
if (getEvictionPolicy() == EVICT_ON_SESSION_EXIT)
|
||||||
|
{
|
||||||
|
doDelete(session.getId());
|
||||||
|
session.setResident(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
session.setResident(true);
|
||||||
|
if (doPutIfAbsent(id,session) == null) //ensure it is in our map
|
||||||
|
session.updateInactivityTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//backing store supports passivation
|
//backing store supports passivation, call the listeners
|
||||||
session.willPassivate();
|
session.willPassivate();
|
||||||
_sessionStore.store(id, session.getSessionData());
|
_sessionDataStore.store(id, session.getSessionData());
|
||||||
session.setPassivated();
|
|
||||||
if (isPassivateOnComplete())
|
if (getEvictionPolicy() == EVICT_ON_SESSION_EXIT)
|
||||||
{
|
{
|
||||||
//throw out the passivated session object from the map
|
//throw out the passivated session object from the map
|
||||||
doDelete(id);
|
doDelete(id);
|
||||||
|
session.setResident(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//reactivate the session
|
//reactivate the session
|
||||||
session.setActive();
|
session.didActivate();
|
||||||
session.didActivate();
|
session.setResident(true);
|
||||||
|
if (doPutIfAbsent(id,session) == null) //ensure it is in our map
|
||||||
|
session.updateInactivityTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
doPutIfAbsent(id,session); //ensure it is in our map
|
{
|
||||||
|
session.setResident(true);
|
||||||
|
if (doPutIfAbsent(id, session) == null) //ensure it is the map, but don't save it to the backing store until the last request exists
|
||||||
|
session.updateInactivityTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +530,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
}
|
}
|
||||||
|
|
||||||
//not there, so find out if session data exists for it
|
//not there, so find out if session data exists for it
|
||||||
return _sessionStore.exists (id);
|
return _sessionDataStore.exists (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -486,16 +546,21 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
//get the session, if its not in memory, this will load it
|
//get the session, if its not in memory, this will load it
|
||||||
Session session = get(id);
|
Session session = get(id);
|
||||||
|
|
||||||
|
|
||||||
//Always delete it from the backing data store
|
//Always delete it from the backing data store
|
||||||
if (_sessionStore != null)
|
if (_sessionDataStore != null)
|
||||||
{
|
{
|
||||||
boolean dsdel = _sessionStore.delete(id);
|
|
||||||
|
boolean dsdel = _sessionDataStore.delete(id);
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Session {} deleted in db {}",id, dsdel);
|
if (LOG.isDebugEnabled()) LOG.debug("Session {} deleted in db {}",id, dsdel);
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete it from the session object store
|
//delete it from the session object store
|
||||||
if (session != null)
|
if (session != null)
|
||||||
session.stopTimeout();
|
{
|
||||||
|
session.stopInactivityTimer();
|
||||||
|
session.setResident(false);
|
||||||
|
}
|
||||||
|
|
||||||
return doDelete(id);
|
return doDelete(id);
|
||||||
}
|
}
|
||||||
|
@ -515,70 +580,64 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("SessionStore checking expiration on {}", candidates);
|
LOG.debug("SessionDataStore checking expiration on {}", candidates);
|
||||||
return _sessionStore.getExpired(candidates);
|
return _sessionDataStore.getExpired(candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the SessionDataStore supports passivation,
|
* Check a session for being inactive and
|
||||||
* write the session to the backing data store.
|
* thus being able to be evicted, if eviction
|
||||||
|
* is enabled.
|
||||||
*
|
*
|
||||||
* @param id identity of session to passivate
|
*
|
||||||
|
* @param session
|
||||||
*/
|
*/
|
||||||
@Override
|
public void checkInactiveSession (Session session)
|
||||||
public void passivateIdleSession(String id)
|
|
||||||
{
|
{
|
||||||
if (!isStarted())
|
if (session == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_sessionStore == null || !_sessionStore.isPassivating())
|
|
||||||
return; //no data store to passivate or it doesn't passivate
|
|
||||||
|
|
||||||
//get the session locally
|
try (Lock s = session.lock())
|
||||||
Session s = doGet(id);
|
|
||||||
|
|
||||||
if (s == null)
|
|
||||||
{
|
{
|
||||||
LOG.warn("Session {} not in this session store", s);
|
if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) && session.isValid() && session.isResident() && session.getRequests() <= 0)
|
||||||
return;
|
{
|
||||||
}
|
//Be careful with saveOnInactiveEviction - you may be able to re-animate a session that was
|
||||||
|
//being managed on another node and has expired.
|
||||||
|
|
||||||
//lock the session during passivation
|
|
||||||
try (Lock lock = s.lock())
|
|
||||||
{
|
|
||||||
//check the session is still idle and that it doesn't have requests using it
|
|
||||||
if (s.isValid() && s.isIdleLongerThan(_idlePassivationTimeoutSec) && s.isActive() && (s.getRequests() <= 0))
|
|
||||||
{
|
|
||||||
//TODO - do we need to check that the session exists in the session data store
|
|
||||||
//before we passivate it? If it doesn't exist, we can assume another node
|
|
||||||
//invalidated it. If the session was new, it shouldn't have been idle passivated.
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Passivating idle session {}", id);
|
LOG.debug("Evicting idle session {}", session.getId());
|
||||||
s.willPassivate();
|
|
||||||
_sessionStore.store(id, s.getSessionData());
|
//save before evicting
|
||||||
s.setPassivated();
|
if (isSaveOnInactiveEviction() && _sessionDataStore != null)
|
||||||
s.stopTimeout();
|
{
|
||||||
doDelete(id); //Take the session object of this session store
|
if (_sessionDataStore.isPassivating())
|
||||||
|
session.willPassivate();
|
||||||
|
|
||||||
|
_sessionDataStore.store(session.getId(), session.getSessionData());
|
||||||
|
}
|
||||||
|
|
||||||
|
//evict
|
||||||
|
// session.stopInactivityTimer();
|
||||||
|
|
||||||
|
doDelete(session.getId()); //detach from this cache
|
||||||
|
session.setResident(false);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOG.warn("Passivation of idle session {} failed", id, e);
|
LOG.warn("Passivation of idle session {} failed", session.getId(), e);
|
||||||
s.setPassivated(); //set it as passivated so it can't be used
|
doDelete(session.getId()); //detach it
|
||||||
doDelete(id); //detach it
|
session.setResident(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -604,10 +663,10 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
session.getSessionData().setDirty(true); //ensure we will try to write the session out
|
session.getSessionData().setDirty(true); //ensure we will try to write the session out
|
||||||
doPutIfAbsent(newId, session); //put the new id into our map
|
doPutIfAbsent(newId, session); //put the new id into our map
|
||||||
doDelete (oldId); //take old out of map
|
doDelete (oldId); //take old out of map
|
||||||
if (_sessionStore != null)
|
if (_sessionDataStore != null)
|
||||||
{
|
{
|
||||||
_sessionStore.delete(oldId); //delete the session data with the old id
|
_sessionDataStore.delete(oldId); //delete the session data with the old id
|
||||||
_sessionStore.store(newId, session.getSessionData()); //save the session data with the new id
|
_sessionDataStore.store(newId, session.getSessionData()); //save the session data with the new id
|
||||||
}
|
}
|
||||||
LOG.info("Session id {} swapped for new id {}", oldId, newId);
|
LOG.info("Session id {} swapped for new id {}", oldId, newId);
|
||||||
return session;
|
return session;
|
||||||
|
@ -615,25 +674,37 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setPassivateOnComplete (boolean passivateOnComplete)
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.session.SessionCache#setSaveOnInactiveEviction(boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setSaveOnInactiveEviction (boolean saveOnEvict)
|
||||||
{
|
{
|
||||||
_passivateOnComplete = passivateOnComplete;
|
_saveOnInactiveEviction = saveOnEvict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isPassivateOnComplete ()
|
/**
|
||||||
|
* Whether we should save a session that has been inactive before
|
||||||
|
* we boot it from the cache.
|
||||||
|
*
|
||||||
|
* @return true if an inactive session will be saved before being evicted
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isSaveOnInactiveEviction ()
|
||||||
{
|
{
|
||||||
return _passivateOnComplete;
|
return _saveOnInactiveEviction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
|
* @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
|
public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
|
||||||
{
|
{
|
||||||
Session session = newSession(request, _sessionStore.newSessionData(id, time, time, time, maxInactiveMs));
|
if (LOG.isDebugEnabled()) LOG.debug("Creating new session id="+id);
|
||||||
session.setSessionHandler(_handler);
|
Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs));
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,11 @@ import java.util.Set;
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSessionStore
|
* AbstractSessionDataStore
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSessionStore extends AbstractLifeCycle implements SessionStore
|
public abstract class AbstractSessionDataStore extends AbstractLifeCycle implements SessionDataStore
|
||||||
{
|
{
|
||||||
protected SessionContext _context; //context associated with this session data store
|
protected SessionContext _context; //context associated with this session data store
|
||||||
protected int _gracePeriodSec = 60 * 60; //default of 1hr
|
protected int _gracePeriodSec = 60 * 60; //default of 1hr
|
||||||
|
@ -51,14 +51,14 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
||||||
* Implemented by subclasses to resolve which sessions this node
|
* Implemented by subclasses to resolve which sessions this node
|
||||||
* should attempt to expire.
|
* should attempt to expire.
|
||||||
*
|
*
|
||||||
* @param candidates the ids of sessions the SessionStore thinks has expired
|
* @param candidates the ids of sessions the SessionDataStore thinks has expired
|
||||||
* @return the reconciled set of session ids that this node should attempt to expire
|
* @return the reconciled set of session ids that this node should attempt to expire
|
||||||
*/
|
*/
|
||||||
public abstract Set<String> doGetExpired (Set<String> candidates);
|
public abstract Set<String> doGetExpired (Set<String> candidates);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#initialize(org.eclipse.jetty.server.session.SessionContext)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#initialize(org.eclipse.jetty.server.session.SessionContext)
|
||||||
*/
|
*/
|
||||||
public void initialize (SessionContext context)
|
public void initialize (SessionContext context)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void store(String id, SessionData data) throws Exception
|
public void store(String id, SessionData data) throws Exception
|
||||||
|
@ -94,7 +94,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(java.util.Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getExpired(Set<String> candidates)
|
public Set<String> getExpired(Set<String> candidates)
|
||||||
|
@ -113,7 +113,7 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#newSessionData(java.lang.String, long, long, long, long)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
|
@ -20,11 +20,11 @@
|
||||||
package org.eclipse.jetty.server.session;
|
package org.eclipse.jetty.server.session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSessionStoreFactory
|
* AbstractSessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSessionStoreFactory implements SessionStoreFactory
|
public abstract class AbstractSessionDataStoreFactory implements SessionDataStoreFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
int _gracePeriodSec;
|
int _gracePeriodSec;
|
|
@ -26,43 +26,42 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
/**
|
/**
|
||||||
* CachingSessionStore
|
* CachingSessionStore
|
||||||
*
|
*
|
||||||
* A SessionStore is a mechanism for (persistently) storing data associated with sessions.
|
* A SessionDataStore is a mechanism for (persistently) storing data associated with sessions.
|
||||||
* This implementation delegates to a pluggable SessionStore for actually storing the
|
* This implementation delegates to a pluggable SessionDataStore for actually storing the
|
||||||
* session data. It also uses a pluggable cache implementation in front of the
|
* session data. It also uses a pluggable cache implementation in front of the
|
||||||
* delegate SessionStore to improve performance: accessing most persistent store
|
* delegate SessionDataStore to improve performance: accessing most persistent store
|
||||||
* technology can be expensive time-wise, so introducing a fronting cache
|
* technology can be expensive time-wise, so introducing a fronting cache
|
||||||
* can increase performance. The cache implementation can either be a local cache,
|
* can increase performance. The cache implementation can either be a local cache,
|
||||||
* a remote cache, or a clustered cache. If the cache is cluster-wide then this can
|
* a remote cache, or a clustered cache.
|
||||||
* help with deployments without a sticky load balancer (but this is not ideal).
|
*
|
||||||
|
* The implementation here will try to read first from the cache and fallback to
|
||||||
|
* reading from the SessionDataStore if the session key is not found. On writes, the
|
||||||
|
* session data is written first to the SessionDataStore, and then to the cache. On
|
||||||
|
* deletes, the data is deleted first from the SessionDataStore, and then from the
|
||||||
|
* cache. There is no transaction manager ensuring atomic operations, so it is
|
||||||
|
* possible that failures can result in cache inconsistency.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class CachingSessionStore extends AbstractLifeCycle implements SessionStore
|
public class CachingSessionStore extends AbstractLifeCycle implements SessionDataStore
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache
|
* The actual store for the session data
|
||||||
*
|
|
||||||
* An interface that represents the contract with the particular cache
|
|
||||||
* implementation, eg memcache, infinispan etc
|
|
||||||
*/
|
*/
|
||||||
public interface Cache
|
protected SessionDataStore _store;
|
||||||
{
|
|
||||||
public SessionData get (String id); //get cached value
|
|
||||||
public boolean putIfAbsent (String id, SessionData data); //only insert if no mapping for key already
|
|
||||||
public boolean remove (String id); //remove the mapping for key, returns false if no mapping
|
|
||||||
public void put (String id, SessionData data); //overwrite or add the mapping
|
|
||||||
public void initialize(SessionContext context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected SessionStore _store;
|
/**
|
||||||
protected Cache _cache;
|
* The fronting cache
|
||||||
|
*/
|
||||||
|
protected SessionDataMap _cache;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cache
|
* @param cache
|
||||||
* @param store
|
* @param store
|
||||||
*/
|
*/
|
||||||
public CachingSessionStore (Cache cache, SessionStore store)
|
public CachingSessionStore (SessionDataMap cache, SessionDataStore store)
|
||||||
{
|
{
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
_store = store;
|
_store = store;
|
||||||
|
@ -70,9 +69,9 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return the delegate session store
|
||||||
*/
|
*/
|
||||||
public SessionStore getSessionStore()
|
public SessionDataStore getSessionStore()
|
||||||
{
|
{
|
||||||
return _store;
|
return _store;
|
||||||
}
|
}
|
||||||
|
@ -80,63 +79,52 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return the cache
|
||||||
*/
|
*/
|
||||||
public Cache getSessionStoreCache ()
|
public SessionDataMap getCache ()
|
||||||
{
|
{
|
||||||
return _cache;
|
return _cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
{
|
{
|
||||||
|
SessionData d = null;
|
||||||
|
|
||||||
|
|
||||||
//check to see if the session data is already in the cache
|
//check to see if the session data is already in the cache
|
||||||
SessionData d = _cache.get(id);
|
d = _cache.load(id);
|
||||||
if (d == null)
|
|
||||||
{
|
|
||||||
//not in the cache, go get it from the store
|
|
||||||
d = _store.load(id);
|
|
||||||
|
|
||||||
if (d != null)
|
if (d != null)
|
||||||
{
|
return d; //cache hit
|
||||||
//put it into the cache, unless another thread/node has put it into the cache
|
|
||||||
boolean inserted = _cache.putIfAbsent(id, d);
|
//cache miss - go get it from the store
|
||||||
if (!inserted)
|
d = _store.load(id);
|
||||||
{
|
|
||||||
//some other thread/node put this data into the cache, so get it from there
|
|
||||||
SessionData d2 = _cache.get(id);
|
|
||||||
|
|
||||||
if (d2 != null)
|
|
||||||
d = d2;
|
|
||||||
//else: The cache either timed out the entry, or maybe the session data was being removed, and we're about to resurrect it!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
{
|
{
|
||||||
//delete from the store and from the cache
|
//delete from the store
|
||||||
boolean deleted = _store.delete(id);
|
boolean deleted = _store.delete(id);
|
||||||
|
//and from the cache
|
||||||
//TODO what to do if couldn't remove from the cache?
|
_cache.delete(id);
|
||||||
_cache.remove(id);
|
|
||||||
|
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getExpired(Set<String> candidates)
|
public Set<String> getExpired(Set<String> candidates)
|
||||||
|
@ -145,8 +133,10 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
return _store.getExpired(candidates);
|
return _store.getExpired(candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void store(String id, SessionData data) throws Exception
|
public void store(String id, SessionData data) throws Exception
|
||||||
|
@ -155,7 +145,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
_store.store(id, data);
|
_store.store(id, data);
|
||||||
|
|
||||||
//then update the cache with written data
|
//then update the cache with written data
|
||||||
_cache.put(id,data);
|
_cache.store(id,data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,7 +163,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
||||||
|
@ -182,13 +172,13 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id) throws Exception
|
public boolean exists(String id) throws Exception
|
||||||
{
|
{
|
||||||
//check the cache first
|
//check the cache first
|
||||||
SessionData data = _cache.get(id);
|
SessionData data = _cache.load(id);
|
||||||
if (data != null)
|
if (data != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -198,7 +188,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#initialize(org.eclipse.jetty.server.session.SessionContext)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#initialize(org.eclipse.jetty.server.session.SessionContext)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(SessionContext context)
|
public void initialize(SessionContext context)
|
||||||
|
@ -209,7 +199,7 @@ public class CachingSessionStore extends AbstractLifeCycle implements SessionSto
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#newSessionData(java.lang.String, long, long, long, long)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
||||||
|
|
|
@ -24,34 +24,34 @@ package org.eclipse.jetty.server.session;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CachingSessionStoreFactory extends AbstractSessionStoreFactory
|
public class CachingSessionStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SessionStore that will store session data.
|
* The SessionDataStore that will store session data.
|
||||||
*/
|
*/
|
||||||
protected SessionStoreFactory _backingSessionStoreFactory;
|
protected SessionDataStoreFactory _backingSessionStoreFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param factory The factory for the actual SessionStore that the
|
* @param factory The factory for the actual SessionDataStore that the
|
||||||
* CachingSessionStore will delegate to
|
* CachingSessionStore will delegate to
|
||||||
*/
|
*/
|
||||||
public void setBackingSessionStoreFactory (SessionStoreFactory factory)
|
public void setBackingSessionStoreFactory (SessionDataStoreFactory factory)
|
||||||
{
|
{
|
||||||
_backingSessionStoreFactory = factory;
|
_backingSessionStoreFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionStore getSessionStore(SessionHandler handler) throws Exception
|
public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception
|
||||||
{
|
{
|
||||||
// TODO configure and create a cache!
|
// TODO configure and create a cache!
|
||||||
return new CachingSessionStore(null, _backingSessionStoreFactory.getSessionStore(handler));
|
return new CachingSessionStore(null, _backingSessionStoreFactory.getSessionDataStore(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,14 +146,14 @@ public class DefaultSessionCache extends AbstractSessionCache
|
||||||
for (Session session: _sessions.values())
|
for (Session session: _sessions.values())
|
||||||
{
|
{
|
||||||
//if we have a backing store and the session is dirty make sure it is written out
|
//if we have a backing store and the session is dirty make sure it is written out
|
||||||
if (_sessionStore != null)
|
if (_sessionDataStore != null)
|
||||||
{
|
{
|
||||||
if (session.getSessionData().isDirty())
|
if (session.getSessionData().isDirty())
|
||||||
{
|
{
|
||||||
session.willPassivate();
|
session.willPassivate();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_sessionStore.store(session.getId(), session.getSessionData());
|
_sessionDataStore.store(session.getId(), session.getSessionData());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -186,7 +186,7 @@ public class DefaultSessionCache extends AbstractSessionCache
|
||||||
@Override
|
@Override
|
||||||
public Session newSession(HttpServletRequest request, SessionData data)
|
public Session newSession(HttpServletRequest request, SessionData data)
|
||||||
{
|
{
|
||||||
Session s = new Session(request,data);
|
Session s = new Session(getSessionHandler(),request, data);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ public class DefaultSessionCache extends AbstractSessionCache
|
||||||
@Override
|
@Override
|
||||||
public Session newSession(SessionData data)
|
public Session newSession(SessionData data)
|
||||||
{
|
{
|
||||||
Session s = new Session (data);
|
Session s = new Session (getSessionHandler(), data);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,53 +26,54 @@ package org.eclipse.jetty.server.session;
|
||||||
*/
|
*/
|
||||||
public class DefaultSessionCacheFactory implements SessionCacheFactory
|
public class DefaultSessionCacheFactory implements SessionCacheFactory
|
||||||
{
|
{
|
||||||
int _idlePassivationTimeoutSec;
|
int _evictionTimeout;
|
||||||
boolean _passivateOnComplete;
|
boolean _saveOnInactiveEvict;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the passivateOnComplete
|
|
||||||
*/
|
public int getEvictionTimeout()
|
||||||
public boolean isPassivateOnComplete()
|
|
||||||
{
|
{
|
||||||
return _passivateOnComplete;
|
return _evictionTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param passivateOnComplete the passivateOnComplete to set
|
|
||||||
*/
|
|
||||||
public void setPassivateOnComplete(boolean passivateOnComplete)
|
|
||||||
{
|
|
||||||
_passivateOnComplete = passivateOnComplete;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the idlePassivationTimeoutSec
|
public void setEvictionTimeout(int evictionTimeout)
|
||||||
*/
|
|
||||||
public int getIdlePassivationTimeoutSec()
|
|
||||||
{
|
{
|
||||||
return _idlePassivationTimeoutSec;
|
_evictionTimeout = evictionTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param idlePassivationTimeoutSec the idlePassivationTimeoutSec to set
|
|
||||||
*/
|
public boolean isSaveOnInactiveEvict()
|
||||||
public void setIdlePassivationTimeoutSec(int idlePassivationTimeoutSec)
|
|
||||||
{
|
{
|
||||||
_idlePassivationTimeoutSec = idlePassivationTimeoutSec;
|
return _saveOnInactiveEvict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setSaveOnInactiveEvict(boolean saveOnInactiveEvict)
|
||||||
|
{
|
||||||
|
_saveOnInactiveEvict = saveOnInactiveEvict;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionCacheFactory#getSessionCache(SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionCacheFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionCache getSessionCache (SessionHandler handler)
|
public SessionCache getSessionCache (SessionHandler handler)
|
||||||
{
|
{
|
||||||
DefaultSessionCache cache = new DefaultSessionCache(handler);
|
DefaultSessionCache cache = new DefaultSessionCache(handler);
|
||||||
cache.setIdlePassivationTimeoutSec(_idlePassivationTimeoutSec);
|
cache.setEvictionPolicy(_evictionTimeout);
|
||||||
cache.setPassivateOnComplete(_passivateOnComplete);
|
cache.setSaveOnInactiveEviction(_saveOnInactiveEvict);
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
|
||||||
return cluster_id;
|
return cluster_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Else reuse any new session ID already defined for this request.
|
// Else reuse any new session ID already defined for this request.
|
||||||
String new_id=(String)request.getAttribute(__NEW_SESSION_ID);
|
String new_id=(String)request.getAttribute(__NEW_SESSION_ID);
|
||||||
if (new_id!=null&&isIdInUse(new_id))
|
if (new_id!=null&&isIdInUse(new_id))
|
||||||
|
|
|
@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileSessionStore
|
* FileSessionDataStore
|
||||||
*
|
*
|
||||||
* A file-based store of session data.
|
* A file-based store of session data.
|
||||||
*/
|
*/
|
||||||
public class FileSessionStore extends AbstractSessionStore
|
public class FileSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
private File _storeDir;
|
private File _storeDir;
|
||||||
|
@ -92,7 +92,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -112,7 +112,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(final Set<String> candidates)
|
public Set<String> doGetExpired(final Set<String> candidates)
|
||||||
|
@ -166,7 +166,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -220,7 +220,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -262,7 +262,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
||||||
|
@ -274,7 +274,7 @@ public class FileSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id) throws Exception
|
public boolean exists(String id) throws Exception
|
|
@ -22,11 +22,11 @@ package org.eclipse.jetty.server.session;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileSessionStoreFactory
|
* FileSessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FileSessionStoreFactory extends AbstractSessionStoreFactory
|
public class FileSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
boolean _deleteUnrestorableFiles;
|
boolean _deleteUnrestorableFiles;
|
||||||
File _storeDir;
|
File _storeDir;
|
||||||
|
@ -69,12 +69,12 @@ public class FileSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionStore getSessionStore(SessionHandler handler)
|
public SessionDataStore getSessionDataStore(SessionHandler handler)
|
||||||
{
|
{
|
||||||
FileSessionStore fsds = new FileSessionStore();
|
FileSessionDataStore fsds = new FileSessionDataStore();
|
||||||
fsds.setDeleteUnrestorableFiles(isDeleteUnrestorableFiles());
|
fsds.setDeleteUnrestorableFiles(isDeleteUnrestorableFiles());
|
||||||
fsds.setStoreDir(getStoreDir());
|
fsds.setStoreDir(getStoreDir());
|
||||||
fsds.setGracePeriodSec(getGracePeriodSec());
|
fsds.setGracePeriodSec(getGracePeriodSec());
|
|
@ -42,11 +42,11 @@ import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDBCSessionStore
|
* JDBCSessionDataStore
|
||||||
*
|
*
|
||||||
* Session data stored in database
|
* Session data stored in database
|
||||||
*/
|
*/
|
||||||
public class JDBCSessionStore extends AbstractSessionStore
|
public class JDBCSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public JDBCSessionStore ()
|
public JDBCSessionDataStore ()
|
||||||
{
|
{
|
||||||
super ();
|
super ();
|
||||||
}
|
}
|
||||||
|
@ -662,7 +662,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -758,7 +758,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -779,7 +779,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -884,7 +884,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(Set<String> candidates)
|
public Set<String> doGetExpired(Set<String> candidates)
|
||||||
|
@ -1083,7 +1083,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
||||||
|
@ -1096,7 +1096,7 @@ public class JDBCSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id)
|
public boolean exists(String id)
|
|
@ -20,11 +20,11 @@
|
||||||
package org.eclipse.jetty.server.session;
|
package org.eclipse.jetty.server.session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDBCSessionStoreFactory
|
* JDBCSessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory
|
public class JDBCSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
JDBCSessionStore.SessionTableSchema _schema;
|
JDBCSessionDataStore.SessionTableSchema _schema;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -82,12 +82,12 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionStore getSessionStore(SessionHandler handler)
|
public SessionDataStore getSessionDataStore(SessionHandler handler)
|
||||||
{
|
{
|
||||||
JDBCSessionStore ds = new JDBCSessionStore();
|
JDBCSessionDataStore ds = new JDBCSessionDataStore();
|
||||||
ds.setDatabaseAdaptor(_adaptor);
|
ds.setDatabaseAdaptor(_adaptor);
|
||||||
ds.setSessionTableSchema(_schema);
|
ds.setSessionTableSchema(_schema);
|
||||||
ds.setDeleteUnloadableSessions(_deleteUnloadableSessions);
|
ds.setDeleteUnloadableSessions(_deleteUnloadableSessions);
|
||||||
|
@ -109,7 +109,7 @@ public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory
|
||||||
/**
|
/**
|
||||||
* @param schema
|
* @param schema
|
||||||
*/
|
*/
|
||||||
public void setSessionTableSchema (JDBCSessionStore.SessionTableSchema schema)
|
public void setSessionTableSchema (JDBCSessionDataStore.SessionTableSchema schema)
|
||||||
{
|
{
|
||||||
_schema = schema;
|
_schema = schema;
|
||||||
}
|
}
|
|
@ -22,15 +22,15 @@ package org.eclipse.jetty.server.session;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NullSessionStore
|
* NullSessionDataStore
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NullSessionStore extends AbstractSessionStore
|
public class NullSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData load(String id) throws Exception
|
public SessionData load(String id) throws Exception
|
||||||
|
@ -40,7 +40,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSessionData(java.lang.String, long, long, long, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#newSessionData(java.lang.String, long, long, long, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
||||||
|
@ -49,7 +49,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(String id) throws Exception
|
public boolean delete(String id) throws Exception
|
||||||
|
@ -59,7 +59,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
|
@ -69,7 +69,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> doGetExpired(Set<String> candidates)
|
public Set<String> doGetExpired(Set<String> candidates)
|
||||||
|
@ -79,7 +79,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
|
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPassivating()
|
public boolean isPassivating()
|
||||||
|
@ -89,7 +89,7 @@ public class NullSessionStore extends AbstractSessionStore
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
|
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String id)
|
public boolean exists(String id)
|
|
@ -68,12 +68,7 @@ public class Session implements SessionHandler.SessionIf
|
||||||
public enum State {VALID, INVALID, INVALIDATING};
|
public enum State {VALID, INVALID, INVALIDATING};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PassivationState
|
|
||||||
*
|
|
||||||
* States of a session - either active in memory or passivated to persistent store
|
|
||||||
*/
|
|
||||||
public enum PassivationState {PASSIVATED, ACTIVE};
|
|
||||||
|
|
||||||
|
|
||||||
protected SessionData _sessionData; //the actual data associated with a session
|
protected SessionData _sessionData; //the actual data associated with a session
|
||||||
|
@ -84,22 +79,25 @@ public class Session implements SessionHandler.SessionIf
|
||||||
private boolean _newSession;
|
private boolean _newSession;
|
||||||
private State _state = State.VALID; //state of the session:valid,invalid or being invalidated
|
private State _state = State.VALID; //state of the session:valid,invalid or being invalidated
|
||||||
private Locker _lock = new Locker(); //sync lock
|
private Locker _lock = new Locker(); //sync lock
|
||||||
private PassivationState _passivationState = PassivationState.ACTIVE; //passivated or not
|
private boolean _resident = false;
|
||||||
private InspectionTimeout _inspectionTimeout = null;
|
private SessionInactivityTimeout _sessionInactivityTimer = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* InspectionTimeout
|
* SessionInactivityTimeout
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InspectionTimeout extends IdleTimeout
|
public class SessionInactivityTimeout extends IdleTimeout
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public InspectionTimeout()
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public SessionInactivityTimeout()
|
||||||
{
|
{
|
||||||
super(getSessionHandler().getScheduler());
|
super(getSessionHandler().getScheduler());
|
||||||
}
|
}
|
||||||
|
@ -112,7 +110,7 @@ public class Session implements SessionHandler.SessionIf
|
||||||
{
|
{
|
||||||
//called when the timer goes off
|
//called when the timer goes off
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Timer expired for session {}", getId());
|
if (LOG.isDebugEnabled()) LOG.debug("Timer expired for session {}", getId());
|
||||||
getSessionHandler().inspect(Session.this);
|
getSessionHandler().sessionInactivityTimerExpired(Session.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +125,7 @@ public class Session implements SessionHandler.SessionIf
|
||||||
// BUT if passivated out to disk, do we really want this timer to keep going off?
|
// BUT if passivated out to disk, do we really want this timer to keep going off?
|
||||||
try (Lock lock = _lock.lockIfNotHeld())
|
try (Lock lock = _lock.lockIfNotHeld())
|
||||||
{
|
{
|
||||||
return isValid() && !isPassivated();
|
return isValid() && isResident();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,12 +146,13 @@ public class Session implements SessionHandler.SessionIf
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* Create a new session
|
* Create a new session
|
||||||
*
|
* @param handler TODO
|
||||||
* @param request the request the session should be based on
|
* @param request the request the session should be based on
|
||||||
* @param data the session data
|
* @param data the session data
|
||||||
*/
|
*/
|
||||||
public Session (HttpServletRequest request, SessionData data)
|
public Session (SessionHandler handler, HttpServletRequest request, SessionData data)
|
||||||
{
|
{
|
||||||
|
_handler = handler;
|
||||||
_sessionData = data;
|
_sessionData = data;
|
||||||
_newSession = true;
|
_newSession = true;
|
||||||
_requests = 1; //access will not be called on this new session, but we are obviously in a request
|
_requests = 1; //access will not be called on this new session, but we are obviously in a request
|
||||||
|
@ -164,10 +163,12 @@ public class Session implements SessionHandler.SessionIf
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* Re-create an existing session
|
* Re-create an existing session
|
||||||
|
* @param handler TODO
|
||||||
* @param data the session data
|
* @param data the session data
|
||||||
*/
|
*/
|
||||||
public Session (SessionData data)
|
public Session (SessionHandler handler, SessionData data)
|
||||||
{
|
{
|
||||||
|
_handler = handler;
|
||||||
_sessionData = data;
|
_sessionData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,11 +190,6 @@ public class Session implements SessionHandler.SessionIf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
|
||||||
public void setSessionHandler (SessionHandler manager)
|
|
||||||
{
|
|
||||||
_handler = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
|
@ -455,9 +451,9 @@ public class Session implements SessionHandler.SessionIf
|
||||||
try (Lock lock = _lock.lockIfNotHeld())
|
try (Lock lock = _lock.lockIfNotHeld())
|
||||||
{
|
{
|
||||||
_sessionData.setMaxInactiveMs((long)secs*1000L);
|
_sessionData.setMaxInactiveMs((long)secs*1000L);
|
||||||
_sessionData.setExpiry(_sessionData.calcExpiry());
|
_sessionData.calcAndSetExpiry();
|
||||||
_sessionData.setDirty(true);
|
_sessionData.setDirty(true);
|
||||||
setTimeout();
|
updateInactivityTimer();
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
{
|
{
|
||||||
if (secs <= 0)
|
if (secs <= 0)
|
||||||
|
@ -470,53 +466,77 @@ public class Session implements SessionHandler.SessionIf
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Set the inactivity timer to the smaller of the session maxInactivity
|
||||||
|
* (ie session-timeout from web.xml), or the inactive eviction time.
|
||||||
*/
|
*/
|
||||||
public void setTimeout ()
|
public void updateInactivityTimer ()
|
||||||
{
|
{
|
||||||
try (Lock lock = _lock.lockIfNotHeld())
|
try (Lock lock = _lock.lockIfNotHeld())
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())LOG.debug("Set timeout called");
|
if (LOG.isDebugEnabled())LOG.debug("updateInactivityTimer");
|
||||||
long maxInactive = _sessionData.getMaxInactiveMs();
|
|
||||||
long maxIdle = TimeUnit.SECONDS.toMillis(getSessionHandler().getSessionStore().getIdlePassivationTimeoutSec());
|
|
||||||
|
|
||||||
|
long maxInactive = _sessionData.getMaxInactiveMs();
|
||||||
|
int evictionPolicy = getSessionHandler().getSessionCache().getEvictionPolicy();
|
||||||
|
|
||||||
if (maxInactive <= 0 && maxIdle <=0)
|
|
||||||
{
|
|
||||||
//session is immortal and idle passivation is not supported
|
|
||||||
if (_inspectionTimeout != null)
|
|
||||||
_inspectionTimeout.setIdleTimeout(-1);
|
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Session maxInactive <= 0 && idlePassivation <=0: timer cancelled");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_inspectionTimeout == null)
|
|
||||||
_inspectionTimeout = new InspectionTimeout();
|
|
||||||
|
|
||||||
//set the inspection timer to the smaller of the maxIdle interval or the idlePassivation interval
|
|
||||||
long timeout = 0;
|
|
||||||
if (maxInactive <= 0)
|
if (maxInactive <= 0)
|
||||||
timeout = maxIdle;
|
{
|
||||||
else if (maxIdle <= 0)
|
//sessions are immortal, they never expire
|
||||||
timeout = maxInactive;
|
if (evictionPolicy < SessionCache.EVICT_ON_INACTIVITY)
|
||||||
|
{
|
||||||
|
//we do not want to evict inactive sessions
|
||||||
|
setInactivityTimer(-1L);
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("Session is immortal && never evict: timer cancelled");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//sessions are immortal but we want to evict after inactivity
|
||||||
|
setInactivityTimer(TimeUnit.SECONDS.toMillis(evictionPolicy));
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("Session is immortal; evict after {} sec inactivity", evictionPolicy);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
timeout = Math.min(maxInactive, maxIdle);
|
{
|
||||||
|
//sessions are not immortal
|
||||||
_inspectionTimeout.setIdleTimeout(timeout);
|
if (evictionPolicy < SessionCache.EVICT_ON_INACTIVITY)
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Session timer(ms)={}", timeout);
|
{
|
||||||
|
//don't want to evict inactive sessions, set the timer for the session's maxInactive setting
|
||||||
|
setInactivityTimer(_sessionData.getMaxInactiveMs());
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("No inactive session eviction");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//set the time to the lesser of the session's maxInactive and eviction timeout
|
||||||
|
setInactivityTimer(Math.min(maxInactive, TimeUnit.SECONDS.toMillis(evictionPolicy)));
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("Inactivity timer set to lesser of maxInactive={} and inactivityEvict={}", maxInactive, evictionPolicy);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the inactivity timer
|
||||||
|
*
|
||||||
|
* @param ms value in millisec, -1 disables it
|
||||||
|
*/
|
||||||
|
private void setInactivityTimer (long ms)
|
||||||
|
{
|
||||||
|
if (_sessionInactivityTimer == null)
|
||||||
|
_sessionInactivityTimer = new SessionInactivityTimeout();
|
||||||
|
_sessionInactivityTimer.setIdleTimeout(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void stopTimeout ()
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void stopInactivityTimer ()
|
||||||
{
|
{
|
||||||
try (Lock lock = _lock.lockIfNotHeld())
|
try (Lock lock = _lock.lockIfNotHeld())
|
||||||
{
|
{
|
||||||
if (_inspectionTimeout != null)
|
if (_sessionInactivityTimer != null)
|
||||||
{
|
{
|
||||||
_inspectionTimeout.setIdleTimeout(-1);
|
_sessionInactivityTimer.setIdleTimeout(-1);
|
||||||
_inspectionTimeout = null;
|
_sessionInactivityTimer = null;
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Session timer stopped");
|
if (LOG.isDebugEnabled()) LOG.debug("Session timer stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,8 +583,8 @@ public class Session implements SessionHandler.SessionIf
|
||||||
if (_state != State.VALID)
|
if (_state != State.VALID)
|
||||||
throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry());
|
throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry());
|
||||||
|
|
||||||
if (_passivationState == PassivationState.PASSIVATED)
|
if (!isResident())
|
||||||
throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" passivated");
|
throw new IllegalStateException("Not valid for write: id="+_sessionData.getId()+" not resident");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -580,8 +600,8 @@ public class Session implements SessionHandler.SessionIf
|
||||||
if (_state == State.INVALID)
|
if (_state == State.INVALID)
|
||||||
throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry());
|
throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" created="+_sessionData.getCreated()+" accessed="+_sessionData.getAccessed()+" lastaccessed="+_sessionData.getLastAccessed()+" maxInactiveMs="+_sessionData.getMaxInactiveMs()+" expiry="+_sessionData.getExpiry());
|
||||||
|
|
||||||
if (_passivationState == PassivationState.PASSIVATED)
|
if (!isResident())
|
||||||
throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" passivated");
|
throw new IllegalStateException("Invalid for read: id="+_sessionData.getId()+" not resident");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -762,32 +782,7 @@ public class Session implements SessionHandler.SessionIf
|
||||||
setIdChanged(true);
|
setIdChanged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
|
||||||
/* * Swap the id on a session from old to new, keeping the object
|
|
||||||
* the same.
|
|
||||||
*
|
|
||||||
* @param oldId
|
|
||||||
* @param oldExtendedId
|
|
||||||
* @param newId
|
|
||||||
* @param newExtendedId
|
|
||||||
*/
|
|
||||||
/* public void renewId (String oldId, String oldExtendedId, String newId, String newExtendedId)
|
|
||||||
{
|
|
||||||
try (Lock lock = _lock.lockIfNotHeld())
|
|
||||||
{
|
|
||||||
checkValidForWrite(); //can't change id on invalid session
|
|
||||||
|
|
||||||
if (!oldId.equals(getId()))
|
|
||||||
throw new IllegalStateException("Id clash detected on renewal: was "+oldId+" but is "+ getId());
|
|
||||||
|
|
||||||
_sessionData.setId(newId);
|
|
||||||
setExtendedId(newExtendedId);
|
|
||||||
_sessionData.setLastSaved(0); //forces an insert
|
|
||||||
_sessionData.setDirty(true); //forces an insert
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/** Called by users to invalidate a session, or called by the
|
/** Called by users to invalidate a session, or called by the
|
||||||
* access method as a request enters the session if the session
|
* access method as a request enters the session if the session
|
||||||
|
@ -934,36 +929,14 @@ public class Session implements SessionHandler.SessionIf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setResident (boolean resident)
|
||||||
|
{
|
||||||
|
_resident = resident;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public boolean isResident ()
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setPassivated ()
|
|
||||||
{
|
{
|
||||||
checkLocked();
|
return _resident;
|
||||||
_passivationState = PassivationState.PASSIVATED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setActive ()
|
|
||||||
{
|
|
||||||
checkLocked();
|
|
||||||
_passivationState = PassivationState.ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive ()
|
|
||||||
{
|
|
||||||
checkLocked();
|
|
||||||
return _passivationState == PassivationState.ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPassivated ()
|
|
||||||
{
|
|
||||||
checkLocked();
|
|
||||||
return _passivationState == PassivationState.PASSIVATED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,39 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SessionStore
|
* SessionCache
|
||||||
*
|
*
|
||||||
* A store of Session objects. This store of Session objects can be backed by
|
* A set of Session objects for a context that are actively being
|
||||||
* a SessionDataStore to persist/distribute the data contained in the Session objects.
|
* managed by this context instance.
|
||||||
*
|
*
|
||||||
* This store of Session objects ensures that all threads within the same context on
|
* Multiple requests for the same session id on the same context should always
|
||||||
* the same node with the same session id will share exactly the same Session object.
|
* share the same Session object from the SessionCache.
|
||||||
|
*
|
||||||
|
* The data for the Session objects is obtained from, and written to a SessionDataStore.
|
||||||
|
* It is assumed that the SessionDataStore is the authoritative source of session data:
|
||||||
|
* <ul>
|
||||||
|
* <li>if the session data is not present in the SessionDataStore the session does not exist.</li>
|
||||||
|
* <li>if the session data is present in the SessionDataStore but its expiry time has passed then
|
||||||
|
* the session is deemed to have expired</li>
|
||||||
|
*</ul>
|
||||||
|
*
|
||||||
|
* Examples of SessionDataStores are relational or nosql databases, filesystems, or other
|
||||||
|
* distributed mechanisms.
|
||||||
|
*
|
||||||
|
* A SessionCache is optionally able to passivate a managed Session to the SessionDataStore and
|
||||||
|
* evict it from the cache if it has been in memory, but not accessed for a configurable amount of time.
|
||||||
|
*
|
||||||
|
* Implementations of the SessionCache may also implement different strategies for writing out
|
||||||
|
* Session data to the SessionDataStore.
|
||||||
*/
|
*/
|
||||||
public interface SessionCache extends LifeCycle
|
public interface SessionCache extends LifeCycle
|
||||||
{
|
{
|
||||||
|
public static final int NEVER_EVICT = -1;
|
||||||
|
public static final int EVICT_ON_SESSION_EXIT = 0;
|
||||||
|
public static final int EVICT_ON_INACTIVITY = 1; //any number equal or greater is time in seconds
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void initialize(SessionContext context);
|
void initialize(SessionContext context);
|
||||||
SessionHandler getSessionHandler();
|
SessionHandler getSessionHandler();
|
||||||
Session newSession (HttpServletRequest request, String id, long time, long maxInactiveMs);
|
Session newSession (HttpServletRequest request, String id, long time, long maxInactiveMs);
|
||||||
|
@ -47,9 +70,11 @@ public interface SessionCache extends LifeCycle
|
||||||
Session delete (String id) throws Exception;
|
Session delete (String id) throws Exception;
|
||||||
void shutdown ();
|
void shutdown ();
|
||||||
Set<String> checkExpiration (Set<String> candidates);
|
Set<String> checkExpiration (Set<String> candidates);
|
||||||
void setIdlePassivationTimeoutSec(int sec);
|
SessionDataStore getSessionDataStore();
|
||||||
int getIdlePassivationTimeoutSec();
|
void setSessionDataStore(SessionDataStore sds);
|
||||||
SessionStore getSessionStore();
|
void checkInactiveSession(Session session);
|
||||||
void setSessionStore(SessionStore sds);
|
void setEvictionPolicy (int policy);
|
||||||
void passivateIdleSession(String id);
|
int getEvictionPolicy ();
|
||||||
|
void setSaveOnInactiveEviction (boolean saveOnEvict);
|
||||||
|
boolean isSaveOnInactiveEviction ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class SessionData implements Serializable
|
||||||
_accessed = accessed;
|
_accessed = accessed;
|
||||||
_lastAccessed = lastAccessed;
|
_lastAccessed = lastAccessed;
|
||||||
_maxInactiveMs = maxInactiveMs;
|
_maxInactiveMs = maxInactiveMs;
|
||||||
_expiry = calcExpiry();
|
calcAndSetExpiry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,6 +250,11 @@ public class SessionData implements Serializable
|
||||||
{
|
{
|
||||||
return (getMaxInactiveMs() <= 0 ? 0 : (System.currentTimeMillis() + getMaxInactiveMs()));
|
return (getMaxInactiveMs() <= 0 ? 0 : (System.currentTimeMillis() + getMaxInactiveMs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void calcAndSetExpiry ()
|
||||||
|
{
|
||||||
|
setExpiry(calcExpiry());
|
||||||
|
}
|
||||||
|
|
||||||
public long getCreated()
|
public long getCreated()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.server.session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SessionDataMap
|
||||||
|
*
|
||||||
|
* A map style access to SessionData keyed by the session id.
|
||||||
|
*/
|
||||||
|
public interface SessionDataMap
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initialize this session data store for the
|
||||||
|
* given context. A SessionDataStore can only
|
||||||
|
* be used by one context(/session manager).
|
||||||
|
*
|
||||||
|
* @param context context associated
|
||||||
|
*/
|
||||||
|
void initialize(SessionContext context);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read in session data from storage
|
||||||
|
* @param id identity of session to load
|
||||||
|
* @return the SessionData matching the id
|
||||||
|
* @throws Exception if unable to load session data
|
||||||
|
*/
|
||||||
|
public SessionData load (String id) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write out session data to storage
|
||||||
|
* @param id identity of session to store
|
||||||
|
* @param data info of session to store
|
||||||
|
* @throws Exception if unable to write session data
|
||||||
|
*/
|
||||||
|
public void store (String id, SessionData data) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete session data from storage
|
||||||
|
* @param id identity of session to delete
|
||||||
|
* @return true if the session was deleted from the permanent store
|
||||||
|
* @throws Exception if unable to delete session data
|
||||||
|
*/
|
||||||
|
public boolean delete (String id) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -24,32 +24,13 @@ import java.util.Set;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SessionStore
|
* SessionDataStore
|
||||||
*
|
*
|
||||||
* A store for the data contained in a Session object. The store
|
* A store for the data contained in a Session object. The store
|
||||||
* would usually be persistent.
|
* would usually be persistent.
|
||||||
*/
|
*/
|
||||||
public interface SessionStore extends LifeCycle
|
public interface SessionDataStore extends SessionDataMap, LifeCycle
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Initialize this session data store for the
|
|
||||||
* given context. A SessionDataStore can only
|
|
||||||
* be used by one context(/session manager).
|
|
||||||
*
|
|
||||||
* @param context context associated
|
|
||||||
*/
|
|
||||||
void initialize(SessionContext context);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read in session data from storage
|
|
||||||
* @param id identity of session to load
|
|
||||||
* @return the SessionData matching the id
|
|
||||||
* @throws Exception if unable to load session data
|
|
||||||
*/
|
|
||||||
public SessionData load (String id) throws Exception;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new SessionData
|
* Create a new SessionData
|
||||||
|
@ -63,35 +44,13 @@ public interface SessionStore extends LifeCycle
|
||||||
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
|
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write out session data to storage
|
|
||||||
* @param id identity of session to store
|
|
||||||
* @param data info of session to store
|
|
||||||
* @throws Exception if unable to write session data
|
|
||||||
*/
|
|
||||||
public void store (String id, SessionData data) throws Exception;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete session data from storage
|
|
||||||
* @param id identity of session to delete
|
|
||||||
* @return true if the session was deleted from the permanent store
|
|
||||||
* @throws Exception if unable to delete session data
|
|
||||||
*/
|
|
||||||
public boolean delete (String id) throws Exception;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called periodically, this method should search the data store
|
* Called periodically, this method should search the data store
|
||||||
* for sessions that have been expired for a 'reasonable' amount
|
* for sessions that have been expired for a 'reasonable' amount
|
||||||
* of time.
|
* of time.
|
||||||
* @param candidates if provided, these are keys of sessions that
|
* @param candidates if provided, these are keys of sessions that
|
||||||
* the SessionStore thinks has expired and should be verified by the
|
* the SessionDataStore thinks has expired and should be verified by the
|
||||||
* SessionDataStore
|
* SessionDataStore
|
||||||
* @return set of session ids
|
* @return set of session ids
|
||||||
*/
|
*/
|
|
@ -20,11 +20,11 @@
|
||||||
package org.eclipse.jetty.server.session;
|
package org.eclipse.jetty.server.session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SessionStoreFactory
|
* SessionDataStoreFactory
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface SessionStoreFactory
|
public interface SessionDataStoreFactory
|
||||||
{
|
{
|
||||||
SessionStore getSessionStore (SessionHandler handler) throws Exception;
|
SessionDataStore getSessionDataStore (SessionHandler handler) throws Exception;
|
||||||
}
|
}
|
|
@ -31,6 +31,8 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
import javax.servlet.AsyncEvent;
|
||||||
|
import javax.servlet.AsyncListener;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.SessionCookieConfig;
|
import javax.servlet.SessionCookieConfig;
|
||||||
|
@ -144,6 +146,49 @@ public class SessionHandler extends ScopedHandler
|
||||||
* max number of minutes that you can set.
|
* max number of minutes that you can set.
|
||||||
*/
|
*/
|
||||||
public final static java.math.BigDecimal MAX_INACTIVE_MINUTES = new java.math.BigDecimal(Integer.MAX_VALUE/60);
|
public final static java.math.BigDecimal MAX_INACTIVE_MINUTES = new java.math.BigDecimal(Integer.MAX_VALUE/60);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SessionAsyncListener
|
||||||
|
*
|
||||||
|
* Used to ensure that a request for which async has been started
|
||||||
|
* has its session completed as the request exits the context.
|
||||||
|
*/
|
||||||
|
public class SessionAsyncListener implements AsyncListener
|
||||||
|
{
|
||||||
|
private Session _session;
|
||||||
|
|
||||||
|
public SessionAsyncListener(Session session)
|
||||||
|
{
|
||||||
|
_session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete(AsyncEvent event) throws IOException
|
||||||
|
{
|
||||||
|
//An async request has completed, so we can complete the session
|
||||||
|
complete(((HttpServletRequest)event.getAsyncContext().getRequest()).getSession(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeout(AsyncEvent event) throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(AsyncEvent event) throws IOException
|
||||||
|
{
|
||||||
|
complete(((HttpServletRequest)event.getAsyncContext().getRequest()).getSession(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartAsync(AsyncEvent event) throws IOException
|
||||||
|
{
|
||||||
|
event.getAsyncContext().addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static final HttpSessionContext __nullSessionContext=new HttpSessionContext()
|
static final HttpSessionContext __nullSessionContext=new HttpSessionContext()
|
||||||
{
|
{
|
||||||
|
@ -161,6 +206,8 @@ public class SessionHandler extends ScopedHandler
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setting of max inactive interval for new sessions
|
* Setting of max inactive interval for new sessions
|
||||||
|
@ -310,6 +357,9 @@ public class SessionHandler extends ScopedHandler
|
||||||
*/
|
*/
|
||||||
public void complete(HttpSession session)
|
public void complete(HttpSession session)
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
Session s = ((SessionIf)session).getSession();
|
Session s = ((SessionIf)session).getSession();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -322,6 +372,24 @@ public class SessionHandler extends ScopedHandler
|
||||||
LOG.warn(e);
|
LOG.warn(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void complete (Session session, Request request)
|
||||||
|
{
|
||||||
|
if (request.isAsyncStarted() && request.getDispatcherType() == DispatcherType.REQUEST)
|
||||||
|
{
|
||||||
|
request.getAsyncContext().addListener(new SessionAsyncListener(session));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
complete(session);
|
||||||
|
}
|
||||||
|
//if dispatcher type is not async and not request, complete immediately (its a forward or an include)
|
||||||
|
|
||||||
|
//else if dispatcher type is request and not async, complete immediately
|
||||||
|
|
||||||
|
//else register an async callback completion listener that will complete the session
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -341,7 +409,7 @@ public class SessionHandler extends ScopedHandler
|
||||||
|
|
||||||
synchronized (server)
|
synchronized (server)
|
||||||
{
|
{
|
||||||
//Get a SessionStore and a SessionDataStore, falling back to in-memory sessions only
|
//Get a SessionDataStore and a SessionDataStore, falling back to in-memory sessions only
|
||||||
if (_sessionCache == null)
|
if (_sessionCache == null)
|
||||||
{
|
{
|
||||||
SessionCacheFactory ssFactory = server.getBean(SessionCacheFactory.class);
|
SessionCacheFactory ssFactory = server.getBean(SessionCacheFactory.class);
|
||||||
|
@ -350,14 +418,14 @@ public class SessionHandler extends ScopedHandler
|
||||||
else
|
else
|
||||||
_sessionCache = new DefaultSessionCache(this);
|
_sessionCache = new DefaultSessionCache(this);
|
||||||
|
|
||||||
SessionStore sds = null;
|
SessionDataStore sds = null;
|
||||||
SessionStoreFactory sdsFactory = server.getBean(SessionStoreFactory.class);
|
SessionDataStoreFactory sdsFactory = server.getBean(SessionDataStoreFactory.class);
|
||||||
if (sdsFactory != null)
|
if (sdsFactory != null)
|
||||||
sds = sdsFactory.getSessionStore(this);
|
sds = sdsFactory.getSessionDataStore(this);
|
||||||
else
|
else
|
||||||
sds = new NullSessionStore();
|
sds = new NullSessionDataStore();
|
||||||
|
|
||||||
_sessionCache.setSessionStore(sds);
|
_sessionCache.setSessionDataStore(sds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -730,11 +798,12 @@ public class SessionHandler extends ScopedHandler
|
||||||
Session session = _sessionCache.newSession(request, id, created, (_dftMaxIdleSecs>0?_dftMaxIdleSecs*1000L:-1));
|
Session session = _sessionCache.newSession(request, id, created, (_dftMaxIdleSecs>0?_dftMaxIdleSecs*1000L:-1));
|
||||||
session.setExtendedId(_sessionIdManager.getExtendedId(id, request));
|
session.setExtendedId(_sessionIdManager.getExtendedId(id, request));
|
||||||
session.getSessionData().setLastNode(_sessionIdManager.getWorkerName());
|
session.getSessionData().setLastNode(_sessionIdManager.getWorkerName());
|
||||||
session.setMaxInactiveInterval(_dftMaxIdleSecs>0?_dftMaxIdleSecs:-1); //TODO awkward: needed to kick off timer and calc expiry
|
|
||||||
if (request.isSecure())
|
if (request.isSecure())
|
||||||
session.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
|
session.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
_sessionCache.put(id, session);
|
_sessionCache.put(id, session);
|
||||||
_sessionsCreatedStats.increment();
|
_sessionsCreatedStats.increment();
|
||||||
|
|
||||||
|
@ -934,15 +1003,15 @@ public class SessionHandler extends ScopedHandler
|
||||||
/**
|
/**
|
||||||
* @return the session store
|
* @return the session store
|
||||||
*/
|
*/
|
||||||
public SessionCache getSessionStore ()
|
public SessionCache getSessionCache ()
|
||||||
{
|
{
|
||||||
return _sessionCache;
|
return _sessionCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSessionStore (SessionCache store)
|
public void setSessionCache (SessionCache cache)
|
||||||
{
|
{
|
||||||
_sessionCache = store;
|
_sessionCache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -1214,7 +1283,18 @@ public class SessionHandler extends ScopedHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void inspect (Session session)
|
/**
|
||||||
|
* Each session has a timer that is configured to go off
|
||||||
|
* when either the session has not been accessed for a
|
||||||
|
* configurable amount of time, or the session itself
|
||||||
|
* has passed its expiry.
|
||||||
|
* <ul>
|
||||||
|
* <li> for being expired </li>
|
||||||
|
* <li> for being idle </li>
|
||||||
|
* </ul>
|
||||||
|
* @param session
|
||||||
|
*/
|
||||||
|
public void sessionInactivityTimerExpired (Session session)
|
||||||
{
|
{
|
||||||
if (session == null)
|
if (session == null)
|
||||||
return;
|
return;
|
||||||
|
@ -1223,8 +1303,8 @@ public class SessionHandler extends ScopedHandler
|
||||||
//check if the session is:
|
//check if the session is:
|
||||||
//1. valid
|
//1. valid
|
||||||
//2. expired
|
//2. expired
|
||||||
//3. passivatable
|
//3. idle
|
||||||
boolean passivate = false;
|
boolean expired = false;
|
||||||
try (Lock lock = session.lock())
|
try (Lock lock = session.lock())
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
|
@ -1233,22 +1313,24 @@ public class SessionHandler extends ScopedHandler
|
||||||
if (!session.isValid())
|
if (!session.isValid())
|
||||||
return; //do nothing, session is no longer valid
|
return; //do nothing, session is no longer valid
|
||||||
|
|
||||||
if (session.isExpiredAt(System.currentTimeMillis()))
|
if (session.isExpiredAt(System.currentTimeMillis()) && session.getRequests() <=0)
|
||||||
{
|
expired = true;
|
||||||
_candidateSessionIdsForExpiry.add(session.getId());
|
|
||||||
if (LOG.isDebugEnabled())LOG.debug("Session {} is candidate for expiry", session.getId());
|
|
||||||
}
|
|
||||||
else if (_sessionCache.getIdlePassivationTimeoutSec() > 0 && session.isIdleLongerThan(_sessionCache.getIdlePassivationTimeoutSec()))
|
|
||||||
{
|
|
||||||
passivate = true;
|
|
||||||
if (LOG.isDebugEnabled())LOG.debug("Session {} will be passivated", session.getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (passivate)
|
if (expired)
|
||||||
_sessionCache.passivateIdleSession(session.getId()); //TODO call passivate inside lock
|
{
|
||||||
|
//instead of expiring the session directly here, accumulate a list of
|
||||||
|
//session ids that need to be expired. This is an efficiency measure: as
|
||||||
|
//the expiration involves the SessionDataStore doing a delete, it is
|
||||||
|
//most efficient if it can be done as a bulk operation to eg reduce
|
||||||
|
//roundtrips to the persistent store.
|
||||||
|
_candidateSessionIdsForExpiry.add(session.getId());
|
||||||
|
if (LOG.isDebugEnabled())LOG.debug("Session {} is candidate for expiry", session.getId());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_sessionCache.checkInactiveSession(session); //if inactivity eviction is enabled the session will be deleted from the cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1449,7 +1531,8 @@ public class SessionHandler extends ScopedHandler
|
||||||
{
|
{
|
||||||
SessionHandler old_session_manager = null;
|
SessionHandler old_session_manager = null;
|
||||||
HttpSession old_session = null;
|
HttpSession old_session = null;
|
||||||
HttpSession access = null;
|
HttpSession existingSession = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
old_session_manager = baseRequest.getSessionHandler();
|
old_session_manager = baseRequest.getSessionHandler();
|
||||||
|
@ -1463,54 +1546,39 @@ public class SessionHandler extends ScopedHandler
|
||||||
checkRequestedSessionId(baseRequest,request);
|
checkRequestedSessionId(baseRequest,request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// access any existing session
|
// access any existing session for this context
|
||||||
HttpSession session = null;
|
existingSession = baseRequest.getSession(false);
|
||||||
|
|
||||||
session = baseRequest.getSession(false);
|
if ((existingSession != null) && (old_session_manager != this))
|
||||||
if (session != null)
|
|
||||||
{
|
{
|
||||||
if ((session != old_session) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST))
|
HttpCookie cookie = access(existingSession,request.isSecure());
|
||||||
{
|
// Handle changed ID or max-age refresh, but only if this is not a redispatched request
|
||||||
access = session;
|
if ((cookie != null) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST))
|
||||||
HttpCookie cookie = access(session,request.isSecure());
|
baseRequest.getResponse().addCookie(cookie);
|
||||||
if (cookie != null) // Handle changed ID or max-age refresh
|
|
||||||
baseRequest.getResponse().addCookie(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
session = baseRequest.recoverNewSession(this);
|
|
||||||
if (session != null)
|
|
||||||
baseRequest.setSession(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
{
|
{
|
||||||
LOG.debug("sessionHandler=" + this);
|
LOG.debug("sessionHandler=" + this);
|
||||||
LOG.debug("session=" + session);
|
LOG.debug("session=" + existingSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start manual inline of nextScope(target,baseRequest,request,response);
|
|
||||||
if (_nextScope != null)
|
if (_nextScope != null)
|
||||||
_nextScope.doScope(target,baseRequest,request,response);
|
_nextScope.doScope(target,baseRequest,request,response);
|
||||||
else if (_outerScope != null)
|
else if (_outerScope != null)
|
||||||
_outerScope.doHandle(target,baseRequest,request,response);
|
_outerScope.doHandle(target,baseRequest,request,response);
|
||||||
else
|
else
|
||||||
doHandle(target,baseRequest,request,response);
|
doHandle(target,baseRequest,request,response);
|
||||||
// end manual inline (pathentic attempt to reduce stack depth)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
//if we accessed an existing session entering this context, then complete it
|
|
||||||
if (access != null)
|
|
||||||
complete(access);
|
|
||||||
|
|
||||||
|
|
||||||
//if there is a session that was created during handling this context, then complete it
|
//if there is a session that was created during handling this context, then complete it
|
||||||
HttpSession session = baseRequest.getSession(false);
|
HttpSession finalSession = baseRequest.getSession(false);
|
||||||
if ((session != null && old_session == null && session != access) && (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.REQUEST))
|
if ((finalSession != null) && (old_session_manager != this))
|
||||||
complete(session);
|
{
|
||||||
|
complete((Session)finalSession, baseRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (old_session_manager != null && old_session_manager != this)
|
if (old_session_manager != null && old_session_manager != this)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,7 +56,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||||
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
|
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
|
||||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||||
import org.eclipse.jetty.server.session.NullSessionStore;
|
import org.eclipse.jetty.server.session.NullSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.Session;
|
import org.eclipse.jetty.server.session.Session;
|
||||||
import org.eclipse.jetty.server.session.SessionData;
|
import org.eclipse.jetty.server.session.SessionData;
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
|
@ -514,8 +514,8 @@ public class ResponseTest
|
||||||
request.setRequestedSessionIdFromCookie(false);
|
request.setRequestedSessionIdFromCookie(false);
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
NullSessionStore ds = new NullSessionStore();
|
NullSessionDataStore ds = new NullSessionDataStore();
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
|
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
|
||||||
request.setSessionHandler(handler);
|
request.setSessionHandler(handler);
|
||||||
TestSession tsession = new TestSession(handler, "12345");
|
TestSession tsession = new TestSession(handler, "12345");
|
||||||
|
@ -594,10 +594,10 @@ public class ResponseTest
|
||||||
request.setRequestedSessionIdFromCookie(i>2);
|
request.setRequestedSessionIdFromCookie(i>2);
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
|
|
||||||
NullSessionStore ds = new NullSessionStore();
|
NullSessionDataStore ds = new NullSessionDataStore();
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
|
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
|
||||||
request.setSessionHandler(handler);
|
request.setSessionHandler(handler);
|
||||||
request.setSession(new TestSession(handler, "12345"));
|
request.setSession(new TestSession(handler, "12345"));
|
||||||
|
@ -898,8 +898,7 @@ public class ResponseTest
|
||||||
{
|
{
|
||||||
protected TestSession(SessionHandler handler, String id)
|
protected TestSession(SessionHandler handler, String id)
|
||||||
{
|
{
|
||||||
super(new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300));
|
super(handler, new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300));
|
||||||
setSessionHandler(handler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,11 @@ public class FileSessionManagerTest
|
||||||
idmgr.setServer(server);
|
idmgr.setServer(server);
|
||||||
server.setSessionIdManager(idmgr);
|
server.setSessionIdManager(idmgr);
|
||||||
|
|
||||||
FileSessionStore ds = new FileSessionStore();
|
FileSessionDataStore ds = new FileSessionDataStore();
|
||||||
ds.setDeleteUnrestorableFiles(true);
|
ds.setDeleteUnrestorableFiles(true);
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
//manager.setLazyLoad(true);
|
//manager.setLazyLoad(true);
|
||||||
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
|
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
|
||||||
testDir.mkdirs();
|
testDir.mkdirs();
|
||||||
|
@ -101,9 +101,9 @@ public class FileSessionManagerTest
|
||||||
server.setSessionIdManager(idmgr);
|
server.setSessionIdManager(idmgr);
|
||||||
|
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
FileSessionStore ds = new FileSessionStore();
|
FileSessionDataStore ds = new FileSessionDataStore();
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
ds.setDeleteUnrestorableFiles(true);
|
ds.setDeleteUnrestorableFiles(true);
|
||||||
handler.setSessionIdManager(idmgr);
|
handler.setSessionIdManager(idmgr);
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ public class FileSessionManagerTest
|
||||||
handler.setServer(server);
|
handler.setServer(server);
|
||||||
|
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
FileSessionStore ds = new FileSessionStore();
|
FileSessionDataStore ds = new FileSessionDataStore();
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
ds.setStoreDir(testDir);
|
ds.setStoreDir(testDir);
|
||||||
handler.setMaxInactiveInterval(5);
|
handler.setMaxInactiveInterval(5);
|
||||||
Assert.assertTrue(testDir.exists());
|
Assert.assertTrue(testDir.exists());
|
||||||
|
|
|
@ -165,13 +165,13 @@ public class SessionCookieTest
|
||||||
idMgr.setWorkerName("node1");
|
idMgr.setWorkerName("node1");
|
||||||
SessionHandler mgr = new SessionHandler();
|
SessionHandler mgr = new SessionHandler();
|
||||||
MockSessionStore store = new MockSessionStore(mgr);
|
MockSessionStore store = new MockSessionStore(mgr);
|
||||||
store.setSessionStore(new NullSessionStore());
|
store.setSessionDataStore(new NullSessionDataStore());
|
||||||
mgr.setSessionStore(store);
|
mgr.setSessionCache(store);
|
||||||
mgr.setSessionIdManager(idMgr);
|
mgr.setSessionIdManager(idMgr);
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
Session session = new Session(new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30));
|
Session session = new Session(null, new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30));
|
||||||
|
|
||||||
SessionCookieConfig sessionCookieConfig = mgr.getSessionCookieConfig();
|
SessionCookieConfig sessionCookieConfig = mgr.getSessionCookieConfig();
|
||||||
sessionCookieConfig.setSecure(true);
|
sessionCookieConfig.setSecure(true);
|
||||||
|
|
|
@ -18,12 +18,15 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.servlet;
|
package org.eclipse.jetty.servlet;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.server.HttpChannel;
|
||||||
import org.eclipse.jetty.server.LocalConnector;
|
import org.eclipse.jetty.server.LocalConnector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
@ -35,32 +38,41 @@ import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
public class PostServletTest
|
public class PostServletTest
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(PostServletTest.class);
|
private static final Logger LOG = Log.getLogger(PostServletTest.class);
|
||||||
|
private static final AtomicReference<Throwable> ex0=new AtomicReference<>();
|
||||||
|
private static final AtomicReference<Throwable> ex1=new AtomicReference<>();
|
||||||
|
|
||||||
public static class BasicReadPostServlet extends HttpServlet
|
public static class BasicReadPostServlet extends HttpServlet
|
||||||
{
|
{
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
{
|
{
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
response.flushBuffer();
|
int len=request.getInputStream().read(buffer);
|
||||||
request.getInputStream().read();
|
while(len>0)
|
||||||
|
{
|
||||||
|
response.getOutputStream().println("read "+len);
|
||||||
|
response.getOutputStream().flush();
|
||||||
|
len = request.getInputStream().read(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e0)
|
catch (Exception e0)
|
||||||
{
|
{
|
||||||
|
ex0.set(e0);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// this read-call should fail immediately
|
// this read-call should fail immediately
|
||||||
request.getInputStream().read();
|
request.getInputStream().read(buffer);
|
||||||
}
|
}
|
||||||
catch (Exception e1)
|
catch (Exception e1)
|
||||||
{
|
{
|
||||||
|
ex1.set(e1);
|
||||||
LOG.warn(e1.toString());
|
LOG.warn(e1.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +85,8 @@ public class PostServletTest
|
||||||
@Before
|
@Before
|
||||||
public void startServer() throws Exception
|
public void startServer() throws Exception
|
||||||
{
|
{
|
||||||
|
ex0.set(null);
|
||||||
|
ex1.set(null);
|
||||||
server = new Server();
|
server = new Server();
|
||||||
connector = new LocalConnector(server);
|
connector = new LocalConnector(server);
|
||||||
server.addConnector(connector);
|
server.addConnector(connector);
|
||||||
|
@ -98,21 +112,27 @@ public class PostServletTest
|
||||||
StringBuilder req = new StringBuilder();
|
StringBuilder req = new StringBuilder();
|
||||||
req.append("POST /post HTTP/1.1\r\n");
|
req.append("POST /post HTTP/1.1\r\n");
|
||||||
req.append("Host: localhost\r\n");
|
req.append("Host: localhost\r\n");
|
||||||
req.append("Connection: close\r\n");
|
|
||||||
req.append("Transfer-Encoding: chunked\r\n");
|
req.append("Transfer-Encoding: chunked\r\n");
|
||||||
req.append("\r\n");
|
req.append("\r\n");
|
||||||
req.append("6\r\n");
|
req.append("6\r\n");
|
||||||
req.append("Hello ");
|
req.append("Hello ");
|
||||||
req.append("\r\n");
|
req.append("\r\n");
|
||||||
req.append("6\r\n");
|
req.append("7\r\n");
|
||||||
req.append("World\n");
|
req.append("World!\n");
|
||||||
req.append("\r\n");
|
req.append("\r\n");
|
||||||
req.append("0\r\n");
|
req.append("0\r\n");
|
||||||
req.append("\r\n");
|
req.append("\r\n");
|
||||||
|
|
||||||
String resp = connector.getResponses(req.toString());
|
String resp = connector.getResponses(req.toString(),1,TimeUnit.SECONDS);
|
||||||
|
|
||||||
assertThat("resp", resp, Matchers.containsString("HTTP/1.1 200 OK"));
|
assertThat("resp", resp, containsString("HTTP/1.1 200 OK"));
|
||||||
|
assertThat("resp", resp, containsString("chunked"));
|
||||||
|
assertThat("resp", resp, containsString("read 6"));
|
||||||
|
assertThat("resp", resp, containsString("read 7"));
|
||||||
|
assertThat("resp", resp, containsString("\r\n0\r\n"));
|
||||||
|
|
||||||
|
assertThat(ex0.get(),nullValue());
|
||||||
|
assertThat(ex1.get(),nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -132,12 +152,47 @@ public class PostServletTest
|
||||||
try (StacklessLogging scope = new StacklessLogging(ServletHandler.class))
|
try (StacklessLogging scope = new StacklessLogging(ServletHandler.class))
|
||||||
{
|
{
|
||||||
String resp = connector.getResponses(req.toString());
|
String resp = connector.getResponses(req.toString());
|
||||||
assertThat("resp", resp, Matchers.containsString("HTTP/1.1 200 "));
|
assertThat(resp,is("")); // Aborted before response committed
|
||||||
assertThat("resp", resp, Matchers.containsString("chunked"));
|
|
||||||
assertThat("resp", resp, not(containsString("\r\n0\r\n")));
|
|
||||||
}
|
}
|
||||||
|
assertThat(ex0.get(),not(nullValue()));
|
||||||
|
assertThat(ex1.get(),not(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeferredBadPost() throws Exception
|
||||||
|
{
|
||||||
|
StringBuilder req = new StringBuilder(16*1024);
|
||||||
|
req.append("POST /post HTTP/1.1\r\n");
|
||||||
|
req.append("Host: localhost\r\n");
|
||||||
|
req.append("Transfer-Encoding: chunked\r\n");
|
||||||
|
req.append("\r\n");
|
||||||
|
|
||||||
|
try (StacklessLogging scope = new StacklessLogging(ServletHandler.class))
|
||||||
|
{
|
||||||
|
LocalConnector.LocalEndPoint endp=connector.executeRequest(req.toString());
|
||||||
|
Thread.sleep(1000);
|
||||||
|
req.setLength(0);
|
||||||
|
// intentionally bad (not a valid chunked char here)
|
||||||
|
for (int i=1024;i-->0;)
|
||||||
|
req.append("xxxxxxxxxxxx");
|
||||||
|
req.append("\r\n");
|
||||||
|
req.append("\r\n");
|
||||||
|
|
||||||
|
endp.addInput(req.toString());
|
||||||
|
|
||||||
|
endp.waitUntilClosedOrIdleFor(1,TimeUnit.SECONDS);
|
||||||
|
String resp = endp.takeOutputString();
|
||||||
|
|
||||||
|
assertThat("resp", resp, containsString("HTTP/1.1 400 "));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// null because it was never dispatched!
|
||||||
|
assertThat(ex0.get(),nullValue());
|
||||||
|
assertThat(ex1.get(),nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadSplitPost() throws Exception
|
public void testBadSplitPost() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -166,40 +221,11 @@ public class PostServletTest
|
||||||
|
|
||||||
endp.waitUntilClosedOrIdleFor(1,TimeUnit.SECONDS);
|
endp.waitUntilClosedOrIdleFor(1,TimeUnit.SECONDS);
|
||||||
String resp = endp.takeOutputString();
|
String resp = endp.takeOutputString();
|
||||||
assertThat("resp", resp, Matchers.containsString("HTTP/1.1 400 "));
|
assertThat("resp", resp, containsString("HTTP/1.1 200 "));
|
||||||
|
assertThat("resp", resp, not(containsString("\r\n0\r\n"))); // aborted
|
||||||
}
|
}
|
||||||
|
assertThat(ex0.get(),not(nullValue()));
|
||||||
|
assertThat(ex1.get(),not(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBadFlushedPost() throws Exception
|
|
||||||
{
|
|
||||||
StringBuilder req = new StringBuilder();
|
|
||||||
req.append("POST /post HTTP/1.1\r\n");
|
|
||||||
req.append("Host: localhost\r\n");
|
|
||||||
req.append("Transfer-Encoding: chunked\r\n");
|
|
||||||
req.append("\r\n");
|
|
||||||
req.append("6\r\n");
|
|
||||||
req.append("Flush ");
|
|
||||||
req.append("\r\n");
|
|
||||||
|
|
||||||
try (StacklessLogging scope = new StacklessLogging(ServletHandler.class))
|
|
||||||
{
|
|
||||||
LocalConnector.LocalEndPoint endp=connector.executeRequest(req.toString());
|
|
||||||
req.setLength(0);
|
|
||||||
|
|
||||||
Thread.sleep(1000);
|
|
||||||
req.append("x\r\n");
|
|
||||||
req.append("World\n");
|
|
||||||
req.append("\r\n");
|
|
||||||
req.append("0\r\n");
|
|
||||||
req.append("\r\n");
|
|
||||||
endp.addInput(req.toString());
|
|
||||||
|
|
||||||
endp.waitUntilClosedOrIdleFor(1,TimeUnit.SECONDS);
|
|
||||||
String resp = endp.takeOutputString();
|
|
||||||
assertThat("resp", resp, Matchers.containsString("HTTP/1.1 200 "));
|
|
||||||
assertThat("resp", resp, Matchers.containsString("Transfer-Encoding: chunked"));
|
|
||||||
assertThat("resp", resp, not(Matchers.containsString("\r\n0\r\n")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,15 +70,16 @@ public class FileTestServer extends AbstractTestServer
|
||||||
assertFalse(files.length==0);
|
assertFalse(files.length==0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void assertFileExists (String sessionId, boolean exists)
|
public static void assertFileExists (String sessionId, boolean exists)
|
||||||
{
|
{
|
||||||
assertNotNull(_tmpDir);
|
assertNotNull(_tmpDir);
|
||||||
assertTrue(_tmpDir.exists());
|
assertTrue(_tmpDir.exists());
|
||||||
String[] files = _tmpDir.list();
|
String[] files = _tmpDir.list();
|
||||||
assertNotNull(files);
|
assertNotNull(files);
|
||||||
assertFalse(files.length == 0);
|
if (exists)
|
||||||
|
assertFalse(files.length == 0);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String name:files)
|
for (String name:files)
|
||||||
{
|
{
|
||||||
|
@ -143,10 +144,10 @@ public class FileTestServer extends AbstractTestServer
|
||||||
{
|
{
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
FileSessionStore ds = new FileSessionStore();
|
FileSessionDataStore ds = new FileSessionDataStore();
|
||||||
ds.setStoreDir(_tmpDir);
|
ds.setStoreDir(_tmpDir);
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,9 @@ public class IdleSessionTest extends AbstractIdleSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractIdleSessionTest#createServer(int, int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractIdleSessionTest#createServer(int, int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int idleSec)
|
public AbstractTestServer createServer(final int port, final int max, final int scavenge, final int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge, idleSec);
|
return new FileTestServer(port,max,scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest
|
||||||
public void checkSessionDeIdled(String sessionId)
|
public void checkSessionDeIdled(String sessionId)
|
||||||
{
|
{
|
||||||
//Can't check absence of file to indicate session is de-idled
|
//Can't check absence of file to indicate session is de-idled
|
||||||
//because the FileSessionStore writes out the session to a file if anything changes.
|
//because the FileSessionDataStore writes out the session to a file if anything changes.
|
||||||
//The test changes an attribute so the file will probably exist.
|
//The test changes an attribute so the file will probably exist.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ public class IdleSessionTest extends AbstractIdleSessionTest
|
||||||
public void deleteSessionData(String sessionId)
|
public void deleteSessionData(String sessionId)
|
||||||
{
|
{
|
||||||
FileTestServer.deleteFile(sessionId);
|
FileTestServer.deleteFile(sessionId);
|
||||||
|
FileTestServer.assertFileExists(sessionId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge, idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class NewSessionTest extends AbstractNewSessionTest
|
||||||
FileTestServer.teardown();
|
FileTestServer.teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge,idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -39,9 +39,9 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest
|
||||||
FileTestServer.teardown();
|
FileTestServer.teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge,idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -50,9 +50,9 @@ public class ProxySerializationTest extends AbstractProxySerializationTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod )
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy )
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge, idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port, max, scavenge, idlePassivatePeriod);
|
return new FileTestServer(port, max, scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge,idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class SessionCookieTest extends AbstractSessionCookieTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port, max, scavenge,idlePassivatePeriod);
|
return new FileTestServer(port, max, scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge,idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -40,9 +40,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port, max, scavenge,idlePassivatePeriod);
|
return new FileTestServer(port, max, scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class SessionValueSharedSaving extends AbstractSessionValueSavingTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new FileTestServer(port,max,scavenge,idlePassivatePeriod);
|
return new FileTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ public class GCloudSessionTestSupport
|
||||||
public void listSessions () throws Exception
|
public void listSessions () throws Exception
|
||||||
{
|
{
|
||||||
ensureDatastore();
|
ensureDatastore();
|
||||||
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND);
|
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND);
|
||||||
|
|
||||||
Query<Entity> query = builder.build();
|
Query<Entity> query = builder.build();
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ public class GCloudSessionTestSupport
|
||||||
{
|
{
|
||||||
HashSet<String> ids = new HashSet<String>();
|
HashSet<String> ids = new HashSet<String>();
|
||||||
ensureDatastore();
|
ensureDatastore();
|
||||||
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND);
|
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND);
|
||||||
|
|
||||||
Query<Entity> query = builder.build();
|
Query<Entity> query = builder.build();
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ public class GCloudSessionTestSupport
|
||||||
{
|
{
|
||||||
ensureDatastore();
|
ensureDatastore();
|
||||||
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
|
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
|
||||||
.kind(GCloudSessionStore.KIND)
|
.kind(GCloudSessionDataStore.KIND)
|
||||||
.projection(Projection.property("__key__"))
|
.projection(Projection.property("__key__"))
|
||||||
.limit(100)
|
.limit(100)
|
||||||
.build();
|
.build();
|
||||||
|
@ -355,7 +355,7 @@ public class GCloudSessionTestSupport
|
||||||
{
|
{
|
||||||
ensureDatastore();
|
ensureDatastore();
|
||||||
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
|
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
|
||||||
.kind(GCloudSessionStore.KIND)
|
.kind(GCloudSessionDataStore.KIND)
|
||||||
.projection(Projection.property("__key__"))
|
.projection(Projection.property("__key__"))
|
||||||
.limit(100)
|
.limit(100)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -65,11 +65,11 @@ public class GCloudTestServer extends AbstractTestServer
|
||||||
{
|
{
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
handler.setSessionIdManager(_sessionIdManager);
|
handler.setSessionIdManager(_sessionIdManager);
|
||||||
GCloudSessionStore ds = new GCloudSessionStore();
|
GCloudSessionDataStore ds = new GCloudSessionDataStore();
|
||||||
ds.setGCloudConfiguration((GCloudConfiguration)_config);
|
ds.setGCloudConfiguration((GCloudConfiguration)_config);
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
ss.setSessionStore(ds);
|
ss.setSessionDataStore(ds);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, maxInactiveMs, scavengeMs, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.junit.Ignore;
|
||||||
public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
||||||
{
|
{
|
||||||
static GCloudSessionTestSupport _testSupport;
|
static GCloudSessionTestSupport _testSupport;
|
||||||
public static final int IDLE_PASSIVATE_SEC = 3;
|
public static final int EVICT_SEC = 3;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup () throws Exception
|
public static void setup () throws Exception
|
||||||
|
@ -54,9 +54,9 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy)
|
||||||
{
|
{
|
||||||
GCloudTestServer server = new GCloudTestServer(port, maxInactive, scavengeInterval, idlePassivateInterval, _testSupport.getConfiguration())
|
GCloudTestServer server = new GCloudTestServer(port, maxInactive, scavengeInterval, evictionPolicy, _testSupport.getConfiguration())
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.gcloud.session.GCloudTestServer#newSessionManager()
|
* @see org.eclipse.jetty.gcloud.session.GCloudTestServer#newSessionManager()
|
||||||
|
@ -65,7 +65,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
||||||
public SessionHandler newSessionHandler()
|
public SessionHandler newSessionHandler()
|
||||||
{
|
{
|
||||||
SessionHandler handler = super.newSessionHandler();
|
SessionHandler handler = super.newSessionHandler();
|
||||||
handler.getSessionStore().setIdlePassivationTimeoutSec(IDLE_PASSIVATE_SEC);
|
handler.getSessionCache().setEvictionPolicy(EVICT_SEC);
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
||||||
//has expired on node2 for it to reload the session and discover it has been deleted.
|
//has expired on node2 for it to reload the session and discover it has been deleted.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.currentThread().sleep((2*IDLE_PASSIVATE_SEC)*1000);
|
Thread.currentThread().sleep((2*EVICT_SEC)*1000);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,9 +50,9 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractLastAccessTimeTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractLastAccessTimeTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe
|
||||||
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class NewSessionTest extends AbstractNewSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class OrphanedSessionTest extends AbstractOrphanedSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractOrphanedSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractOrphanedSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession
|
||||||
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port,int max, int scavengePeriod,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port,int max, int scavengePeriod,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavengePeriod, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavengePeriod, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -54,9 +54,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge,int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge,int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivatePeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class SameNodeLoadTest extends AbstractSameNodeLoadTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int, int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int, int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionExpiryTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionExpiryTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -78,7 +78,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
public void testSessionExpiry() throws Exception
|
public void testSessionExpiry() throws Exception
|
||||||
{
|
{
|
||||||
super.testSessionExpiry();
|
super.testSessionExpiry();
|
||||||
try{_testSupport.assertSessions(0);}catch(Exception e){ Assert.fail(e.getMessage());}
|
_testSupport.deleteSessions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,7 +92,6 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
public void verifySessionDestroyed(TestHttpSessionListener listener, String sessionId)
|
public void verifySessionDestroyed(TestHttpSessionListener listener, String sessionId)
|
||||||
{
|
{
|
||||||
super.verifySessionDestroyed(listener, sessionId);
|
super.verifySessionDestroyed(listener, sessionId);
|
||||||
try{_testSupport.assertSessions(0);}catch(Exception e){ Assert.fail(e.getMessage());}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port,max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port,max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class SessionValueSavingTest extends AbstractSessionValueSavingTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionValueSavingTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionValueSavingTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new GCloudTestServer(port, max, scavenge, idlePassivationPeriod, _testSupport.getConfiguration());
|
return new GCloudTestServer(port, max, scavenge, evictionPolicy, _testSupport.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -33,9 +33,9 @@ public class HashTestServer extends AbstractTestServer
|
||||||
super(port, 30, 10, 2);
|
super(port, 30, 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashTestServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod)
|
public HashTestServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy)
|
||||||
{
|
{
|
||||||
super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod);
|
super(port, maxInactivePeriod, scavengePeriod, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ public class HashTestServer extends AbstractTestServer
|
||||||
{
|
{
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
ss.setSessionStore(new NullSessionStore());
|
ss.setSessionDataStore(new NullSessionDataStore());
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port,max,scavenge,idlePassivationPeriod);
|
return new HashTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ import org.junit.Test;
|
||||||
public class NewSessionTest extends AbstractNewSessionTest
|
public class NewSessionTest extends AbstractNewSessionTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port,max,scavenge,idlePassivationPeriod);
|
return new HashTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -30,9 +30,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession
|
||||||
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int, int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int, int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivatePeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port, max, scavenge, idlePassivatePeriod);
|
return new HashTestServer(port, max, scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -34,9 +34,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractRemoveSessionTest#createServer(int, int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer (port, max, scavenge, idlePassivationPeriod);
|
return new HashTestServer (port, max, scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class SessionCookieTest extends AbstractSessionCookieTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port, max, scavenge, idlePassivationPeriod);
|
return new HashTestServer(port, max, scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port,max,scavenge,idlePassivationPeriod);
|
return new HashTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -31,9 +31,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port, max, scavenge,idlePassivationPeriod);
|
return new HashTestServer(port, max, scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class SessionValueSharedSaving extends AbstractSessionValueSavingTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivationPeriod)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new HashTestServer(port,max,scavenge,idlePassivationPeriod);
|
return new HashTestServer(port,max,scavenge,evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.eclipse.jetty.server.session;
|
package org.eclipse.jetty.server.session;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.SessionIdManager;
|
import org.eclipse.jetty.server.SessionIdManager;
|
||||||
import org.eclipse.jetty.session.infinispan.InfinispanSessionStore;
|
import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.infinispan.Cache;
|
import org.infinispan.Cache;
|
||||||
import org.infinispan.commons.api.BasicCache;
|
import org.infinispan.commons.api.BasicCache;
|
||||||
|
@ -37,9 +37,9 @@ public class InfinispanTestSessionServer extends AbstractTestServer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public InfinispanTestSessionServer(int port, int maxInactivePeriod, int scavengePeriod, int idlePassivatePeriod, BasicCache config)
|
public InfinispanTestSessionServer(int port, int maxInactivePeriod, int scavengePeriod, int evictionPolicy, BasicCache config)
|
||||||
{
|
{
|
||||||
super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, config);
|
super(port, maxInactivePeriod, scavengePeriod, evictionPolicy, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,11 +48,11 @@ public class InfinispanTestSessionServer extends AbstractTestServer
|
||||||
public SessionHandler newSessionHandler()
|
public SessionHandler newSessionHandler()
|
||||||
{
|
{
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
InfinispanSessionStore sds = new InfinispanSessionStore();
|
InfinispanSessionDataStore sds = new InfinispanSessionDataStore();
|
||||||
sds.setCache((BasicCache)_config);
|
sds.setCache((BasicCache)_config);
|
||||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||||
ss.setSessionStore(sds);
|
ss.setSessionDataStore(sds);
|
||||||
handler.setSessionStore(ss);
|
handler.setSessionCache(ss);
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer
|
||||||
BasicCache cache = (BasicCache)_config;
|
BasicCache cache = (BasicCache)_config;
|
||||||
if (cache != null)
|
if (cache != null)
|
||||||
{
|
{
|
||||||
return cache.containsKey(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id));
|
return cache.containsKey(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionCache().getSessionDataStore())).getCacheKey(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -72,7 +72,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer
|
||||||
BasicCache cache = (BasicCache)_config;
|
BasicCache cache = (BasicCache)_config;
|
||||||
if (cache != null)
|
if (cache != null)
|
||||||
{
|
{
|
||||||
return cache.get(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id));
|
return cache.get(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionCache().getSessionDataStore())).getCacheKey(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -42,9 +42,9 @@ public class LastAccessTimeTest extends AbstractLastAccessTimeTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe
|
||||||
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ public class NewSessionTest extends AbstractNewSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,9 @@ public class ReentrantRequestSessionTest extends AbstractReentrantRequestSession
|
||||||
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, maxInactive, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,9 +43,9 @@ public class RemoveSessionTest extends AbstractRemoveSessionTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class SameNodeLoadTest extends AbstractSameNodeLoadTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port,int maxInactive, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port,maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port,maxInactive, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAnd
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class SessionRenewTest extends AbstractSessionRenewTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -59,9 +59,9 @@ public class RemoteImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractImmortalSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, maxInactiveMs, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class RemoteInvalidationSessionTest extends AbstractInvalidationSessionTe
|
||||||
* @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractInvalidationSessionTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInterval, int scavengeInterval, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, maxInterval, scavengeInterval, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, maxInterval, scavengeInterval, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class RemoteLastAccessTimeTest extends AbstractLastAccessTimeTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class RemoteLocalSessionScavengingTest extends AbstractLocalSessionScaven
|
||||||
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractLocalSessionScavengingTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class RemoteNewSessionTest extends AbstractNewSessionTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractNewSessionTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class RemoteReentrantRequestSessionTest extends AbstractReentrantRequestS
|
||||||
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractReentrantRequestSessionTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, maxInactive, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, maxInactive, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,9 +46,9 @@ public class RemoteRemoveSessionTest extends AbstractRemoveSessionTest
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge,idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer s = new InfinispanTestSessionServer(port, max, scavenge,evictionPolicy, __testSupport.getCache());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,9 @@ public class RemoteSameNodeLoadTest extends AbstractSameNodeLoadTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int)
|
* @see org.eclipse.jetty.server.session.AbstractSameNodeLoadTest#createServer(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactive, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, maxInactive, scavenge,idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, maxInactive, scavenge,evictionPolicy, __testSupport.getCache());
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ public class RemoteSessionExpiryTest extends AbstractSessionExpiryTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
InfinispanTestSessionServer server = new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class RemoteSessionInvalidateAndCreateTest extends AbstractSessionInvalid
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionInvalidateAndCreateTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class RemoteSessionRenewTest extends AbstractSessionRenewTest
|
||||||
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
* @see org.eclipse.jetty.server.session.AbstractSessionRenewTest#createServer(int, int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new InfinispanTestSessionServer(port, max, scavenge, idlePassivateInterval, __testSupport.getCache());
|
return new InfinispanTestSessionServer(port, max, scavenge, evictionPolicy, __testSupport.getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -58,12 +58,12 @@ public class DirtyAttributeTest
|
||||||
public static int INACTIVE = 4;
|
public static int INACTIVE = 4;
|
||||||
public static int SCAVENGE = 1;
|
public static int SCAVENGE = 1;
|
||||||
public static int INSPECT = 1;
|
public static int INSPECT = 1;
|
||||||
public static int IDLE_PASSIVATE = 3;
|
public static int EVICT_SECS = 3;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirtyWrite() throws Exception
|
public void testDirtyWrite() throws Exception
|
||||||
{
|
{
|
||||||
AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, IDLE_PASSIVATE);
|
AbstractTestServer server = new JdbcTestServer(0,INACTIVE,SCAVENGE, EVICT_SECS);
|
||||||
|
|
||||||
ServletContextHandler ctxA = server.addContext("/mod");
|
ServletContextHandler ctxA = server.addContext("/mod");
|
||||||
ctxA.addServlet(TestDirtyServlet.class, "/test");
|
ctxA.addServlet(TestDirtyServlet.class, "/test");
|
||||||
|
|
|
@ -29,9 +29,9 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||||
{
|
{
|
||||||
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int idlePassivate)
|
public AbstractTestServer createServer(int port, int maxInactiveMs, int scavengeMs, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new JdbcTestServer(port, maxInactiveMs, scavengeMs, idlePassivate);
|
return new JdbcTestServer(port, maxInactiveMs, scavengeMs, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -29,9 +29,9 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
|
||||||
{
|
{
|
||||||
public static final int IDLE_PASSIVATE_SEC = 3;
|
public static final int IDLE_PASSIVATE_SEC = 3;
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int idlePassivateInterval)
|
public AbstractTestServer createServer(int port, int maxInactive, int scavengeInterval, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new JdbcTestServer(port, maxInactive, scavengeInterval, idlePassivateInterval);
|
return new JdbcTestServer(port, maxInactive, scavengeInterval, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause()
|
public void pause()
|
||||||
|
|
|
@ -103,14 +103,14 @@ public class JdbcTestServer extends AbstractTestServer
|
||||||
{
|
{
|
||||||
SessionHandler handler = new SessionHandler();
|
SessionHandler handler = new SessionHandler();
|
||||||
DefaultSessionCache sessionStore = new DefaultSessionCache(handler);
|
DefaultSessionCache sessionStore = new DefaultSessionCache(handler);
|
||||||
handler.setSessionStore(sessionStore);
|
handler.setSessionCache(sessionStore);
|
||||||
JDBCSessionStore ds = new JDBCSessionStore();
|
JDBCSessionDataStore ds = new JDBCSessionDataStore();
|
||||||
sessionStore.setSessionStore(ds);
|
sessionStore.setSessionDataStore(ds);
|
||||||
ds.setGracePeriodSec(_scavengePeriod);
|
ds.setGracePeriodSec(_scavengePeriod);
|
||||||
DatabaseAdaptor da = new DatabaseAdaptor();
|
DatabaseAdaptor da = new DatabaseAdaptor();
|
||||||
da.setDriverInfo(DRIVER_CLASS, (_config==null?DEFAULT_CONNECTION_URL:(String)_config));
|
da.setDriverInfo(DRIVER_CLASS, (_config==null?DEFAULT_CONNECTION_URL:(String)_config));
|
||||||
ds.setDatabaseAdaptor(da);
|
ds.setDatabaseAdaptor(da);
|
||||||
JDBCSessionStore.SessionTableSchema sessionTableSchema = new JDBCSessionStore.SessionTableSchema();
|
JDBCSessionDataStore.SessionTableSchema sessionTableSchema = new JDBCSessionDataStore.SessionTableSchema();
|
||||||
sessionTableSchema.setTableName(TABLE);
|
sessionTableSchema.setTableName(TABLE);
|
||||||
sessionTableSchema.setIdColumn(ID_COL);
|
sessionTableSchema.setIdColumn(ID_COL);
|
||||||
sessionTableSchema.setAccessTimeColumn(ACCESS_COL);
|
sessionTableSchema.setAccessTimeColumn(ACCESS_COL);
|
||||||
|
|
|
@ -26,9 +26,9 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class LastAccessTimeTest extends AbstractLastAccessTimeTest
|
public class LastAccessTimeTest extends AbstractLastAccessTimeTest
|
||||||
{
|
{
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new JdbcTestServer(port,max,scavenge, idlePassivate);
|
return new JdbcTestServer(port,max,scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -43,9 +43,9 @@ public class LocalSessionScavengingTest extends AbstractLocalSessionScavengingTe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractTestServer createServer(int port, int max, int scavenge, int idlePassivate)
|
public AbstractTestServer createServer(int port, int max, int scavenge, int evictionPolicy)
|
||||||
{
|
{
|
||||||
return new JdbcTestServer(port,max,scavenge, idlePassivate);
|
return new JdbcTestServer(port,max,scavenge, evictionPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue