Partial refactoring - does not yet compile.

This commit is contained in:
Jan Bartel 2015-08-27 18:03:44 +10:00
parent 8070ce61f3
commit c45cd8ce03
25 changed files with 2852 additions and 103 deletions

View File

@ -130,10 +130,10 @@ public class InfinispanSessionIdManager extends AbstractSessionIdManager
*
* This method will consult the cluster.
*
* @see org.eclipse.jetty.server.SessionIdManager#idInUse(java.lang.String)
* @see org.eclipse.jetty.server.SessionIdManager#isIdInUse(java.lang.String)
*/
@Override
public boolean idInUse(String id)
public boolean isIdInUse(String id)
{
if (id == null)
return false;
@ -270,7 +270,7 @@ public class InfinispanSessionIdManager extends AbstractSessionIdManager
if (manager != null && manager instanceof InfinispanSessionManager)
{
((InfinispanSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
((InfinispanSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
}
}

View File

@ -576,7 +576,7 @@ public class MongoSessionIdManager extends AbstractSessionIdManager
* Searches database to find if the session id known to mongo, and is it valid
*/
@Override
public boolean idInUse(String sessionId)
public boolean isIdInUse(String sessionId)
{
/*
* optimize this query to only return the valid variable
@ -708,7 +708,7 @@ public class MongoSessionIdManager extends AbstractSessionIdManager
if (manager != null && manager instanceof MongoSessionManager)
{
((MongoSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
((MongoSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
}
}

View File

@ -29,25 +29,27 @@ import org.eclipse.jetty.util.component.LifeCycle;
public interface SessionIdManager extends LifeCycle
{
/**
* @param id The session ID without any cluster node extension
* @param id The plain session ID (ie no workername extension)
* @return True if the session ID is in use by at least one context.
*/
public boolean idInUse(String id);
public boolean isIdInUse(String id);
/**
* Add a session to the list of known sessions for a given ID.
* @param session The session
* Notify the sessionid manager that a particular session id is in use
* @param id
*/
public void addSession(HttpSession session);
public void useId (String id);
/**
* Remove session from the list of known sessions for a given ID.
* @param session the session to remove
* Remove id
* @param id the plain session id (no workername extension) of the session to remove
*/
public void removeSession(HttpSession session);
public void removeId (String id);
/**
* Call {@link HttpSession#invalidate()} on all known sessions for the given id.
* Invalidate all sessions on all contexts that share the same id.
*
* @param id The session ID without any cluster node extension
*/
public void invalidateAll(String id);
@ -67,30 +69,36 @@ public interface SessionIdManager extends LifeCycle
/* ------------------------------------------------------------ */
/** Get a cluster ID from a node ID.
/** Get just the session id from an id that includes the worker name
* as a suffix.
*
* Strip node identifier from a located session ID.
* @param nodeId the node id
* @param qualifiedId the session id including the worker name
* @return the cluster id
*/
public String getClusterId(String nodeId);
public String getId(String qualifiedId);
/* ------------------------------------------------------------ */
/** Get a node ID from a cluster ID and a request
* @param clusterId The ID of the session
/** Get an extended id for a session. An extended id contains
* the workername as a suffix.
*
* @param id The id of the session
* @param request The request that for the session (or null)
* @return The session ID qualified with the node ID.
* @return The session id qualified with the worker name
*/
public String getNodeId(String clusterId,HttpServletRequest request);
public String getExtendedId(String id,HttpServletRequest request);
/* ------------------------------------------------------------ */
/** Change the existing session id.
*
* @param oldClusterId the old cluster id
* @param oldNodeId the old node id
* @param oldId the old plain session id
* @param oldExtendedId the old fully qualified id
* @param request the request containing the session
*/
public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request);
public void renewSessionId(String oldId, String oldExtendedId, HttpServletRequest request);
}

View File

@ -194,13 +194,7 @@ public interface SessionManager extends LifeCycle
*/
public SessionIdManager getSessionIdManager();
/* ------------------------------------------------------------ */
/**
* @return the cross context session id manager.
* @deprecated use {@link #getSessionIdManager()}
*/
@Deprecated
public SessionIdManager getMetaManager();
/* ------------------------------------------------------------ */
/**
@ -308,10 +302,10 @@ public interface SessionManager extends LifeCycle
/* ------------------------------------------------------------ */
/** Change the existing session id.
*
* @param oldClusterId the old cluster id
* @param oldNodeId the old node id
* @param newClusterId the new cluster id
* @param newNodeId the new node id
* @param oldId the old session id
* @param oldExtendedId the session id including worker suffix
* @param newId the new session id
* @param newExtendedId the new session id including worker suffix
*/
public void renewSessionId(String oldClusterId, String oldNodeId, String newClusterId, String newNodeId);
public void renewSessionId(String oldId, String oldExtendedId, String newId, String newExtendedId);
}

View File

@ -71,7 +71,7 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
_newSession=true;
_created=System.currentTimeMillis();
_clusterId=_manager._sessionIdManager.newSessionId(request,_created);
_nodeId=_manager._sessionIdManager.getNodeId(_clusterId,request);
_nodeId=_manager._sessionIdManager.getExtendedId(_clusterId,request);
_accessed=_created;
_lastAccessed=_created;
_requests=1;
@ -86,7 +86,7 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
_manager = abstractSessionManager;
_created=created;
_clusterId=clusterId;
_nodeId=_manager._sessionIdManager.getNodeId(_clusterId,null);
_nodeId=_manager._sessionIdManager.getExtendedId(_clusterId,null);
_accessed=accessed;
_lastAccessed=accessed;
_requests=1;

View File

@ -52,6 +52,12 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
}
/* ------------------------------------------------------------ */
@Override
public abstract void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request);
/* ------------------------------------------------------------ */
/**
* Get the workname. If set, the workername is dot appended to the session
@ -133,14 +139,14 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
String requested_id=request.getRequestedSessionId();
if (requested_id!=null)
{
String cluster_id=getClusterId(requested_id);
if (idInUse(cluster_id))
String cluster_id=getId(requested_id);
if (isIdInUse(cluster_id))
return cluster_id;
}
// Else reuse any new session ID already defined for this request.
String new_id=(String)request.getAttribute(__NEW_SESSION_ID);
if (new_id!=null&&idInUse(new_id))
if (new_id!=null&&isIdInUse(new_id))
return new_id;
// pick a new unique ID!
@ -156,7 +162,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
{
// pick a new unique ID!
String id=null;
while (id==null||id.length()==0||idInUse(id))
while (id==null||id.length()==0||isIdInUse(id))
{
long r0=_weakRandom
?(hashCode()^Runtime.getRuntime().freeMemory()^_random.nextInt()^((seedTerm)<<32))
@ -198,9 +204,6 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
}
/* ------------------------------------------------------------ */
@Override
public abstract void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request);
/* ------------------------------------------------------------ */
@ -249,7 +252,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
* @return sessionId plus any worker ID.
*/
@Override
public String getNodeId(String clusterId, HttpServletRequest request)
public String getExtendedId(String clusterId, HttpServletRequest request)
{
if (_workerName!=null)
{
@ -266,14 +269,14 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
/** Get the session ID without any worker ID.
*
* @param nodeId the node id
* @param extendedId the session id with the worker extension
* @return sessionId without any worker ID.
*/
@Override
public String getClusterId(String nodeId)
public String getId(String extendedId)
{
int dot=nodeId.lastIndexOf('.');
return (dot>0)?nodeId.substring(0,dot):nodeId;
int dot=extendedId.lastIndexOf('.');
return (dot>0)?extendedId.substring(0,dot):extendedId;
}

View File

@ -318,7 +318,7 @@ public abstract class AbstractSessionManager extends ContainerLifeCycle implemen
@Override
public HttpSession getHttpSession(String nodeId)
{
String cluster_id = getSessionIdManager().getClusterId(nodeId);
String cluster_id = getSessionIdManager().getId(nodeId);
AbstractSession session = getSession(cluster_id);
if (session!=null && !session.getNodeId().equals(nodeId))
@ -676,7 +676,7 @@ public abstract class AbstractSessionManager extends ContainerLifeCycle implemen
{
synchronized (_sessionIdManager)
{
_sessionIdManager.addSession(session);
// _sessionIdManager.addSession(session); TODO cope with id coming in from database
addSession(session);
}
@ -766,7 +766,7 @@ public abstract class AbstractSessionManager extends ContainerLifeCycle implemen
_sessionTimeStats.set(round((System.currentTimeMillis() - session.getCreationTime())/1000.0));
// Remove session from all context and global id maps
_sessionIdManager.removeSession(session);
_sessionIdManager.removeId(session.getId());
if (invalidate)
_sessionIdManager.invalidateAll(session.getClusterId());

View File

@ -100,10 +100,10 @@ public class HashSessionIdManager extends AbstractSessionIdManager
/* ------------------------------------------------------------ */
/**
* @see SessionIdManager#idInUse(String)
* @see SessionIdManager#isIdInUse(String)
*/
@Override
public boolean idInUse(String id)
public boolean isIdInUse(String id)
{
synchronized (this)
{
@ -220,7 +220,7 @@ public class HashSessionIdManager extends AbstractSessionIdManager
if (s instanceof AbstractSession)
{
AbstractSession abstractSession = (AbstractSession)s;
abstractSession.getSessionManager().renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
abstractSession.getSessionManager().renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
}
}

View File

@ -806,29 +806,19 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
}
@Override
public void addSession(HttpSession session)
public String newSessionId(long seedTerm)
{
if (session == null)
return;
synchronized (_sessionIds)
{
String id = ((JDBCSessionManager.Session)session).getClusterId();
try
{
insert(id);
_sessionIds.add(id);
}
catch (Exception e)
{
LOG.warn("Problem storing session id="+id, e);
}
}
String id = super.newSessionId(seedTerm);
useId(id);
return id;
}
public void addSession(String id)
//TODO useId might not be the right paradigm
public void useId (String id)
{
if (id == null)
return;
@ -849,18 +839,12 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
/**
* @see org.eclipse.jetty.server.SessionIdManager#removeId(java.lang.String)
*/
@Override
public void removeSession(HttpSession session)
{
if (session == null)
return;
removeSession(((JDBCSessionManager.Session)session).getClusterId());
}
public void removeSession (String id)
public void removeId (String id)
{
if (id == null)
@ -885,16 +869,16 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
@Override
public boolean idInUse(String id)
public boolean isIdInUse(String id)
{
if (id == null)
return false;
String clusterId = getClusterId(id);
String sessionId = getId(id);
boolean inUse = false;
synchronized (_sessionIds)
{
inUse = _sessionIds.contains(clusterId);
inUse = _sessionIds.contains(sessionId);
}
@ -904,11 +888,11 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
//otherwise, we need to go to the database to check
try
{
return exists(clusterId);
return exists(sessionId);
}
catch (Exception e)
{
LOG.warn("Problem checking inUse for id="+clusterId, e);
LOG.warn("Problem checking inUse for id="+sessionId, e);
return false;
}
}
@ -922,7 +906,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
public void invalidateAll(String id)
{
//take the id out of the list of known sessionids for this node
removeSession(id);
removeId(id);
synchronized (_sessionIds)
{
@ -954,8 +938,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
synchronized (_sessionIds)
{
removeSession(oldClusterId);//remove the old one from the list (and database)
addSession(newClusterId); //add in the new session id to the list (and database)
removeId(oldClusterId);//remove the old one from the list (and database)
//tell all contexts to update the id
Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class);
@ -968,7 +951,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
if (manager != null && manager instanceof JDBCSessionManager)
{
((JDBCSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
((JDBCSessionManager)manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
}
}
@ -1499,4 +1482,6 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
}
}

View File

@ -554,7 +554,7 @@ public class JDBCSessionManager extends AbstractSessionManager
LOG.debug("getSession ({}): Session has expired", idInCluster);
//ensure that the session id for the expired session is deleted so that a new session with the
//same id cannot be created (because the idInUse() test would succeed)
_jdbcSessionIdMgr.removeSession(idInCluster);
_jdbcSessionIdMgr.removeId(idInCluster);
session=null;
}
@ -943,7 +943,7 @@ public class JDBCSessionManager extends AbstractSessionManager
{
//if the session could not be restored, take its id out of the pool of currently-in-use
//session ids
_jdbcSessionIdMgr.removeSession(id);
_jdbcSessionIdMgr.removeId(id);
throw _exception.get();
}

View File

@ -0,0 +1,49 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* AbstractSessionDataStore
*
*
*/
public abstract class AbstractSessionDataStore implements SessionDataStore
{
public abstract void doStore() throws Exception;
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.x.SessionData)
*/
@Override
public void store(String id, SessionData data) throws Exception
{
try
{
doStore();
}
finally
{
data.setDirty(false);
}
}
}

View File

@ -0,0 +1,167 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* AbstractSessionStore
*
*
*/
public abstract class AbstractSessionStore implements SessionStore
{
protected SessionDataStore _sessionDataStore;
public abstract Session newSession (SessionData data);
public abstract Session doGet(String id);
public abstract Session doPutIfAbsent (String id, Session session);
public abstract void doPut (String id, Session session);
public abstract boolean doExists (String id);
public abstract void doDelete (String id);
public AbstractSessionStore ()
{
}
public SessionDataStore getSessionDataStore()
{
return _sessionDataStore;
}
public void setSessionDataStore(SessionDataStore sessionDataStore)
{
_sessionDataStore = sessionDataStore;
}
/**
* Get a session object.
*
* If the session object is not in this session store, try getting
* the data for it from a SessionDataStore associated with the
* session manager.
*
* @see org.eclipse.jetty.server.session.x.SessionStore#get(java.lang.String)
*/
@Override
public Session get(String id) throws Exception
{
//look locally
Session session = doGet(id);
//not in session store, load the data for the session if possible
if (session == null && _sessionDataStore != null)
{
SessionData data = _sessionDataStore.load(id);
session = newSession(data);
doPut(id, session);
}
return session;
}
/**
* Put the Session object into the session store.
* If the session manager supports a session data store, write the
* session data through to the session data store.
*
* @see org.eclipse.jetty.server.session.x.SessionStore#put(java.lang.String, org.eclipse.jetty.server.session.x.Session)
*/
@Override
public void put(String id, Session session) throws Exception
{
//if the session is already in our cache, then we want to write through any changes
if (doExists(id))
{
//if the session data has changed, or the cache is considered stale, write it to any backing store
if ((session.getSessionData().isDirty() || isStale(session)) && _sessionDataStore != null)
{
session.willPassivate();
_sessionDataStore.store(id, session.getSessionData());
session.didActivate();
}
}
else
{
//session not already in cache, add it and write through
if (_sessionDataStore != null)
{
session.willPassivate();
_sessionDataStore.store(id, session.getSessionData());
session.didActivate();
}
doPut(id,session);
}
}
/**
* Check to see if the session object exists.
*
* TODO should this check through to the backing store?
*
* @see org.eclipse.jetty.server.session.x.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id)
{
return doExists(id);
}
/**
*TODO does this mean absent in the Session cache or the backing store???
*
* @see org.eclipse.jetty.server.session.x.SessionStore#putIfAbsent(java.lang.String, org.eclipse.jetty.server.session.x.Session)
*/
@Override
public Session putIfAbsent(String id, Session session) throws Exception
{
return doPutIfAbsent(id, session);
}
/**
* Remove a session object from this store and from any backing store.
*
* @see org.eclipse.jetty.server.session.x.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
{
boolean deleted = true;
//TODO synchronization???
if (_sessionDataStore != null)
deleted = _sessionDataStore.delete(id);
doDelete(id);
return deleted;
}
public boolean isStale (Session session)
{
//TODO implement (pluggable?) algorithm for deciding if memory is stale
return false;
}
}

View File

@ -0,0 +1,150 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* JDBCSessionDataStore
*
*
*/
public class JDBCSessionDataStore extends AbstractSessionDataStore
{
/**
* JDBCSessionData
*
*
*/
public class JDBCSessionData extends SessionData
{
protected String _rowId;
//TODO other fields needed by jdbc
/**
* @param id
* @param created
* @param accessed
* @param lastAccessed
* @param maxInactiveMs
*/
public JDBCSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
super(id, created, accessed, lastAccessed, maxInactiveMs);
}
public String getRowId()
{
return _rowId;
}
public void setRowId(String rowId)
{
_rowId = rowId;
}
}
/**
*
*/
public JDBCSessionDataStore ()
{
super ();
}
@Override
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
return new JDBCSessionData(id, created, accessed, lastAccessed, maxInactiveMs);
}
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
{
// TODO make jdbc calls to load in the session
long created = 0;
long accessed = 0;
long lastAccessed = 0;
long maxInactiveMs = 0;
JDBCSessionData data = (JDBCSessionData)newSessionData(id, created, accessed, lastAccessed, maxInactiveMs);
// set vhost etc
// set row id
// set expiry time
return data;
}
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
{
// TODO delete from jdbc
return false;
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionDataStore#doStore()
*/
@Override
public void doStore() throws Exception
{
// TODO write session data to jdbc
}
}

View File

@ -0,0 +1,53 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* JDBCSessionManager
*
*
*/
public class JDBCSessionManager extends SessionManager
{
@Override
public void doStart() throws Exception
{
_sessionStore = new MemorySessionStore();
((AbstractSessionStore)_sessionStore).setSessionDataStore(new JDBCSessionDataStore());
super.doStart();
}
@Override
public void doStop() throws Exception
{
// TODO Auto-generated method stub
super.doStop();
}
}

View File

@ -0,0 +1,197 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* MemorySessionStore
*
*
*/
public class MemorySessionStore extends AbstractSessionStore
{
private static final Logger LOG = Log.getLogger(MemorySessionStore.class);
protected ConcurrentHashMap<String, Session> _sessions = new ConcurrentHashMap<String, Session>();
public class MemorySession extends Session
{
/**
* @param manager
* @param request
* @param data
*/
public MemorySession(HttpServletRequest request, SessionData data)
{
super(request, data);
}
/**
* @param manager
* @param data
*/
public MemorySession(SessionData data)
{
super(data);
}
}
public MemorySessionStore ()
{
super();
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#doGet(java.lang.String)
*/
@Override
public Session doGet(String id)
{
Session session = _sessions.get(id);
if (isStale(session))
{
//delete from memory
doDelete(id);
return null;
}
return session;
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#doPutIfAbsent(java.lang.String, org.eclipse.jetty.server.session.x.Session)
*/
@Override
public Session doPutIfAbsent(String id, Session session)
{
return _sessions.putIfAbsent(id, session);
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#doPut(java.lang.String, org.eclipse.jetty.server.session.x.Session)
*/
@Override
public void doPut(String id, Session session)
{
_sessions.put(id, session);
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#doExists(java.lang.String)
*/
@Override
public boolean doExists(String id)
{
return _sessions.containsKey(id);
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#doDelete(java.lang.String)
*/
@Override
public void doDelete(String id)
{
_sessions.remove(id);
}
@Override
public void shutdown ()
{
//TODO Always have a sessionDataStore, but it may be the null store!
// loop over all the sessions in memory (a few times if necessary to catch sessions that have been
// added while we're running
int loop=100;
while (!_sessions.isEmpty() && loop-- > 0)
{
for (Session session: _sessions.values())
{
//if we have a backing store and the session is dirty make sure it is written out
if (_sessionDataStore != null)
{
if (session.getSessionData().isDirty())
{
session.willPassivate();
try
{
_sessionDataStore.store(session.getId(), session.getSessionData());
}
catch (Exception e)
{
LOG.warn(e);
}
}
doDelete (session.getId()); //remove from memory
}
else
{
//TODO this will call back into our delete method
//not preserving sessions on exit
session.invalidate();
}
}
}
}
/**
* @see org.eclipse.jetty.server.session.x.SessionStore#newSession(java.lang.String)
*/
@Override
public Session newSession(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
return new MemorySession(_sessionDataStore.newSessionData(id, created, accessed, lastAccessed, maxInactiveMs));
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionStore#newSession(org.eclipse.jetty.server.session.x.SessionData)
*/
@Override
public Session newSession(SessionData data)
{
return new MemorySession (data);
}
}

View File

@ -0,0 +1,66 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* NullSessionDataStore
*
*
*/
public class NullSessionDataStore extends AbstractSessionDataStore
{
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
{
return null;
}
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#newSessionData(java.lang.String, long, long, long, long)
*/
@Override
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
return new SessionData(id, created, accessed, lastAccessed, maxInactiveMs);
}
/**
* @see org.eclipse.jetty.server.session.x.SessionDataStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
{
return true;
}
/**
* @see org.eclipse.jetty.server.session.x.AbstractSessionDataStore#doStore()
*/
@Override
public void doStore() throws Exception
{
//noop
}
}

View File

@ -0,0 +1,601 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionContext;
import javax.servlet.http.HttpSessionEvent;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* AbstractSession
*
*
*/
public class Session implements SessionManager.SessionIf
{
final static Logger LOG = Log.getLogger(Session.class); // TODO SessionHandler.LOG;
public final static String SESSION_CREATED_SECURE="org.eclipse.jetty.security.sessionCreatedSecure";
protected SessionData _sessionData;
protected SessionManager _manager;
protected String _extendedId; //the _id plus the worker name
protected long _requests;
private boolean _idChanged;
private boolean _newSession;
private boolean _doInvalidate; //remember we should invalidate this session
public Session (HttpServletRequest request, SessionData data)
{
_sessionData = data;
_newSession = true;
_requests = 1;
}
public Session (SessionData data)
{
_sessionData = data;
_requests = 1;
}
public void setSessionManager (SessionManager manager)
{
_manager = manager;
}
public void setExtendedId (String extendedId)
{
_extendedId = extendedId;
}
/* ------------------------------------------------------------- */
protected void cookieSet()
{
synchronized (this)
{
_sessionData.setCookieSet(_sessionData.getAccessed());
}
}
/* ------------------------------------------------------------ */
protected boolean access(long time)
{
synchronized(this)
{
if (!isValid())
return false;
_newSession=false;
long lastAccessed = _sessionData.getAccessed();
_sessionData.setAccessed(time);
_sessionData.setLastAccessed(lastAccessed);
int maxInterval=getMaxInactiveInterval();
_sessionData.setExpiry(maxInterval <= 0 ? 0 : (time + maxInterval*1000L));
if (checkExpiry(time))
{
invalidate();
return false;
}
_requests++;
return true;
}
}
/* ------------------------------------------------------------ */
protected void complete()
{
synchronized(this)
{
_requests--;
if (_doInvalidate && _requests<=0 )
doInvalidate();
}
}
/* ------------------------------------------------------------- */
protected void timeout() throws Exception
{
// remove session from context and invalidate other sessions with same ID.
if (_manager == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
_manager.removeSession(this,true);
// Notify listeners and unbind values
boolean do_invalidate=false;
synchronized (this)
{
if (!_sessionData.isInvalid())
{
if (_requests<=0)
do_invalidate=true;
else
_doInvalidate=true;
}
}
if (do_invalidate)
doInvalidate();
}
/* ------------------------------------------------------------- */
/** Check to see if session has expired as at the time given.
* @param time the time in milliseconds
* @return true if expired
*/
protected boolean checkExpiry(long time)
{
//TODO replace by check on SessionData object instead
if (_sessionData.getMaxInactiveMs()>0 && _sessionData.getLastAccessed()>0 && _sessionData.getLastAccessed() + _sessionData.getMaxInactiveMs() < time)
return true;
return false;
}
public void clearAttributes()
{
Set<String> keys = null;
do
{
keys = _sessionData.getKeys();
for (String key:keys)
{
setAttribute(key,null);
}
}
while (!keys.isEmpty());
}
/* ------------------------------------------------------------ */
/**
* Call binding and attribute listeners based on the new and old
* values of the attribute.
*
* @param name name of the attribute
* @param newValue new value of the attribute
* @param oldValue previous value of the attribute
*/
protected void callSessionAttributeListeners (String name, Object newValue, Object oldValue)
{
if (newValue==null || !newValue.equals(oldValue))
{
if (oldValue!=null)
unbindValue(name,oldValue);
if (newValue!=null)
bindValue(name,newValue);
if (_manager == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
_manager.doSessionAttributeListeners(this,name,oldValue,newValue);
}
}
/* ------------------------------------------------------------- */
/**
* Unbind value if value implements {@link HttpSessionBindingListener} (calls {@link HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)})
* @param name the name with which the object is bound or unbound
* @param value the bound value
*/
public void unbindValue(java.lang.String name, Object value)
{
if (value!=null&&value instanceof HttpSessionBindingListener)
((HttpSessionBindingListener)value).valueUnbound(new HttpSessionBindingEvent(this,name));
}
/* ------------------------------------------------------------- */
/**
* Bind value if value implements {@link HttpSessionBindingListener} (calls {@link HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)})
* @param name the name with which the object is bound or unbound
* @param value the bound value
*/
public void bindValue(java.lang.String name, Object value)
{
if (value!=null&&value instanceof HttpSessionBindingListener)
((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent(this,name));
}
/* ------------------------------------------------------------- */
public void didActivate()
{
synchronized(this)
{
HttpSessionEvent event = new HttpSessionEvent(this);
for (Iterator<String> iter = _sessionData.getKeys().iterator(); iter.hasNext();)
{
Object value = _sessionData.getAttribute(iter.next());
if (value instanceof HttpSessionActivationListener)
{
HttpSessionActivationListener listener = (HttpSessionActivationListener) value;
listener.sessionDidActivate(event);
}
}
}
}
/* ------------------------------------------------------------- */
public void willPassivate()
{
synchronized(this)
{
HttpSessionEvent event = new HttpSessionEvent(this);
for (Iterator<String> iter = _sessionData.getKeys().iterator(); iter.hasNext();)
{
Object value = _sessionData.getAttribute(iter.next());
if (value instanceof HttpSessionActivationListener)
{
HttpSessionActivationListener listener = (HttpSessionActivationListener) value;
listener.sessionWillPassivate(event);
}
}
}
}
/* ------------------------------------------------------------ */
public boolean isValid()
{
return !_sessionData.isInvalid();
}
/* ------------------------------------------------------------- */
public long getCookieSetTime()
{
return _sessionData.getCookieSet();
}
/* ------------------------------------------------------------- */
public void setCookieSetTime(long time)
{
_sessionData.setCookieSet(time);
}
/* ------------------------------------------------------------- */
@Override
public long getCreationTime() throws IllegalStateException
{
checkValid();
return _sessionData.getCreated();
}
/**
* @see javax.servlet.http.HttpSession#getId()
*/
@Override
public String getId()
{
return _sessionData.getId();
}
public String getExtendedId()
{
return _extendedId;
}
/**
* @see javax.servlet.http.HttpSession#getLastAccessedTime()
*/
@Override
public long getLastAccessedTime()
{
return _sessionData.getLastAccessed();
}
/**
* @see javax.servlet.http.HttpSession#getServletContext()
*/
@Override
public ServletContext getServletContext()
{
if (_manager == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
return _manager._context;
}
/**
* @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
*/
@Override
public void setMaxInactiveInterval(int secs)
{
_sessionData.setMaxInactiveMs((long)secs*1000L);
}
/**
* @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
*/
@Override
public int getMaxInactiveInterval()
{
return (int)(_sessionData.getMaxInactiveMs()/1000);
}
/**
* @see javax.servlet.http.HttpSession#getSessionContext()
*/
@Override
public HttpSessionContext getSessionContext()
{
checkValid();
return SessionManager.__nullSessionContext;
}
/* ------------------------------------------------------------- */
/**
* asserts that the session is valid
* @throws IllegalStateException if the sesion is invalid
*/
protected void checkValid() throws IllegalStateException
{
if (_sessionData.isInvalid())
throw new IllegalStateException();
}
/**
* @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
*/
@Override
public Object getAttribute(String name)
{
//TODO synchronization
checkValid();
return _sessionData.getAttribute(name);
}
/**
* @see javax.servlet.http.HttpSession#getValue(java.lang.String)
*/
@Override
public Object getValue(String name)
{
// TODO synchronization
return _sessionData.getAttribute(name);
}
/**
* @see javax.servlet.http.HttpSession#getAttributeNames()
*/
@Override
public Enumeration<String> getAttributeNames()
{
synchronized (this)
{
checkValid();
final Iterator<String> itor = _sessionData.getKeys().iterator();
return new Enumeration<String> ()
{
@Override
public boolean hasMoreElements()
{
return itor.hasNext();
}
@Override
public String nextElement()
{
return itor.next();
}
};
}
}
/* ------------------------------------------------------------ */
public int getAttributes()
{
return _sessionData.getKeys().size();
}
/* ------------------------------------------------------------ */
public Set<String> getNames()
{
return _sessionData.getKeys();
}
/* ------------------------------------------------------------- */
/**
* @deprecated As of Version 2.2, this method is replaced by
* {@link #getAttributeNames}
*/
@Deprecated
@Override
public String[] getValueNames() throws IllegalStateException
{
synchronized(this)
{
checkValid();
Iterator<String> itor = _sessionData.getKeys().iterator();
if (!itor.hasNext())
return new String[0];
ArrayList<String> names = new ArrayList<String>();
while (itor.hasNext())
names.add(itor.next());
return names.toArray(new String[names.size()]);
}
}
/**
* @see javax.servlet.http.HttpSession#setAttribute(java.lang.String, java.lang.Object)
*/
@Override
public void setAttribute(String name, Object value)
{
Object old=null;
synchronized (this)
{
//if session is not valid, don't accept the set
checkValid();
old=_sessionData.setAttribute(name,value);
}
if (value == null && old == null)
return; //if same as remove attribute but attribute was already removed, no change
callSessionAttributeListeners(name, value, old);
}
/**
* @see javax.servlet.http.HttpSession#putValue(java.lang.String, java.lang.Object)
*/
@Override
public void putValue(String name, Object value)
{
setAttribute(name,value);
}
/**
* @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
*/
@Override
public void removeAttribute(String name)
{
setAttribute(name, null);
}
/**
* @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
*/
@Override
public void removeValue(String name)
{
setAttribute(name, null);
}
/* ------------------------------------------------------------ */
public void renewId(HttpServletRequest request)
{
if (_manager == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
_manager._sessionIdManager.renewSessionId(_sessionData.getId(), getExtendedId(), request);
setIdChanged(true);
}
/* ------------------------------------------------------------- */
@Override
public void invalidate()
{
if (_manager == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
checkValid();
try
{
// remove session from context and invalidate other sessions with same ID.
_manager.removeSession(this,true);
doInvalidate();
}
catch (Exception e)
{
LOG.warn(e);
}
}
/* ------------------------------------------------------------- */
protected void doInvalidate() throws IllegalStateException
{
try
{
if (LOG.isDebugEnabled())
LOG.debug("invalidate {}",_sessionData.getId());
if (isValid())
clearAttributes();
}
finally
{
synchronized (this)
{
// mark as invalid
_sessionData.setInvalid(true);
}
}
}
/* ------------------------------------------------------------- */
@Override
public boolean isNew() throws IllegalStateException
{
checkValid();
return _newSession;
}
/* ------------------------------------------------------------- */
public void setIdChanged(boolean changed)
{
_idChanged=changed;
}
public boolean isIdChanged ()
{
return _idChanged;
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionManager.SessionIf#getSession()
*/
@Override
public Session getSession()
{
// TODO why is this used
return this;
}
protected SessionData getSessionData()
{
return _sessionData;
}
}

View File

@ -0,0 +1,238 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* SessionData
*
* The data associated with a session
*/
public class SessionData implements Serializable
{
protected String _id;
protected String _contextPath;
protected String _vhost;
protected String _lastNode;
protected long _expiry;
protected long _created;
protected long _cookieSet;
protected long _accessed; // the time of the last access
protected long _lastAccessed; // the time of the last access excluding this one
protected boolean _invalid;
protected long _maxInactiveMs;
protected Map<String,Object> _attributes = new ConcurrentHashMap<String, Object>();
protected boolean _dirty;
public SessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
_id = id;
_created = created;
_accessed = accessed;
_lastAccessed = lastAccessed;
_maxInactiveMs = maxInactiveMs;
}
public boolean isDirty()
{
return _dirty;
}
public void setDirty(boolean dirty)
{
_dirty = dirty;
}
public Object getAttribute (String name)
{
return _attributes.get(name);
}
public Set<String> getKeys()
{
return _attributes.keySet();
}
public Object setAttribute (String name, Object value)
{
Object old = (value==null?_attributes.remove(name):_attributes.put(name,value));
if (value == null && old == null)
return old; //if same as remove attribute but attribute was already removed, no change
_dirty = true;
return old;
}
public String getId()
{
return _id;
}
public void setId(String id)
{
_id = id;
}
public String getContextPath()
{
return _contextPath;
}
public void setContextPath(String contextPath)
{
_contextPath = contextPath;
}
public String getVhost()
{
return _vhost;
}
public void setVhost(String vhost)
{
_vhost = vhost;
}
public String getLastNode()
{
return _lastNode;
}
public void setLastNode(String lastNode)
{
_lastNode = lastNode;
}
public long getExpiry()
{
return _expiry;
}
public void setExpiry(long expiry)
{
_expiry = expiry;
}
public long getCreated()
{
return _created;
}
public void setCreated(long created)
{
_created = created;
}
public long getCookieSet()
{
return _cookieSet;
}
public void setCookieSet(long cookieSet)
{
_cookieSet = cookieSet;
}
public long getAccessed()
{
return _accessed;
}
public void setAccessed(long accessed)
{
_accessed = accessed;
}
public long getLastAccessed()
{
return _lastAccessed;
}
public void setLastAccessed(long lastAccessed)
{
_lastAccessed = lastAccessed;
}
public boolean isInvalid()
{
return _invalid;
}
public void setInvalid(boolean invalid)
{
_invalid = invalid;
}
public long getMaxInactiveMs()
{
return _maxInactiveMs;
}
public void setMaxInactiveMs(long maxInactive)
{
_maxInactiveMs = maxInactive;
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException
{
out.writeUTF(_id); //session id
out.writeUTF(_contextPath); //context path
out.writeUTF(_vhost); //first vhost
out.writeLong(_accessed);//accessTime
out.writeLong(_lastAccessed); //lastAccessTime
out.writeLong(_created); //time created
out.writeLong(_cookieSet);//time cookie was set
out.writeUTF(_lastNode); //name of last node managing
out.writeLong(_expiry);
out.writeLong(_maxInactiveMs);
out.writeObject(_attributes);
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
{
_id = in.readUTF();
_contextPath = in.readUTF();
_vhost = in.readUTF();
_accessed = in.readLong();//accessTime
_lastAccessed = in.readLong(); //lastAccessTime
_created = in.readLong(); //time created
_cookieSet = in.readLong();//time cookie was set
_lastNode = in.readUTF(); //last managing node
_expiry = in.readLong();
_maxInactiveMs = in.readLong();
_attributes = (HashMap<String,Object>)in.readObject();
}
}

View File

@ -0,0 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
import javax.servlet.http.HttpServletRequest;
/**
* SessionDataFactory
*
*
*/
public interface SessionDataFactory
{
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
public SessionData newSessionData (HttpServletRequest request);
}

View File

@ -0,0 +1,68 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* SessionDataStore
*
* A (usually persistent) store for the data contained in a Session.
*/
public interface SessionDataStore
{
/**
* Read in session data from storage
* @param id
* @return
* @throws Exception
*/
public SessionData load (String id) throws Exception;
/**
* Create a new SessionData
* @return
*/
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
/**
* Write out session data to storage
* @param id
* @param data
* @throws Exception
*/
public void store (String id, SessionData data) throws Exception;
/**
* Delete session data from storage
* @param id
* @return
* @throws Exception
*/
public boolean delete (String id) throws Exception;
}

View File

@ -0,0 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
import javax.servlet.http.HttpServletRequest;
/**
* SessionFactory
*
*
*/
public interface SessionFactory
{
public SessionManager.SessionIf newSession (HttpServletRequest request);
public SessionManager.SessionIf newSession (SessionData data);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.x;
/**
* SessionStore
*
* A store/cache of Session objects. This store of Session objects can be backed by
* a SessionDataStore to persist/distribute the data contained in the Session objects.
*/
public interface SessionStore
{
Session newSession (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
Session get(String id) throws Exception;
void put(String id, Session session) throws Exception;
boolean exists (String id) throws Exception;
Session putIfAbsent(String id, Session session) throws Exception;
boolean delete (String id) throws Exception;
void shutdown ();
}

View File

@ -137,10 +137,10 @@ public class SessionCookieTest
{
/**
* @see org.eclipse.jetty.server.SessionIdManager#idInUse(java.lang.String)
* @see org.eclipse.jetty.server.SessionIdManager#isIdInUse(java.lang.String)
*/
@Override
public boolean idInUse(String id)
public boolean isIdInUse(String id)
{
return false;
}

View File

@ -143,8 +143,8 @@ public abstract class AbstractSessionRenewTest
AbstractSessionManager sessionManager = (AbstractSessionManager)((AbstractSession)afterSession).getSessionManager();
AbstractSessionIdManager sessionIdManager = (AbstractSessionIdManager)sessionManager.getSessionIdManager();
assertTrue(sessionIdManager.idInUse(afterSessionId));
assertFalse(sessionIdManager.idInUse(beforeSessionId));
assertTrue(sessionIdManager.isIdInUse(afterSessionId));
assertFalse(sessionIdManager.isIdInUse(beforeSessionId));
HttpSession session = sessionManager.getSession(afterSessionId);
assertNotNull(session);