You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/05/23 12:08:43 UTC
[tomcat] branch 7.0.x updated: Review o.a.catalina.ha.session and
minimise diff
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new 110d281 Review o.a.catalina.ha.session and minimise diff
110d281 is described below
commit 110d281d4cf37da85ec5ab0eca853af5e5774e53
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu May 23 13:08:20 2019 +0100
Review o.a.catalina.ha.session and minimise diff
First pass at reducing diff between 9.0.x. 8.5.x and 7.0.x to simplify
backports. Mostly whitespace and NO-OP refactorings.
---
.../apache/catalina/ha/session/BackupManager.java | 17 +-
.../catalina/ha/session/ClusterManagerBase.java | 37 ++-
.../ha/session/ClusterSessionListener.java | 9 +-
.../apache/catalina/ha/session/DeltaManager.java | 314 +++++++++++++--------
.../apache/catalina/ha/session/DeltaRequest.java | 59 ++--
.../apache/catalina/ha/session/DeltaSession.java | 28 +-
.../catalina/ha/session/JvmRouteBinderValve.java | 73 ++---
.../apache/catalina/ha/session/SessionMessage.java | 12 +-
.../catalina/ha/session/SessionMessageImpl.java | 16 +-
.../catalina/ha/session/mbeans-descriptors.xml | 18 +-
10 files changed, 330 insertions(+), 253 deletions(-)
diff --git a/java/org/apache/catalina/ha/session/BackupManager.java b/java/org/apache/catalina/ha/session/BackupManager.java
index 996564d..565a824 100644
--- a/java/org/apache/catalina/ha/session/BackupManager.java
+++ b/java/org/apache/catalina/ha/session/BackupManager.java
@@ -17,7 +17,6 @@
package org.apache.catalina.ha.session;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.apache.catalina.DistributedManager;
@@ -45,7 +44,7 @@ public class BackupManager extends ClusterManagerBase
/**
* The string manager for this package.
*/
- protected static final StringManager sm = StringManager.getManager(Constants.Package);
+ protected static final StringManager sm = StringManager.getManager(BackupManager.class);
protected static long DEFAULT_REPL_TIMEOUT = 15000;//15 seconds
@@ -132,7 +131,7 @@ public class BackupManager extends ClusterManagerBase
//=========================================================================
@Override
public void objectMadePrimay(Object key, Object value) {
- if (value!=null && value instanceof DeltaSession) {
+ if (value instanceof DeltaSession) {
DeltaSession session = (DeltaSession)value;
synchronized (session) {
session.access();
@@ -172,10 +171,9 @@ public class BackupManager extends ClusterManagerBase
try {
if (cluster == null) throw new LifecycleException(sm.getString("backupManager.noCluster", getName()));
- LazyReplicatedMap<String,Session> map =
- new LazyReplicatedMap<String,Session>(this,
- cluster.getChannel(), rpcTimeout, getMapName(),
- getClassLoaders(), terminateOnStartFailure);
+ LazyReplicatedMap<String,Session> map = new LazyReplicatedMap<String,Session>(
+ this, cluster.getChannel(), rpcTimeout, getMapName(),
+ getClassLoaders(), terminateOnStartFailure);
map.setChannelSendOptions(mapSendOptions);
map.setAccessTimeout(accessTimeout);
this.sessions = map;
@@ -286,9 +284,8 @@ public class BackupManager extends ClusterManagerBase
Set<String> sessionIds = new HashSet<String>();
LazyReplicatedMap<String,Session> map =
(LazyReplicatedMap<String,Session>)sessions;
- Iterator<String> keys = map.keySetFull().iterator();
- while (keys.hasNext()) {
- sessionIds.add(keys.next());
+ for (String id : map.keySetFull()) {
+ sessionIds.add(id);
}
return sessionIds;
}
diff --git a/java/org/apache/catalina/ha/session/ClusterManagerBase.java b/java/org/apache/catalina/ha/session/ClusterManagerBase.java
index 89121aa..684b6b4 100644
--- a/java/org/apache/catalina/ha/session/ClusterManagerBase.java
+++ b/java/org/apache/catalina/ha/session/ClusterManagerBase.java
@@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.catalina.ha.session;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import org.apache.catalina.Cluster;
import org.apache.catalina.Container;
@@ -39,8 +39,7 @@ import org.apache.tomcat.util.collections.SynchronizedStack;
*
* @author Filip Hanik
*/
-public abstract class ClusterManagerBase extends ManagerBase
- implements ClusterManager {
+public abstract class ClusterManagerBase extends ManagerBase implements ClusterManager {
private final Log log = LogFactory.getLog(ClusterManagerBase.class); // must not be static
@@ -147,21 +146,25 @@ public abstract class ClusterManagerBase extends ManagerBase
public static ClassLoader[] getClassLoaders(Container container) {
- Loader loader = null;
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ Loader loader = container.getLoader();
ClassLoader classLoader = null;
- if (container != null) loader = container.getLoader();
- if (loader != null) classLoader = loader.getClassLoader();
- else classLoader = Thread.currentThread().getContextClassLoader();
- if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
+ if (loader != null) {
+ classLoader = loader.getClassLoader();
+ }
+ if (classLoader == null) {
+ classLoader = tccl;
+ }
+ if (classLoader == tccl) {
return new ClassLoader[] {classLoader};
} else {
- return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
+ return new ClassLoader[] {classLoader, tccl};
}
}
public ClassLoader[] getClassLoaders() {
- return getClassLoaders(container);
+ return getClassLoaders(getContainer());
}
@Override
@@ -209,14 +212,22 @@ public abstract class ClusterManagerBase extends ManagerBase
copy.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
if (getSessionIdGenerator() != null) {
try {
- SessionIdGenerator copyIdGenerator = sessionIdGeneratorClass.newInstance();
+ SessionIdGenerator copyIdGenerator = sessionIdGeneratorClass.getConstructor().newInstance();
copyIdGenerator.setSessionIdLength(getSessionIdGenerator().getSessionIdLength());
copyIdGenerator.setJvmRoute(getSessionIdGenerator().getJvmRoute());
copy.setSessionIdGenerator(copyIdGenerator);
} catch (InstantiationException e) {
- // Ignore
+ // Ignore
} catch (IllegalAccessException e) {
- // Ignore
+ // Ignore
+ } catch (IllegalArgumentException e) {
+ // Ignore
+ } catch (SecurityException e) {
+ // Ignore
+ } catch (InvocationTargetException e) {
+ // Ignore
+ } catch (NoSuchMethodException e) {
+ // Ignore
}
}
copy.setRecordAllActions(isRecordAllActions());
diff --git a/java/org/apache/catalina/ha/session/ClusterSessionListener.java b/java/org/apache/catalina/ha/session/ClusterSessionListener.java
index 49ffe40..5830e1e 100644
--- a/java/org/apache/catalina/ha/session/ClusterSessionListener.java
+++ b/java/org/apache/catalina/ha/session/ClusterSessionListener.java
@@ -60,13 +60,13 @@ public class ClusterSessionListener extends ClusterListener {
/**
* Callback from the cluster, when a message is received, The cluster will
* broadcast it invoking the messageReceived on the receiver.
- *
+ *
* @param myobj
* ClusterMessage - the message received from the cluster
*/
@Override
public void messageReceived(ClusterMessage myobj) {
- if (myobj != null && myobj instanceof SessionMessage) {
+ if (myobj instanceof SessionMessage) {
SessionMessage msg = (SessionMessage) myobj;
String ctxname = msg.getContextName();
//check if the message is a EVT_GET_ALL_SESSIONS,
@@ -104,12 +104,11 @@ public class ClusterSessionListener extends ClusterListener {
}
}
}
- return;
}
/**
* Accept only SessionMessage
- *
+ *
* @param msg
* ClusterMessage
* @return boolean - returns true to indicate that messageReceived should be
@@ -118,7 +117,7 @@ public class ClusterSessionListener extends ClusterListener {
*/
@Override
public boolean accept(ClusterMessage msg) {
- return (msg instanceof SessionMessage);
+ return msg instanceof SessionMessage;
}
}
diff --git a/java/org/apache/catalina/ha/session/DeltaManager.java b/java/org/apache/catalina/ha/session/DeltaManager.java
index 0ee5251..6531c60 100644
--- a/java/org/apache/catalina/ha/session/DeltaManager.java
+++ b/java/org/apache/catalina/ha/session/DeltaManager.java
@@ -24,7 +24,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;
-import java.util.Iterator;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
@@ -37,6 +36,8 @@ import org.apache.catalina.ha.ClusterMessage;
import org.apache.catalina.session.ManagerBase;
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.io.ReplicationStream;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
@@ -60,12 +61,12 @@ import org.apache.tomcat.util.res.StringManager;
public class DeltaManager extends ClusterManagerBase{
// ---------------------------------------------------- Security Classes
- public final org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(DeltaManager.class);
+ public final Log log = LogFactory.getLog(DeltaManager.class);
/**
* The string manager for this package.
*/
- protected static final StringManager sm = StringManager.getManager(Constants.Package);
+ protected static final StringManager sm = StringManager.getManager(DeltaManager.class);
// ----------------------------------------------------- Instance Variables
@@ -94,12 +95,12 @@ public class DeltaManager extends ClusterManagerBase{
*/
private int sendAllSessionsWaitTime = 2 * 1000 ;
private ArrayList<SessionMessage> receivedMessageQueue =
- new ArrayList<SessionMessage>() ;
+ new ArrayList<SessionMessage>() ;
private boolean receiverQueue = false ;
private boolean stateTimestampDrop = true ;
private volatile long stateTransferCreateSendTime;
- // ------------------------------------------------------------------ stats attributes
+ // -------------------------------------------------------- stats attributes
private long sessionReplaceCounter = 0 ;
private long counterReceive_EVT_GET_ALL_SESSIONS = 0 ;
@@ -309,8 +310,7 @@ public class DeltaManager extends ClusterManagerBase{
}
/**
- * is session state transfered complete?
- *
+ * @return <code>true</code> if the state transfer is complete.
*/
public boolean getStateTransfered() {
return stateTransfered;
@@ -333,7 +333,7 @@ public class DeltaManager extends ClusterManagerBase{
}
/**
- * @return Returns the sendAllSessionsWaitTime in msec
+ * @return the sendAllSessionsWaitTime in msec
*/
public int getSendAllSessionsWaitTime() {
return sendAllSessionsWaitTime;
@@ -347,7 +347,7 @@ public class DeltaManager extends ClusterManagerBase{
}
/**
- * @return Returns the stateTimestampDrop.
+ * @return the stateTimestampDrop.
*/
public boolean isStateTimestampDrop() {
return stateTimestampDrop;
@@ -362,7 +362,7 @@ public class DeltaManager extends ClusterManagerBase{
/**
*
- * @return Returns the sendAllSessions.
+ * @return the sendAllSessions.
*/
public boolean isSendAllSessions() {
return sendAllSessions;
@@ -376,7 +376,7 @@ public class DeltaManager extends ClusterManagerBase{
}
/**
- * @return Returns the sendAllSessionsSize.
+ * @return the sendAllSessionsSize.
*/
public int getSendAllSessionsSize() {
return sendAllSessionsSize;
@@ -390,16 +390,18 @@ public class DeltaManager extends ClusterManagerBase{
}
/**
- * @return Returns the notifySessionListenersOnReplication.
+ * @return the notifySessionListenersOnReplication.
*/
public boolean isNotifySessionListenersOnReplication() {
return notifySessionListenersOnReplication;
}
/**
- * @param notifyListenersCreateSessionOnReplication The notifySessionListenersOnReplication to set.
+ * @param notifyListenersCreateSessionOnReplication
+ * The notifySessionListenersOnReplication to set.
*/
- public void setNotifySessionListenersOnReplication(boolean notifyListenersCreateSessionOnReplication) {
+ public void setNotifySessionListenersOnReplication(
+ boolean notifyListenersCreateSessionOnReplication) {
this.notifySessionListenersOnReplication = notifyListenersCreateSessionOnReplication;
}
@@ -433,7 +435,8 @@ public class DeltaManager extends ClusterManagerBase{
* Create new session with check maxActiveSessions and send session creation
* to other cluster nodes.
*
- * @param distribute
+ * @param sessionId The session id that should be used for the session
+ * @param distribute <code>true</code> to replicate the new session
* @return The session
*/
public Session createSession(String sessionId, boolean distribute) {
@@ -444,13 +447,13 @@ public class DeltaManager extends ClusterManagerBase{
if (log.isDebugEnabled())
log.debug(sm.getString("deltaManager.createSession.newSession",
session.getId(), Integer.valueOf(sessions.size())));
- return (session);
+ return session;
}
/**
- * Send create session evt to all backup node
- * @param sessionId
- * @param session
+ * Send create session event to all backup node
+ * @param sessionId The session id of the session
+ * @param session The session object
*/
protected void sendCreateSession(String sessionId, DeltaSession session) {
if(cluster.getMembers().length > 0 ) {
@@ -460,7 +463,9 @@ public class DeltaManager extends ClusterManagerBase{
null,
sessionId,
sessionId + "-" + System.currentTimeMillis());
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.sendMessage.newSession",name, sessionId));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.sendMessage.newSession", name, sessionId));
+ }
msg.setTimestamp(session.getCreationTime());
counterSend_EVT_SESSION_CREATED++;
send(msg);
@@ -531,6 +536,8 @@ public class DeltaManager extends ClusterManagerBase{
/**
* serialize sessionID
+ * @param sessionId Session id to serialize
+ * @return byte array with serialized session id
* @throws IOException if an input/output error occurs
*/
protected byte[] serializeSessionId(String sessionId) throws IOException {
@@ -544,6 +551,8 @@ public class DeltaManager extends ClusterManagerBase{
/**
* Load sessionID
+ * @param data serialized session id
+ * @return session id
* @throws IOException if an input/output error occurs
*/
protected String deserializeSessionId(byte[] data) throws IOException {
@@ -557,7 +566,7 @@ public class DeltaManager extends ClusterManagerBase{
* Load Deltarequest from external node
* Load the Class at container classloader
* @see DeltaRequest#readExternal(java.io.ObjectInput)
- * @param session
+ * @param session Corresponding session
* @param data message data
* @return The request
* @throws ClassNotFoundException Serialization error
@@ -585,7 +594,8 @@ public class DeltaManager extends ClusterManagerBase{
* serialize DeltaRequest
* @see DeltaRequest#writeExternal(java.io.ObjectOutput)
*
- * @param deltaRequest
+ * @param session Associated session
+ * @param deltaRequest The request to serialize
* @return serialized delta request
* @throws IOException IO error with serialization
*
@@ -608,6 +618,7 @@ public class DeltaManager extends ClusterManagerBase{
* Load sessions from other cluster node.
* FIXME replace currently sessions with same id without notification.
* FIXME SSO handling is not really correct with the session replacement!
+ * @param data Serialized data
* @exception ClassNotFoundException
* if a serialized class cannot be found during the reload
* @exception IOException
@@ -615,10 +626,7 @@ public class DeltaManager extends ClusterManagerBase{
*/
protected void deserializeSessions(byte[] data) throws ClassNotFoundException,IOException {
- // Initialize our internal data structures
- //sessions.clear(); //should not do this
// Open an input stream to the specified pathname, if any
- ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
ObjectInputStream ois = null;
// Load the previously unloaded active sessions
try {
@@ -647,7 +655,10 @@ public class DeltaManager extends ClusterManagerBase{
} else {
sessionReplaceCounter++;
// FIXME better is to grap this sessions again !
- if (log.isWarnEnabled()) log.warn(sm.getString("deltaManager.loading.existing.session",session.getIdInternal()));
+ if (log.isWarnEnabled()) {
+ log.warn(sm.getString("deltaManager.loading.existing.session",
+ session.getIdInternal()));
+ }
}
add(session);
if (notifySessionListenersOnReplication) {
@@ -667,10 +678,7 @@ public class DeltaManager extends ClusterManagerBase{
} catch (IOException f) {
// ignored
}
- ois = null;
- if (originalLoader != null) Thread.currentThread().setContextClassLoader(originalLoader);
}
-
}
@@ -679,6 +687,8 @@ public class DeltaManager extends ClusterManagerBase{
* mechanism, if any. If persistence is not supported, this method returns
* without doing anything.
*
+ * @param currentSessions Sessions to serialize
+ * @return serialized data
* @exception IOException
* if an input/output error occurs
*/
@@ -710,6 +720,7 @@ public class DeltaManager extends ClusterManagerBase{
oos = null;
}
}
+
// send object data as byte[]
return fos.toByteArray();
}
@@ -739,10 +750,13 @@ public class DeltaManager extends ClusterManagerBase{
} else if( cluster.getContainer() instanceof Engine){
type = "Engine" ;
}
- log.info(sm.getString("deltaManager.registerCluster", getName(), type, cluster.getClusterName()));
+ log.info(sm.getString("deltaManager.registerCluster",
+ getName(), type, cluster.getClusterName()));
}
}
- if (log.isInfoEnabled()) log.info(sm.getString("deltaManager.startClustering", getName()));
+ if (log.isInfoEnabled()) {
+ log.info(sm.getString("deltaManager.startClustering", getName()));
+ }
getAllClusterSessions();
@@ -765,7 +779,8 @@ public class DeltaManager extends ClusterManagerBase{
if(mbr == null) { // No domain member found
return;
}
- SessionMessage msg = new SessionMessageImpl(this.getName(),SessionMessage.EVT_GET_ALL_SESSIONS, null, "GET-ALL","GET-ALL-" + getName());
+ SessionMessage msg = new SessionMessageImpl(this.getName(),
+ SessionMessage.EVT_GET_ALL_SESSIONS, null, "GET-ALL", "GET-ALL-" + getName());
msg.setTimestamp(beforeSendTime);
// set reference time
stateTransferCreateSendTime = beforeSendTime ;
@@ -779,22 +794,28 @@ public class DeltaManager extends ClusterManagerBase{
}
cluster.send(msg, mbr);
if (log.isInfoEnabled())
- log.info(sm.getString("deltaManager.waitForSessionState",getName(), mbr, Integer.valueOf(getStateTransferTimeout())));
- // FIXME At sender ack mode this method check only the state transfer and resend is a problem!
+ log.info(sm.getString("deltaManager.waitForSessionState",
+ getName(), mbr, Integer.valueOf(getStateTransferTimeout())));
+ // FIXME At sender ack mode this method check only the state
+ // transfer and resend is a problem!
waitForSendAllSessions(beforeSendTime);
} finally {
synchronized(receivedMessageQueue) {
- for (Iterator<SessionMessage> iter = receivedMessageQueue.iterator(); iter.hasNext();) {
- SessionMessage smsg = iter.next();
+ for (SessionMessage smsg : receivedMessageQueue) {
if (!stateTimestampDrop) {
messageReceived(smsg, smsg.getAddress() != null ? (Member) smsg.getAddress() : null);
} else {
- if (smsg.getEventType() != SessionMessage.EVT_GET_ALL_SESSIONS && smsg.getTimestamp() >= stateTransferCreateSendTime) {
+ if (smsg.getEventType() != SessionMessage.EVT_GET_ALL_SESSIONS &&
+ smsg.getTimestamp() >= stateTransferCreateSendTime) {
// FIXME handle EVT_GET_ALL_SESSIONS later
- messageReceived(smsg,smsg.getAddress() != null ? (Member) smsg.getAddress() : null);
+ messageReceived(smsg, smsg.getAddress() != null ? (Member) smsg.getAddress() : null);
} else {
if (log.isWarnEnabled()) {
- log.warn(sm.getString("deltaManager.dropMessage",getName(), smsg.getEventTypeString(),new Date(stateTransferCreateSendTime), new Date(smsg.getTimestamp())));
+ log.warn(sm.getString("deltaManager.dropMessage",
+ getName(),
+ smsg.getEventTypeString(),
+ new Date(stateTransferCreateSendTime),
+ new Date(smsg.getTimestamp())));
}
}
}
@@ -816,14 +837,19 @@ public class DeltaManager extends ClusterManagerBase{
Member mbr = null;
Member mbrs[] = cluster.getMembers();
if(mbrs.length != 0 ) mbr = mbrs[0];
- if(mbr == null && log.isWarnEnabled()) log.warn(sm.getString("deltaManager.noMasterMember",getName(), ""));
- if(mbr != null && log.isDebugEnabled()) log.warn(sm.getString("deltaManager.foundMasterMember",getName(), mbr));
+ if(mbr == null && log.isWarnEnabled()) {
+ log.warn(sm.getString("deltaManager.noMasterMember",getName(), ""));
+ }
+ if(mbr != null && log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.foundMasterMember",getName(), mbr));
+ }
return mbr;
}
/**
* Wait that cluster session state is transferred or timeout after 60 Sec
* With stateTransferTimeout == -1 wait that backup is transferred (forever mode)
+ * @param beforeSendTime Start instant of the operation
*/
protected void waitForSendAllSessions(long beforeSendTime) {
long reqStart = System.currentTimeMillis();
@@ -854,13 +880,16 @@ public class DeltaManager extends ClusterManagerBase{
}
if (isTimeout) {
counterNoStateTransfered++ ;
- log.error(sm.getString("deltaManager.noSessionState",getName(),new Date(beforeSendTime),Long.valueOf(reqNow - beforeSendTime)));
+ log.error(sm.getString("deltaManager.noSessionState", getName(),
+ new Date(beforeSendTime), Long.valueOf(reqNow - beforeSendTime)));
}else if (isNoContextManagerReceived()) {
if (log.isWarnEnabled())
- log.warn(sm.getString("deltaManager.noContextManager",getName(),new Date(beforeSendTime),Long.valueOf(reqNow - beforeSendTime)));
+ log.warn(sm.getString("deltaManager.noContextManager", getName(),
+ new Date(beforeSendTime), Long.valueOf(reqNow - beforeSendTime)));
} else {
if (log.isInfoEnabled())
- log.info(sm.getString("deltaManager.sessionReceived",getName(), new Date(beforeSendTime), Long.valueOf(reqNow - beforeSendTime)));
+ log.info(sm.getString("deltaManager.sessionReceived", getName(),
+ new Date(beforeSendTime), Long.valueOf(reqNow - beforeSendTime)));
}
}
@@ -909,7 +938,7 @@ public class DeltaManager extends ClusterManagerBase{
*/
@Override
public void messageDataReceived(ClusterMessage cmsg) {
- if (cmsg != null && cmsg instanceof SessionMessage) {
+ if (cmsg instanceof SessionMessage) {
SessionMessage msg = (SessionMessage) cmsg;
switch (msg.getEventType()) {
case SessionMessage.EVT_GET_ALL_SESSIONS:
@@ -917,7 +946,7 @@ public class DeltaManager extends ClusterManagerBase{
case SessionMessage.EVT_SESSION_EXPIRED:
case SessionMessage.EVT_SESSION_ACCESSED:
case SessionMessage.EVT_SESSION_DELTA:
- case SessionMessage.EVT_CHANGE_SESSION_ID: {
+ case SessionMessage.EVT_CHANGE_SESSION_ID:
synchronized(receivedMessageQueue) {
if(receiverQueue) {
receivedMessageQueue.add(msg);
@@ -925,11 +954,9 @@ public class DeltaManager extends ClusterManagerBase{
}
}
break;
- }
- default: {
+ default:
//we didn't queue, do nothing
break;
- }
} //switch
messageReceived(msg, msg.getAddress() != null ? (Member) msg.getAddress() : null);
@@ -986,7 +1013,8 @@ public class DeltaManager extends ClusterManagerBase{
sessionId + "-" + System.currentTimeMillis());
}
} catch (IOException x) {
- log.error(sm.getString("deltaManager.createMessage.unableCreateDeltaRequest",sessionId), x);
+ log.error(sm.getString("deltaManager.createMessage.unableCreateDeltaRequest",
+ sessionId), x);
return null;
}
if(msg == null) {
@@ -998,12 +1026,13 @@ public class DeltaManager extends ClusterManagerBase{
sessionId,
sessionId + "-" + System.currentTimeMillis());
if (log.isDebugEnabled()) {
- log.debug(sm.getString("deltaManager.createMessage.accessChangePrimary",getName(), sessionId));
+ log.debug(sm.getString("deltaManager.createMessage.accessChangePrimary",
+ getName(), sessionId));
}
}
} else { // log only outside synch block!
if (log.isDebugEnabled()) {
- log.debug(sm.getString("deltaManager.createMessage.delta",getName(), sessionId));
+ log.debug(sm.getString("deltaManager.createMessage.delta", getName(), sessionId));
}
}
if (!expires) session.setPrimarySession(true);
@@ -1019,7 +1048,8 @@ public class DeltaManager extends ClusterManagerBase{
sessionId,
sessionId + "-" + System.currentTimeMillis());
if (log.isDebugEnabled()) {
- log.debug(sm.getString("deltaManager.createMessage.access", getName(),sessionId));
+ log.debug(sm.getString("deltaManager.createMessage.access",
+ getName(), sessionId));
}
}
}
@@ -1089,7 +1119,9 @@ public class DeltaManager extends ClusterManagerBase{
SessionMessage msg = new SessionMessageImpl(getName(),
SessionMessage.EVT_SESSION_EXPIRED, null, id, id+ "-EXPIRED-MSG");
msg.setTimestamp(System.currentTimeMillis());
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.createMessage.expire",getName(), id));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.createMessage.expire", getName(), id));
+ }
send(msg);
}
}
@@ -1104,7 +1136,10 @@ public class DeltaManager extends ClusterManagerBase{
int expireDirect = 0 ;
int expireIndirect = 0 ;
- if(log.isDebugEnabled()) log.debug("Start expire all sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
+ if (log.isDebugEnabled()) {
+ log.debug("Start expire all sessions " + getName() + " at " + timeNow +
+ " sessioncount " + sessions.length);
+ }
for (int i = 0; i < sessions.length; i++) {
if (sessions[i] instanceof DeltaSession) {
DeltaSession session = (DeltaSession) sessions[i];
@@ -1119,8 +1154,12 @@ public class DeltaManager extends ClusterManagerBase{
}//end if
}//for
long timeEnd = System.currentTimeMillis();
- if(log.isDebugEnabled()) log.debug("End expire sessions " + getName() + " expire processingTime " + (timeEnd - timeNow) + " expired direct sessions: " + expireDirect + " expired direct sessions: " + expireIndirect);
-
+ if (log.isDebugEnabled()) {
+ log.debug("End expire sessions " + getName() +
+ " expire processingTime " + (timeEnd - timeNow) +
+ " expired direct sessions: " + expireDirect +
+ " expired direct sessions: " + expireIndirect);
+ }
}
@Override
@@ -1147,49 +1186,42 @@ public class DeltaManager extends ClusterManagerBase{
ClassLoader[] loaders = getClassLoaders();
Thread.currentThread().setContextClassLoader(loaders[0]);
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.eventType",getName(), msg.getEventTypeString(), sender));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.eventType",
+ getName(), msg.getEventTypeString(), sender));
+ }
switch (msg.getEventType()) {
- case SessionMessage.EVT_GET_ALL_SESSIONS: {
+ case SessionMessage.EVT_GET_ALL_SESSIONS:
handleGET_ALL_SESSIONS(msg,sender);
break;
- }
- case SessionMessage.EVT_ALL_SESSION_DATA: {
+ case SessionMessage.EVT_ALL_SESSION_DATA:
handleALL_SESSION_DATA(msg,sender);
break;
- }
- case SessionMessage.EVT_ALL_SESSION_TRANSFERCOMPLETE: {
+ case SessionMessage.EVT_ALL_SESSION_TRANSFERCOMPLETE:
handleALL_SESSION_TRANSFERCOMPLETE(msg,sender);
break;
- }
- case SessionMessage.EVT_SESSION_CREATED: {
+ case SessionMessage.EVT_SESSION_CREATED:
handleSESSION_CREATED(msg,sender);
break;
- }
- case SessionMessage.EVT_SESSION_EXPIRED: {
+ case SessionMessage.EVT_SESSION_EXPIRED:
handleSESSION_EXPIRED(msg,sender);
break;
- }
- case SessionMessage.EVT_SESSION_ACCESSED: {
+ case SessionMessage.EVT_SESSION_ACCESSED:
handleSESSION_ACCESSED(msg,sender);
break;
- }
- case SessionMessage.EVT_SESSION_DELTA: {
+ case SessionMessage.EVT_SESSION_DELTA:
handleSESSION_DELTA(msg,sender);
break;
- }
- case SessionMessage.EVT_CHANGE_SESSION_ID: {
+ case SessionMessage.EVT_CHANGE_SESSION_ID:
handleCHANGE_SESSION_ID(msg,sender);
break;
- }
- case SessionMessage.EVT_ALL_SESSION_NOCONTEXTMANAGER: {
+ case SessionMessage.EVT_ALL_SESSION_NOCONTEXTMANAGER:
handleALL_SESSION_NOCONTEXTMANAGER(msg,sender);
break;
- }
- default: {
+ default:
//we didn't recognize the message type, do nothing
break;
- }
} //switch
} catch (Exception x) {
log.error(sm.getString("deltaManager.receiveMessage.error",getName()), x);
@@ -1203,24 +1235,28 @@ public class DeltaManager extends ClusterManagerBase{
/**
* handle receive session state is complete transferred
- * @param msg
- * @param sender
+ * @param msg Session message
+ * @param sender Member which sent the message
*/
protected void handleALL_SESSION_TRANSFERCOMPLETE(SessionMessage msg, Member sender) {
counterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE++ ;
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.transfercomplete",getName(), sender.getHost(), Integer.valueOf(sender.getPort())));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.transfercomplete",
+ getName(), sender.getHost(), Integer.valueOf(sender.getPort())));
+ }
stateTransferCreateSendTime = msg.getTimestamp() ;
stateTransfered = true ;
}
/**
* handle receive session delta
- * @param msg
- * @param sender
- * @throws IOException
- * @throws ClassNotFoundException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws IOException IO error with serialization
+ * @throws ClassNotFoundException Serialization error
*/
- protected void handleSESSION_DELTA(SessionMessage msg, Member sender) throws IOException, ClassNotFoundException {
+ protected void handleSESSION_DELTA(SessionMessage msg, Member sender)
+ throws IOException, ClassNotFoundException {
counterReceive_EVT_SESSION_DELTA++;
byte[] delta = msg.getSession();
DeltaSession session = (DeltaSession) findSession(msg.getSessionID());
@@ -1241,15 +1277,18 @@ public class DeltaManager extends ClusterManagerBase{
/**
* handle receive session is access at other node ( primary session is now false)
- * @param msg
- * @param sender
- * @throws IOException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws IOException Propagated IO error
*/
protected void handleSESSION_ACCESSED(SessionMessage msg,Member sender) throws IOException {
counterReceive_EVT_SESSION_ACCESSED++;
DeltaSession session = (DeltaSession) findSession(msg.getSessionID());
if (session != null) {
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.accessed",getName(), msg.getSessionID()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.accessed",
+ getName(), msg.getSessionID()));
+ }
session.access();
session.setPrimarySession(false);
session.endAccess();
@@ -1258,32 +1297,39 @@ public class DeltaManager extends ClusterManagerBase{
/**
* handle receive session is expire at other node ( expire session also here)
- * @param msg
- * @param sender
- * @throws IOException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws IOException Propagated IO error
*/
protected void handleSESSION_EXPIRED(SessionMessage msg,Member sender) throws IOException {
counterReceive_EVT_SESSION_EXPIRED++;
DeltaSession session = (DeltaSession) findSession(msg.getSessionID());
if (session != null) {
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.expired",getName(), msg.getSessionID()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.expired",
+ getName(), msg.getSessionID()));
+ }
session.expire(notifySessionListenersOnReplication, false);
}
}
/**
* handle receive new session is created at other node (create backup - primary false)
- * @param msg
- * @param sender
+ * @param msg Session message
+ * @param sender Member which sent the message
*/
protected void handleSESSION_CREATED(SessionMessage msg,Member sender) {
counterReceive_EVT_SESSION_CREATED++;
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.createNewSession",getName(), msg.getSessionID()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.createNewSession",
+ getName(), msg.getSessionID()));
+ }
DeltaSession session = (DeltaSession) createEmptySession();
session.setValid(true);
session.setPrimarySession(false);
session.setCreationTime(msg.getTimestamp());
- // use container maxInactiveInterval so that session will expire correctly in case of primary transfer
+ // use container maxInactiveInterval so that session will expire correctly
+ // in case of primary transfer
session.setMaxInactiveInterval(((Context) getContainer()).getSessionTimeout() * 60, false);
session.access();
session.setId(msg.getSessionID(), notifySessionListenersOnReplication);
@@ -1293,17 +1339,22 @@ public class DeltaManager extends ClusterManagerBase{
/**
* handle receive sessions from other not ( restart )
- * @param msg
- * @param sender
- * @throws ClassNotFoundException
- * @throws IOException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws ClassNotFoundException Serialization error
+ * @throws IOException IO error with serialization
*/
- protected void handleALL_SESSION_DATA(SessionMessage msg,Member sender) throws ClassNotFoundException, IOException {
+ protected void handleALL_SESSION_DATA(SessionMessage msg,Member sender)
+ throws ClassNotFoundException, IOException {
counterReceive_EVT_ALL_SESSION_DATA++;
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.allSessionDataBegin",getName()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.allSessionDataBegin", getName()));
+ }
byte[] data = msg.getSession();
deserializeSessions(data);
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.allSessionDataAfter",getName()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.allSessionDataAfter", getName()));
+ }
//stateTransferred = true;
}
@@ -1312,14 +1363,16 @@ public class DeltaManager extends ClusterManagerBase{
* a) send all sessions with one message
* b) send session at blocks
* After sending send state is complete transferred
- * @param msg
- * @param sender
- * @throws IOException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws IOException IO error sending messages
*/
protected void handleGET_ALL_SESSIONS(SessionMessage msg, Member sender) throws IOException {
counterReceive_EVT_GET_ALL_SESSIONS++;
//get a list of all the session from this manager
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.unloadingBegin", getName()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.unloadingBegin", getName()));
+ }
// Write the number of active sessions, followed by the details
// get all sessions and serialize without sync
Session[] currentSessions = findSessions();
@@ -1330,7 +1383,9 @@ public class DeltaManager extends ClusterManagerBase{
// send session at blocks
int remain = currentSessions.length;
for (int i = 0; i < currentSessions.length; i += getSendAllSessionsSize()) {
- int len = i + getSendAllSessionsSize() > currentSessions.length ? currentSessions.length - i : getSendAllSessionsSize();
+ int len = i + getSendAllSessionsSize() > currentSessions.length ?
+ currentSessions.length - i :
+ getSendAllSessionsSize();
Session[] sendSessions = new Session[len];
System.arraycopy(currentSessions, i, sendSessions, 0, len);
sendSessions(sender, sendSessions,findSessionTimestamp);
@@ -1348,16 +1403,18 @@ public class DeltaManager extends ClusterManagerBase{
SessionMessage.EVT_ALL_SESSION_TRANSFERCOMPLETE, null, "SESSION-STATE-TRANSFERRED",
"SESSION-STATE-TRANSFERRED" + getName());
newmsg.setTimestamp(findSessionTimestamp);
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.createMessage.allSessionTransfered",getName()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.createMessage.allSessionTransfered",getName()));
+ }
counterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE++;
cluster.send(newmsg, sender);
}
/**
* handle receive change sessionID at other node
- * @param msg
- * @param sender
- * @throws IOException
+ * @param msg Session message
+ * @param sender Member which sent the message
+ * @throws IOException IO error with serialization
*/
protected void handleCHANGE_SESSION_ID(SessionMessage msg,Member sender) throws IOException {
counterReceive_EVT_CHANGE_SESSION_ID++;
@@ -1375,29 +1432,36 @@ public class DeltaManager extends ClusterManagerBase{
/**
* handle receive no context manager.
- * @param msg
- * @param sender
+ * @param msg Session message
+ * @param sender Member which sent the message
*/
protected void handleALL_SESSION_NOCONTEXTMANAGER(SessionMessage msg, Member sender) {
counterReceive_EVT_ALL_SESSION_NOCONTEXTMANAGER++ ;
if (log.isDebugEnabled())
- log.debug(sm.getString("deltaManager.receiveMessage.noContextManager",getName(), sender.getHost(), Integer.valueOf(sender.getPort())));
+ log.debug(sm.getString("deltaManager.receiveMessage.noContextManager",
+ getName(), sender.getHost(), Integer.valueOf(sender.getPort())));
noContextManagerReceived = true ;
}
/**
* send a block of session to sender
- * @param sender
- * @param currentSessions
- * @param sendTimestamp
- * @throws IOException
+ * @param sender Sender member
+ * @param currentSessions Sessions to send
+ * @param sendTimestamp Timestamp
+ * @throws IOException IO error sending messages
*/
- protected void sendSessions(Member sender, Session[] currentSessions,long sendTimestamp) throws IOException {
+ protected void sendSessions(Member sender, Session[] currentSessions,long sendTimestamp)
+ throws IOException {
byte[] data = serializeSessions(currentSessions);
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.unloadingAfter",getName()));
- SessionMessage newmsg = new SessionMessageImpl(name,SessionMessage.EVT_ALL_SESSION_DATA, data,"SESSION-STATE", "SESSION-STATE-" + getName());
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.receiveMessage.unloadingAfter", getName()));
+ }
+ SessionMessage newmsg = new SessionMessageImpl(name, SessionMessage.EVT_ALL_SESSION_DATA,
+ data, "SESSION-STATE", "SESSION-STATE-" + getName());
newmsg.setTimestamp(sendTimestamp);
- if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.createMessage.allSessionData",getName()));
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("deltaManager.createMessage.allSessionData", getName()));
+ }
counterSend_EVT_ALL_SESSION_DATA++;
cluster.send(newmsg, sender);
}
diff --git a/java/org/apache/catalina/ha/session/DeltaRequest.java b/java/org/apache/catalina/ha/session/DeltaRequest.java
index 03fa42d..d16dbb2 100644
--- a/java/org/apache/catalina/ha/session/DeltaRequest.java
+++ b/java/org/apache/catalina/ha/session/DeltaRequest.java
@@ -5,22 +5,20 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina.ha.session;
/**
* This class is used to track the series of actions that happens when
- * a request is executed. These actions will then translate into invocations of methods
+ * a request is executed. These actions will then translate into invocations of methods
* on the actual session.
* This class is NOT thread safe. One DeltaRequest per session
* @author <a href="mailto:fhanik@apache.org">Filip Hanik</a>
@@ -36,19 +34,19 @@ import java.util.LinkedList;
import org.apache.catalina.SessionListener;
import org.apache.catalina.realm.GenericPrincipal;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.res.StringManager;
public class DeltaRequest implements Externalizable {
- public static final org.apache.juli.logging.Log log =
- org.apache.juli.logging.LogFactory.getLog( DeltaRequest.class );
+ public static final Log log = LogFactory.getLog(DeltaRequest.class);
/**
* The string manager for this package.
*/
- protected static final StringManager sm = StringManager
- .getManager(Constants.Package);
+ protected static final StringManager sm = StringManager.getManager(DeltaRequest.class);
public static final int TYPE_ATTRIBUTE = 0;
public static final int TYPE_PRINCIPAL = 1;
@@ -68,15 +66,14 @@ public class DeltaRequest implements Externalizable {
private String sessionId;
private LinkedList<AttributeInfo> actions = new LinkedList<AttributeInfo>();
- private LinkedList<AttributeInfo> actionPool =
- new LinkedList<AttributeInfo>();
-
+ private LinkedList<AttributeInfo> actionPool = new LinkedList<AttributeInfo>();
+
private boolean recordAllActions = false;
public DeltaRequest() {
-
+
}
-
+
public DeltaRequest(String sessionId, boolean recordAllActions) {
this.recordAllActions=recordAllActions;
if(sessionId != null)
@@ -90,15 +87,13 @@ public class DeltaRequest implements Externalizable {
}
public void removeAttribute(String name) {
- int action = ACTION_REMOVE;
- addAction(TYPE_ATTRIBUTE,action,name,null);
+ addAction(TYPE_ATTRIBUTE, ACTION_REMOVE, name, null);
}
public void setMaxInactiveInterval(int interval) {
- int action = ACTION_SET;
- addAction(TYPE_MAXINTERVAL,action,NAME_MAXINTERVAL,Integer.valueOf(interval));
+ addAction(TYPE_MAXINTERVAL, ACTION_SET, NAME_MAXINTERVAL, Integer.valueOf(interval));
}
-
+
/**
* convert principal at SerializablePrincipal for backup nodes.
* Only support principals from type {@link GenericPrincipal GenericPrincipal}
@@ -165,7 +160,7 @@ public class DeltaRequest implements Externalizable {
//add the action
actions.addLast(info);
}
-
+
public void execute(DeltaSession session, boolean notifyListeners) {
if ( !this.sessionId.equals( session.getId() ) )
throw new java.lang.IllegalArgumentException("Session id mismatch, not executing the delta request");
@@ -181,10 +176,10 @@ public class DeltaRequest implements Externalizable {
if ( log.isTraceEnabled() ) log.trace("Session.removeAttribute('"+info.getName()+"')");
session.removeAttribute(info.getName(),notifyListeners,false);
}
-
+
break;
case TYPE_ISNEW:
- if ( log.isTraceEnabled() ) log.trace("Session.setNew('"+info.getValue()+"')");
+ if ( log.isTraceEnabled() ) log.trace("Session.setNew('"+info.getValue()+"')");
session.setNew(((Boolean)info.getValue()).booleanValue(),false);
break;
case TYPE_MAXINTERVAL:
@@ -234,7 +229,7 @@ public class DeltaRequest implements Externalizable {
}
actions.clear();
}
-
+
public String getSessionId() {
return sessionId;
}
@@ -247,12 +242,12 @@ public class DeltaRequest implements Externalizable {
public int getSize() {
return actions.size();
}
-
+
public void clear() {
actions.clear();
actionPool.clear();
}
-
+
@Override
public void readExternal(java.io.ObjectInput in) throws IOException,ClassNotFoundException {
//sessionId - String
@@ -300,13 +295,13 @@ public class DeltaRequest implements Externalizable {
info.writeExternal(out);
}
}
-
+
/**
* serialize DeltaRequest
* @see DeltaRequest#writeExternal(java.io.ObjectOutput)
- *
+ *
* @return serialized delta request
- * @throws IOException
+ * @throws IOException IO error serializing
*/
protected byte[] serialize() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -316,7 +311,7 @@ public class DeltaRequest implements Externalizable {
oos.close();
return bos.toByteArray();
}
-
+
private static class AttributeInfo implements java.io.Externalizable {
private String name = null;
private Object value = null;
@@ -364,7 +359,7 @@ public class DeltaRequest implements Externalizable {
public String getName() {
return name;
}
-
+
public void recycle() {
name = null;
value = null;
@@ -378,7 +373,7 @@ public class DeltaRequest implements Externalizable {
AttributeInfo other = (AttributeInfo)o;
return other.getName().equals(this.getName());
}
-
+
@Override
public void readExternal(java.io.ObjectInput in ) throws IOException,ClassNotFoundException {
//type - int
@@ -406,7 +401,7 @@ public class DeltaRequest implements Externalizable {
out.writeBoolean(getValue()!=null);
if (getValue()!=null) out.writeObject(getValue());
}
-
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder("AttributeInfo[type=");
diff --git a/java/org/apache/catalina/ha/session/DeltaSession.java b/java/org/apache/catalina/ha/session/DeltaSession.java
index 4cf78b3..f7c621e 100644
--- a/java/org/apache/catalina/ha/session/DeltaSession.java
+++ b/java/org/apache/catalina/ha/session/DeltaSession.java
@@ -27,6 +27,7 @@ import java.io.WriteAbortedException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
@@ -44,6 +45,8 @@ import org.apache.catalina.session.StandardManager;
import org.apache.catalina.session.StandardSession;
import org.apache.catalina.tribes.io.ReplicationStream;
import org.apache.catalina.tribes.tipis.ReplicatedMapEntry;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.collections.SynchronizedStack;
import org.apache.tomcat.util.res.StringManager;
@@ -56,12 +59,12 @@ import org.apache.tomcat.util.res.StringManager;
*/
public class DeltaSession extends StandardSession implements Externalizable,ClusterSession,ReplicatedMapEntry {
- public static final org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(DeltaSession.class);
+ public static final Log log = LogFactory.getLog(DeltaSession.class);
/**
* The string manager for this package.
*/
- protected static final StringManager sm = StringManager.getManager(Constants.Package);
+ protected static final StringManager sm = StringManager.getManager(DeltaSession.class);
// ----------------------------------------------------- Instance Variables
@@ -133,8 +136,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
/**
* Returns a diff and sets the dirty map to false
- * @return byte[]
- * @throws IOException
+ * @return a serialized view of the difference
+ * @throws IOException IO error serializing
*/
@Override
public byte[] getDiff() throws IOException {
@@ -180,10 +183,10 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
/**
* Applies a diff to an existing object.
- * @param diff byte[]
- * @param offset int
- * @param length int
- * @throws IOException
+ * @param diff Serialized diff data
+ * @param offset Array offset
+ * @param length Array length
+ * @throws IOException IO error deserializing
*/
@Override
public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException {
@@ -459,7 +462,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
}
}
}
- return (this.isValid);
+
+ return this.isValid;
}
/**
@@ -556,7 +560,7 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
sb.append("DeltaSession[");
sb.append(id);
sb.append("]");
- return (sb.toString());
+ return sb.toString();
}
@Override
@@ -932,8 +936,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
// Accumulate the names of serializable and non-serializable attributes
String keys[] = keys();
- ArrayList<String> saveNames = new ArrayList<String>();
- ArrayList<Object> saveValues = new ArrayList<Object>();
+ List<String> saveNames = new ArrayList<String>();
+ List<Object> saveValues = new ArrayList<Object>();
for (int i = 0; i < keys.length; i++) {
Object value = null;
value = attributes.get(keys[i]);
diff --git a/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java b/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
index c2772ff..93f81df 100644
--- a/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
+++ b/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,6 +35,8 @@ import org.apache.catalina.ha.ClusterValve;
import org.apache.catalina.session.ManagerBase;
import org.apache.catalina.session.PersistentManager;
import org.apache.catalina.valves.ValveBase;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.res.StringManager;
/**
@@ -61,27 +63,26 @@ import org.apache.tomcat.util.res.StringManager;
*
* <p>
* Add this Valve to your cluster definition at conf/server.xml .
- *
+ *
* <pre>
* <Cluster>
- * <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
+ * <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
* </Cluster>
* </pre>
- *
- * <em>A Trick:</em><br/>
+ *
+ * <em>A Trick:</em><br>
* You can enable this mod_jk turnover mode via JMX before you drop a node to
* all backup nodes! Set enable true on all JvmRouteBinderValve backups, disable
* worker at mod_jk and then drop node and restart it! Then enable mod_jk worker
* and disable JvmRouteBinderValves again. This use case means that only
* requested sessions are migrated.
- *
+ *
* @author Peter Rossbach
*/
public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/*--Static Variables----------------------------------------*/
- public static final org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory
- .getLog(JvmRouteBinderValve.class);
+ public static final Log log = LogFactory.getLog(JvmRouteBinderValve.class);
/**
* The descriptive information about this implementation.
@@ -103,7 +104,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* The string manager for this package.
*/
- protected static final StringManager sm = StringManager.getManager(Constants.Package);
+ protected static final StringManager sm = StringManager.getManager(JvmRouteBinderValve.class);
/**
* enabled this component
@@ -132,7 +133,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* set session id attribute to failed node for request.
- *
+ *
* @return Returns the sessionIdAttribute.
*/
public String getSessionIdAttribute() {
@@ -141,7 +142,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* get name of failed request session attribute
- *
+ *
* @param sessionIdAttribute
* The sessionIdAttribute to set.
*/
@@ -173,7 +174,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* Detect possible the JVMRoute change at cluster backup node..
- *
+ *
* @param request
* tomcat request being processed
* @param response
@@ -191,7 +192,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
request.getContext() != null &&
request.getContext().getDistributable() &&
!request.isAsyncDispatching()) {
- // valve cluster can access manager - other cluster handle turnover
+ // valve cluster can access manager - other cluster handle turnover
// at host level - hopefully!
Manager manager = request.getContext().getManager();
@@ -200,8 +201,9 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
&& getCluster() != null
&& getCluster().getManager(((ClusterManager)manager).getName()) != null)
||
- (manager instanceof PersistentManager)))
- handlePossibleTurnover(request);
+ (manager instanceof PersistentManager))) {
+ handlePossibleTurnover(request);
+ }
}
// Pass this request on to the next valve in our pipeline
getNext().invoke(request, response);
@@ -209,7 +211,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* handle possible session turn over.
- *
+ *
* @see JvmRouteBinderValve#handleJvmRoute(Request, String, String)
* @param request current request
*/
@@ -219,8 +221,9 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
long t1 = System.currentTimeMillis();
String jvmRoute = getLocalJvmRoute(request);
if (jvmRoute == null) {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.missingJvmRouteAttribute"));
+ }
return;
}
handleJvmRoute( request, sessionID, jvmRoute);
@@ -234,30 +237,32 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* get jvmroute from engine
- *
+ *
* @param request current request
* @return return jvmRoute from ManagerBase or null
*/
protected String getLocalJvmRoute(Request request) {
Manager manager = getManager(request);
- if(manager instanceof ManagerBase)
+ if(manager instanceof ManagerBase) {
return ((ManagerBase) manager).getJvmRoute();
+ }
return null ;
}
/**
* get ClusterManager
- *
+ *
* @param request current request
* @return manager or null
*/
protected Manager getManager(Request request) {
Manager manager = request.getContext().getManager();
if (log.isDebugEnabled()) {
- if(manager != null)
+ if(manager != null) {
log.debug(sm.getString("jvmRoute.foundManager", manager, request.getContext().getName()));
- else
+ } else {
log.debug(sm.getString("jvmRoute.notFoundManager", request.getContext().getName()));
+ }
}
return manager;
}
@@ -269,7 +274,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
public CatalinaCluster getCluster() {
return cluster;
}
-
+
/**
* @param cluster The cluster to set.
*/
@@ -277,12 +282,12 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
public void setCluster(CatalinaCluster cluster) {
this.cluster = cluster;
}
-
+
/**
* Handle jvmRoute stickiness after tomcat instance failed. After this
* correction a new Cookie send to client with new jvmRoute and the
* SessionID change propagate to the other cluster nodes.
- *
+ *
* @param request current request
* @param sessionId
* request SessionID from Cookie
@@ -336,7 +341,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
/**
* change session id and send to all cluster nodes
- *
+ *
* @param request current request
* @param sessionId
* original session id
@@ -362,7 +367,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
if (log.isDebugEnabled()) {
log.debug(sm.getString("jvmRoute.changeSession", sessionId,
newSessionID));
- }
+ }
}
/**
@@ -419,7 +424,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
-
+
if (cluster == null) {
Container hostContainer = getContainer();
// compatibility with JvmRouteBinderValve version 1.1
@@ -440,17 +445,18 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
}
}
}
-
+
if (log.isInfoEnabled()) {
log.info(sm.getString("jvmRoute.valve.started"));
- if (cluster == null)
+ if (cluster == null) {
log.info(sm.getString("jvmRoute.noCluster"));
+ }
}
super.startInternal();
}
-
+
/**
* Stop this component and implement the requirements
* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
@@ -465,8 +471,9 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve {
cluster = null;
numberOfSessions = 0;
- if (log.isInfoEnabled())
+ if (log.isInfoEnabled()) {
log.info(sm.getString("jvmRoute.valve.stopped"));
+ }
}
diff --git a/java/org/apache/catalina/ha/session/SessionMessage.java b/java/org/apache/catalina/ha/session/SessionMessage.java
index 5d86102..6517376 100644
--- a/java/org/apache/catalina/ha/session/SessionMessage.java
+++ b/java/org/apache/catalina/ha/session/SessionMessage.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -71,7 +71,7 @@ public interface SessionMessage extends ClusterMessage {
* When a session state is transferred, this is the event.
*/
public static final int EVT_ALL_SESSION_DATA = 12;
-
+
/**
* When a session state is complete transferred, this is the event.
*/
@@ -89,14 +89,14 @@ public interface SessionMessage extends ClusterMessage {
public static final int EVT_ALL_SESSION_NOCONTEXTMANAGER = 16;
public String getContextName();
-
+
public String getEventTypeString();
-
+
/**
* returns the event type
* @return one of the event types EVT_XXXX
*/
- public int getEventType();
+ public int getEventType();
/**
* @return the serialized data for the session
*/
diff --git a/java/org/apache/catalina/ha/session/SessionMessageImpl.java b/java/org/apache/catalina/ha/session/SessionMessageImpl.java
index 1b0c69e..eee2fdc 100644
--- a/java/org/apache/catalina/ha/session/SessionMessageImpl.java
+++ b/java/org/apache/catalina/ha/session/SessionMessageImpl.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@ import org.apache.catalina.ha.ClusterMessageBase;
/**
* Session cluster message
- *
+ *
* @author Filip Hanik
* @author Peter Rossbach
*/
@@ -35,7 +35,6 @@ public class SessionMessageImpl extends ClusterMessageBase implements SessionMes
/*
-
* Private serializable variables to keep the messages state
*/
private int mEvtType = -1;
@@ -118,7 +117,7 @@ public class SessionMessageImpl extends ClusterMessageBase implements SessionMes
*/
@Override
public String getSessionID(){ return mSessionID; }
-
+
/**
* set message send time but only the first setting works (one shot)
*/
@@ -131,12 +130,12 @@ public class SessionMessageImpl extends ClusterMessageBase implements SessionMes
}
}
}
-
+
@Override
public long getTimestamp() { return serializationTimestamp;}
-
+
/**
- * clear text event type name (for logging purpose only)
+ * clear text event type name (for logging purpose only)
* @return the event type in a string representation, useful for debugging
*/
@Override
@@ -161,6 +160,7 @@ public class SessionMessageImpl extends ClusterMessageBase implements SessionMes
public String getContextName() {
return mContextName;
}
+
@Override
public String getUniqueId() {
return uniqueId;
diff --git a/java/org/apache/catalina/ha/session/mbeans-descriptors.xml b/java/org/apache/catalina/ha/session/mbeans-descriptors.xml
index 02a0b82..bc85c13 100644
--- a/java/org/apache/catalina/ha/session/mbeans-descriptors.xml
+++ b/java/org/apache/catalina/ha/session/mbeans-descriptors.xml
@@ -299,7 +299,7 @@
<attribute
name="stateTransfered"
description="Is session state transferred complete? "
- type="boolean"/>
+ type="boolean"/>
<attribute
name="stateTransferTimeout"
description="state transfer timeout in sec"
@@ -383,7 +383,7 @@
description="Return the set of active Sessions associated with this Manager."
impact="ACTION"
returnType="[Lorg.apache.catalina.Session;">
- </operation>
+ </operation>
<operation
name="getAllClusterSessions"
description="send to oldest cluster member that this node need all cluster sessions (resync member)"
@@ -398,7 +398,7 @@
name="sessionId"
description="The session id for the session "
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="getLastAccessedTime"
description="Get the last access time. This one gets updated whenever a request finishes. "
@@ -408,7 +408,7 @@
name="sessionId"
description="Id of the session"
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="getSessionAttribute"
description="Return a session attribute"
@@ -432,7 +432,7 @@
name="sessionId"
description="Id of the session"
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="listSessionIds"
description="Return the list of active primary session ids"
@@ -621,7 +621,7 @@
description="Return the set of active Sessions associated with this Manager."
impact="ACTION"
returnType="[Lorg.apache.catalina.Session;">
- </operation>
+ </operation>
<operation
name="getCreationTime"
description="Return the creation time for this session"
@@ -631,7 +631,7 @@
name="sessionId"
description="The session id for the session "
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="getLastAccessedTime"
description="Get the last access time. This one gets updated whenever a request finishes. "
@@ -641,7 +641,7 @@
name="sessionId"
description="Id of the session"
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="getSessionAttribute"
description="Return a session attribute"
@@ -665,7 +665,7 @@
name="sessionId"
description="Id of the session"
type="java.lang.String"/>
- </operation>
+ </operation>
<operation
name="listSessionIds"
description="Return the list of active primary session ids"
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org