Methods Summary |
---|
public void | addLifecycleListener(org.apache.catalina.LifecycleListener listener)Add a lifecycle event listener to this component.
lifecycle.addLifecycleListener(listener);
|
protected void | changeSessionID(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response, java.lang.String sessionId, java.lang.String newSessionID, org.apache.catalina.Session catalinaSession)change session id and send to all cluster nodes
lifecycle.fireLifecycleEvent("Before session migration",
catalinaSession);
request.setRequestedSessionId(newSessionID);
catalinaSession.setId(newSessionID);
if (catalinaSession instanceof DeltaSession)
((DeltaSession) catalinaSession).resetDeltaRequest();
if(request.isRequestedSessionIdFromCookie()) setNewSessionCookie(request, response,newSessionID);
// set orginal sessionid at request, to allow application detect the
// change
if (sessionIdAttribute != null && !"".equals(sessionIdAttribute)) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.set.orignalsessionid",sessionIdAttribute,sessionId));
}
request.setAttribute(sessionIdAttribute, sessionId);
}
// now sending the change to all other clusternode!
ClusterManager manager = (ClusterManager)catalinaSession.getManager();
sendSessionIDClusterBackup(manager,request,sessionId, newSessionID);
lifecycle
.fireLifecycleEvent("After session migration", catalinaSession);
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.changeSession", sessionId,
newSessionID));
}
|
public org.apache.catalina.LifecycleListener[] | findLifecycleListeners()Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned.
return lifecycle.findLifecycleListeners();
|
public org.apache.catalina.ha.CatalinaCluster | getCluster()
return cluster;
|
public boolean | getEnabled()
return enabled;
|
public java.lang.String | getInfo()Return descriptive information about this implementation.
/*--Logic---------------------------------------------------*/
return (info);
|
protected java.lang.String | getLocalJvmRoute(org.apache.catalina.connector.Request request)get jvmroute from engine
Manager manager = getManager(request);
if(manager instanceof ManagerBase)
return ((ManagerBase) manager).getJvmRoute();
return null ;
|
protected org.apache.catalina.Manager | getManager(org.apache.catalina.connector.Request request)get Cluster DeltaManager
Manager manager = request.getContext().getManager();
if (log.isDebugEnabled()) {
if(manager != null)
log.debug(sm.getString("jvmRoute.foundManager", manager, request.getContext().getName()));
else
log.debug(sm.getString("jvmRoute.notFoundManager", manager, request.getContext().getName()));
}
return manager;
|
public long | getNumberOfSessions()
return numberOfSessions;
|
public java.lang.String | getSessionIdAttribute()set session id attribute to failed node for request.
return sessionIdAttribute;
|
protected void | handleJvmRoute(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response, java.lang.String sessionId, java.lang.String localJvmRoute)Handle jvmRoute stickyness after tomcat instance failed. After this
correction a new Cookie send to client with new jvmRoute and the
SessionID change propage to the other cluster nodes.
// get requested jvmRoute.
String requestJvmRoute = null;
int index = sessionId.indexOf(".");
if (index > 0) {
requestJvmRoute = sessionId
.substring(index + 1, sessionId.length());
}
if (requestJvmRoute != null && !requestJvmRoute.equals(localJvmRoute)) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.failover", requestJvmRoute,
localJvmRoute, sessionId));
}
// OK - turnover the session ?
String newSessionID = sessionId.substring(0, index) + "."
+ localJvmRoute;
Session catalinaSession = null;
try {
catalinaSession = getManager(request).findSession(sessionId);
} catch (IOException e) {
// Hups!
}
if (catalinaSession != null) {
changeSessionID(request, response, sessionId, newSessionID,
catalinaSession);
numberOfSessions++;
} else {
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.cannotFindSession",
sessionId));
}
}
}
|
protected void | handlePossibleTurnover(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)handle possible session turn over.
Session session = request.getSessionInternal(false);
if (session != null) {
long t1 = System.currentTimeMillis();
String jvmRoute = getLocalJvmRoute(request);
if (jvmRoute == null) {
if (log.isDebugEnabled())
log.debug(sm.getString("jvmRoute.missingJvmRouteAttribute"));
return;
}
handleJvmRoute( request, response,session.getIdInternal(), jvmRoute);
if (log.isDebugEnabled()) {
long t2 = System.currentTimeMillis();
long time = t2 - t1;
log.debug(sm.getString("jvmRoute.turnoverInfo", new Long(time)));
}
}
|
public void | invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)Detect possible the JVMRoute change at cluster backup node..
if (getEnabled()
&& getCluster() != null
&& request.getContext() != null
&& request.getContext().getDistributable() ) {
// valve cluster can access manager - other cluster handle turnover
// at host level - hopefully!
Manager manager = request.getContext().getManager();
if (manager != null && manager instanceof ClusterManager
&& getCluster().getManager(((ClusterManager)manager).getName()) != null)
handlePossibleTurnover(request, response);
}
// Pass this request on to the next valve in our pipeline
getNext().invoke(request, response);
|
public void | removeLifecycleListener(org.apache.catalina.LifecycleListener listener)Remove a lifecycle event listener from this component.
lifecycle.removeLifecycleListener(listener);
|
protected void | sendSessionIDClusterBackup(org.apache.catalina.ha.ClusterManager manager, org.apache.catalina.connector.Request request, java.lang.String sessionId, java.lang.String newSessionID)Send the changed Sessionid to all clusternodes.
SessionIDMessage msg = new SessionIDMessage();
msg.setOrignalSessionID(sessionId);
msg.setBackupSessionID(newSessionID);
Context context = request.getContext();
msg.setContextPath(context.getPath());
msg.setHost(context.getParent().getName());
if(manager.doDomainReplication())
cluster.sendClusterDomain(msg);
else
cluster.send(msg);
|
public void | setCluster(org.apache.catalina.ha.CatalinaCluster cluster)
this.cluster = cluster;
|
public void | setEnabled(boolean enabled)
this.enabled = enabled;
|
protected void | setNewSessionCookie(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response, java.lang.String sessionId)Sets a new cookie for the given session id and response and see
{@link org.apache.catalina.connector.Request#configureSessionCookie(javax.servlet.http.Cookie)}
if (response != null) {
Context context = request.getContext();
if (context.getCookies()) {
// set a new session cookie
Cookie newCookie = new Cookie(Globals.SESSION_COOKIE_NAME,
sessionId);
newCookie.setMaxAge(-1);
String contextPath = null;
if (!response.getConnector().getEmptySessionPath()
&& (context != null)) {
contextPath = context.getEncodedPath();
}
if ((contextPath != null) && (contextPath.length() > 0)) {
newCookie.setPath(contextPath);
} else {
newCookie.setPath("/");
}
if (request.isSecure()) {
newCookie.setSecure(true);
}
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.newSessionCookie",
sessionId, Globals.SESSION_COOKIE_NAME, newCookie
.getPath(), new Boolean(newCookie
.getSecure())));
}
response.addCookie(newCookie);
}
}
|
public void | setSessionIdAttribute(java.lang.String sessionIdAttribute)get name of failed reqeust session attribute
this.sessionIdAttribute = sessionIdAttribute;
|
public void | start()Prepare for the beginning of active use of the public methods of this
component. This method should be called after configure() ,
and before any of the public methods of the component are utilized.
// Validate and update our current component state
if (started)
throw new LifecycleException(sm
.getString("jvmRoute.valve.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
if (cluster == null) {
Container hostContainer = getContainer();
// compatibility with JvmRouteBinderValve version 1.1
// ( setup at context.xml or context.xml.default )
if (!(hostContainer instanceof Host)) {
if (log.isWarnEnabled())
log.warn(sm.getString("jvmRoute.configure.warn"));
hostContainer = hostContainer.getParent();
}
if (hostContainer instanceof Host
&& ((Host) hostContainer).getCluster() != null) {
cluster = (CatalinaCluster) ((Host) hostContainer).getCluster();
} else {
Container engine = hostContainer.getParent() ;
if (engine instanceof Engine
&& ((Engine) engine).getCluster() != null) {
cluster = (CatalinaCluster) ((Engine) engine).getCluster();
}
}
}
if (cluster == null) {
throw new RuntimeException("No clustering support at container "
+ container.getName());
}
if (log.isInfoEnabled())
log.info(sm.getString("jvmRoute.valve.started"));
|
public void | stop()Gracefully terminate the active use of the public methods of this
component. This method should be the last one called on a given instance
of this component.
// Validate and update our current component state
if (!started)
throw new LifecycleException(sm
.getString("jvmRoute.valve.notStarted"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
cluster = null;
numberOfSessions = 0;
if (log.isInfoEnabled())
log.info(sm.getString("jvmRoute.valve.stopped"));
|