cleaned up sessionIdManager setters

This commit is contained in:
Greg Wilkins 2011-07-07 12:56:37 +10:00
parent fc5e92c43f
commit 17ce8ec161
8 changed files with 63 additions and 33 deletions

View File

@ -1286,7 +1286,7 @@ public class Request implements HttpServletRequest
return false;
HttpSession session=getSession(false);
return (session != null && _sessionManager.getIdManager().getClusterId(_requestedSessionId).equals(_sessionManager.getClusterId(session)));
return (session != null && _sessionManager.getSessionIdManager().getClusterId(_requestedSessionId).equals(_sessionManager.getClusterId(session)));
}
/* ------------------------------------------------------------ */

View File

@ -187,14 +187,14 @@ public interface SessionManager extends LifeCycle
/* ------------------------------------------------------------ */
/**
* @return the cross context session id manager.
* @see #setIdManager(SessionIdManager)
* @see #setSessionIdManager(SessionIdManager)
*/
public SessionIdManager getIdManager();
public SessionIdManager getSessionIdManager();
/* ------------------------------------------------------------ */
/**
* @return the cross context session id manager.
* @deprecated use {@link #getIdManager()}
* @deprecated use {@link #getSessionIdManager()}
*/
@Deprecated
public SessionIdManager getMetaManager();
@ -204,9 +204,9 @@ public interface SessionManager extends LifeCycle
* Sets the cross context session id manager
*
* @param idManager the cross context session id manager.
* @see #getIdManager()
* @see #getSessionIdManager()
*/
public void setIdManager(SessionIdManager idManager);
public void setSessionIdManager(SessionIdManager idManager);
/* ------------------------------------------------------------ */
/**

View File

@ -108,6 +108,18 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
{
}
/* ------------------------------------------------------------ */
public ContextHandler.Context getContext()
{
return _context;
}
/* ------------------------------------------------------------ */
public ContextHandler getContextHandler()
{
return _context.getContextHandler();
}
/* ------------------------------------------------------------ */
public HttpCookie access(HttpSession session,boolean secure)
{
@ -237,7 +249,7 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
/* ------------------------------------------------------------ */
public HttpSession getHttpSession(String nodeId)
{
String cluster_id = getIdManager().getClusterId(nodeId);
String cluster_id = getSessionIdManager().getClusterId(nodeId);
AbstractSession session = getSession(cluster_id);
if (session!=null && !session.getNodeId().equals(nodeId))
@ -245,12 +257,21 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
return session;
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/**
* @return Returns the metaManager used for cross context session management
* @deprecated Use {@link #getSessionIdManager()}
*/
public SessionIdManager getIdManager()
{
return getSessionIdManager();
}
/* ------------------------------------------------------------ */
/**
* @return Returns the SessionIdManager used for cross context session management
*/
public SessionIdManager getSessionIdManager()
{
return _sessionIdManager;
}
@ -300,12 +321,12 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
/* ------------------------------------------------------------ */
/**
* @deprecated use {@link #getIdManager()}
* @deprecated use {@link #getSessionIdManager()}
*/
@Deprecated
public SessionIdManager getMetaManager()
{
return getIdManager();
return getSessionIdManager();
}
/* ------------------------------------------------------------ */
@ -491,12 +512,21 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
_httpOnly=httpOnly;
}
/* ------------------------------------------------------------ */
/**
* @param metaManager The metaManager used for cross context session management.
* @deprecated use {@link #setSessionIdManager(SessionIdManager)}
*/
public void setIdManager(SessionIdManager metaManager)
{
setSessionIdManager(metaManager);
}
/* ------------------------------------------------------------ */
/**
* @param metaManager The metaManager used for cross context session management.
*/
public void setIdManager(SessionIdManager metaManager)
public void setSessionIdManager(SessionIdManager metaManager)
{
_sessionIdManager=metaManager;
}
@ -522,12 +552,12 @@ public abstract class AbstractSessionManager extends AbstractLifeCycle implement
/* ------------------------------------------------------------ */
/**
* @deprecated use {@link #setIdManager(SessionIdManager)}
* @deprecated use {@link #setSessionIdManager(SessionIdManager)}
*/
@Deprecated
public void setMetaManager(SessionIdManager metaManager)
{
setIdManager(metaManager);
setSessionIdManager(metaManager);
}
/* ------------------------------------------------------------ */

View File

@ -105,7 +105,7 @@ public class JDBCSessionManager extends AbstractSessionManager
_created=System.currentTimeMillis();
_accessed = _created;
_attributes = new HashMap<String,Object>();
_lastNode = getIdManager().getWorkerName();
_lastNode = getSessionIdManager().getWorkerName();
}
public SessionData (String sessionId,Map<String,Object> attributes)
@ -114,7 +114,7 @@ public class JDBCSessionManager extends AbstractSessionManager
_created=System.currentTimeMillis();
_accessed = _created;
_attributes = attributes;
_lastNode = getIdManager().getWorkerName();
_lastNode = getSessionIdManager().getWorkerName();
}
public synchronized String getId ()
@ -511,7 +511,7 @@ public class JDBCSessionManager extends AbstractSessionManager
" lastSaved="+(session==null?0:session._data._lastSaved)+
" interval="+(_saveIntervalSec * 1000)+
" lastNode="+session._data.getLastNode()+
" thisNode="+getIdManager().getWorkerName()+
" thisNode="+getSessionIdManager().getWorkerName()+
" difference="+(now - session._data._lastSaved));
}
@ -533,13 +533,13 @@ public class JDBCSessionManager extends AbstractSessionManager
if (data != null)
{
if (!data.getLastNode().equals(getIdManager().getWorkerName()) || session==null)
if (!data.getLastNode().equals(getSessionIdManager().getWorkerName()) || session==null)
{
//if the session has no expiry, or it is not already expired
if (data._expiryTime <= 0 || data._expiryTime > now)
{
Log.debug("getSession("+idInCluster+"): lastNode="+data.getLastNode()+" thisNode="+getIdManager().getWorkerName());
data.setLastNode(getIdManager().getWorkerName());
Log.debug("getSession("+idInCluster+"): lastNode="+data.getLastNode()+" thisNode="+getSessionIdManager().getWorkerName());
data.setLastNode(getSessionIdManager().getWorkerName());
//session last used on a different node, or we don't have it in memory
session = new Session(now,data);
_sessions.put(idInCluster, session);
@ -879,7 +879,7 @@ public class JDBCSessionManager extends AbstractSessionManager
data.setCanonicalContext(result.getString("contextPath"));
data.setVirtualHost(result.getString("virtualHost"));
InputStream is = ((JDBCSessionIdManager)getIdManager())._dbAdaptor.getBlobInputStream(result, "map");
InputStream is = ((JDBCSessionIdManager)getSessionIdManager())._dbAdaptor.getBlobInputStream(result, "map");
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream (is);
Object o = ois.readObject();
data.setAttributeMap((Map<String,Object>)o);
@ -942,7 +942,7 @@ public class JDBCSessionManager extends AbstractSessionManager
statement.setString(2, data.getId()); //session id
statement.setString(3, data.getCanonicalContext()); //context path
statement.setString(4, data.getVirtualHost()); //first vhost
statement.setString(5, getIdManager().getWorkerName());//my node id
statement.setString(5, getSessionIdManager().getWorkerName());//my node id
statement.setLong(6, data.getAccessed());//accessTime
statement.setLong(7, data.getLastAccessed()); //lastAccessTime
statement.setLong(8, data.getCreated()); //time created
@ -993,7 +993,7 @@ public class JDBCSessionManager extends AbstractSessionManager
long now = System.currentTimeMillis();
connection.setAutoCommit(true);
statement = connection.prepareStatement(__updateSession);
statement.setString(1, getIdManager().getWorkerName());//my node id
statement.setString(1, getSessionIdManager().getWorkerName());//my node id
statement.setLong(2, data.getAccessed());//accessTime
statement.setLong(3, data.getLastAccessed()); //lastAccessTime
statement.setLong(4, now); //last saved time
@ -1030,7 +1030,7 @@ public class JDBCSessionManager extends AbstractSessionManager
protected void updateSessionNode (SessionData data)
throws Exception
{
String nodeId = getIdManager().getWorkerName();
String nodeId = getSessionIdManager().getWorkerName();
Connection connection = getConnection();
PreparedStatement statement = null;
try
@ -1067,7 +1067,7 @@ public class JDBCSessionManager extends AbstractSessionManager
long now = System.currentTimeMillis();
connection.setAutoCommit(true);
statement = connection.prepareStatement(__updateSessionAccessTime);
statement.setString(1, getIdManager().getWorkerName());
statement.setString(1, getSessionIdManager().getWorkerName());
statement.setLong(2, data.getAccessed());
statement.setLong(3, data.getLastAccessed());
statement.setLong(4, now);
@ -1127,7 +1127,7 @@ public class JDBCSessionManager extends AbstractSessionManager
private Connection getConnection ()
throws SQLException
{
return ((JDBCSessionIdManager)getIdManager()).getConnection();
return ((JDBCSessionIdManager)getSessionIdManager()).getConnection();
}
/**

View File

@ -331,7 +331,7 @@ public class ResponseTest
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(false);
AbstractSessionManager manager=new HashSessionManager();
manager.setIdManager(new HashSessionIdManager());
manager.setSessionIdManager(new HashSessionIdManager());
request.setSessionManager(manager);
request.setSession(new TestSession(manager,"12345"));
@ -379,7 +379,7 @@ public class ResponseTest
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(false);
AbstractSessionManager manager=new HashSessionManager();
manager.setIdManager(new HashSessionIdManager());
manager.setSessionIdManager(new HashSessionIdManager());
request.setSessionManager(manager);
request.setSession(new TestSession(manager,"12345"));
manager.setCheckingRemoteSessionIdEncoding(false);

View File

@ -417,7 +417,7 @@ public class SessionHandlerTest
return null;
}
public SessionIdManager getIdManager()
public SessionIdManager getSessionIdManager()
{
return null;
}
@ -496,7 +496,7 @@ public class SessionHandlerTest
{
}
public void setIdManager(SessionIdManager idManager)
public void setSessionIdManager(SessionIdManager idManager)
{
}

View File

@ -79,7 +79,7 @@ public class JdbcTestServer extends AbstractTestServer
public SessionManager newSessionManager()
{
JDBCSessionManager manager = new JDBCSessionManager();
manager.setIdManager((JDBCSessionIdManager)_sessionIdManager);
manager.setSessionIdManager((JDBCSessionIdManager)_sessionIdManager);
manager.setSaveInterval(SAVE_INTERVAL); //ensure we save any changes to the session at least once per second
return manager;
}

View File

@ -71,7 +71,7 @@ public abstract class AbstractTestServer
ServletContextHandler context = new ServletContextHandler(_contexts, contextPath);
SessionManager sessionManager = newSessionManager();
sessionManager.setIdManager(_sessionIdManager);
sessionManager.setSessionIdManager(_sessionIdManager);
sessionManager.setMaxInactiveInterval(_maxInactivePeriod);
SessionHandler sessionHandler = newSessionHandler(sessionManager);
@ -96,7 +96,7 @@ public abstract class AbstractTestServer
WebAppContext context = new WebAppContext(_contexts, warPath, contextPath);
SessionManager sessionManager = newSessionManager();
sessionManager.setIdManager(_sessionIdManager);
sessionManager.setSessionIdManager(_sessionIdManager);
sessionManager.setMaxInactiveInterval(_maxInactivePeriod);
SessionHandler sessionHandler = newSessionHandler(sessionManager);