Ensure SessionCache and SessionDataStore are managed as beans

This commit is contained in:
Jan Bartel 2016-05-19 13:01:38 +10:00
parent 7fd93f1929
commit 49ce555add
2 changed files with 10 additions and 14 deletions

View File

@ -25,7 +25,7 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.ContainerLifeCycle;
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.eclipse.jetty.util.thread.Locker.Lock; import org.eclipse.jetty.util.thread.Locker.Lock;
@ -51,7 +51,7 @@ import org.eclipse.jetty.util.thread.Locker.Lock;
* passivated before eviction from the cache. * passivated before eviction from the cache.
* *
*/ */
public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionCache public abstract class AbstractSessionCache extends ContainerLifeCycle implements SessionCache
{ {
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -205,9 +205,6 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
throw new IllegalStateException ("No ContextId"); throw new IllegalStateException ("No ContextId");
_sessionDataStore.initialize(_context); _sessionDataStore.initialize(_context);
_sessionDataStore.start();
super.doStart(); super.doStart();
} }
@ -234,6 +231,7 @@ public abstract class AbstractSessionCache extends AbstractLifeCycle implements
*/ */
public void setSessionDataStore(SessionDataStore sessionStore) public void setSessionDataStore(SessionDataStore sessionStore)
{ {
updateBean(_sessionDataStore, sessionStore);
_sessionDataStore = sessionStore; _sessionDataStore = sessionStore;
} }

View File

@ -412,11 +412,7 @@ public class SessionHandler extends ScopedHandler
if (_sessionCache == null) if (_sessionCache == null)
{ {
SessionCacheFactory ssFactory = server.getBean(SessionCacheFactory.class); SessionCacheFactory ssFactory = server.getBean(SessionCacheFactory.class);
if (ssFactory != null) setSessionCache(ssFactory != null?ssFactory.getSessionCache(this):new DefaultSessionCache(this));
_sessionCache = ssFactory.getSessionCache(this);
else
_sessionCache = new DefaultSessionCache(this);
SessionDataStore sds = null; SessionDataStore sds = null;
SessionDataStoreFactory sdsFactory = server.getBean(SessionDataStoreFactory.class); SessionDataStoreFactory sdsFactory = server.getBean(SessionDataStoreFactory.class);
if (sdsFactory != null) if (sdsFactory != null)
@ -500,9 +496,7 @@ public class SessionHandler extends ScopedHandler
} }
_sessionContext = new SessionContext(_sessionIdManager.getWorkerName(), _context); _sessionContext = new SessionContext(_sessionIdManager.getWorkerName(), _context);
_sessionCache.initialize(_sessionContext); _sessionCache.initialize(_sessionContext);
_sessionCache.start();
super.doStart(); super.doStart();
} }
@ -1008,8 +1002,12 @@ public class SessionHandler extends ScopedHandler
} }
/**
* @param cache
*/
public void setSessionCache (SessionCache cache) public void setSessionCache (SessionCache cache)
{ {
updateBean(_sessionCache, cache);
_sessionCache = cache; _sessionCache = cache;
} }