You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pe...@apache.org on 2005/10/18 16:08:48 UTC

svn commit: r326110 - in /tomcat/container/tc5.5.x/modules/cluster: ./ src/share/org/apache/catalina/cluster/session/

Author: pero
Date: Tue Oct 18 07:08:36 2005
New Revision: 326110

URL: http://svn.apache.org/viewcvs?rev=326110&view=rev
Log:
Better support cluster at engine level
Fix some typos
Used Hashtable instead Hashmap at DeltaSession

Modified:
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/LocalStrings.properties
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java
    tomcat/container/tc5.5.x/modules/cluster/to-do.txt

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java Tue Oct 18 07:08:36 2005
@@ -609,7 +609,7 @@
         if(cluster.getMembers().length > 0 ) {
             SessionMessage msg = new SessionMessageImpl(getName(),
                     SessionMessage.EVT_SESSION_CREATED, null, sessionId,
-                    sessionId + System.currentTimeMillis());
+                    sessionId + "-" + System.currentTimeMillis());
             if (log.isDebugEnabled())
                 log.debug(sm.getString("deltaManager.sendMessage.newSession",
                         name, sessionId));
@@ -1048,7 +1048,7 @@
     }
 
     /**
-     * Find the master óf the session state
+     * Find the master of the session state
      * @return master member of sessions 
      */
     protected Member findSessionMasterMember() {
@@ -1249,7 +1249,7 @@
                 byte[] data = unloadDeltaRequest(deltaRequest);
                 msg = new SessionMessageImpl(name,
                         SessionMessage.EVT_SESSION_DELTA, data, sessionId,
-                        sessionId + System.currentTimeMillis());
+                        sessionId + "-" + System.currentTimeMillis());
                 session.resetDeltaRequest();
                 if (log.isDebugEnabled()) {
                     log.debug(sm.getString(
@@ -1261,7 +1261,7 @@
                 counterSend_EVT_SESSION_ACCESSED++;
                 msg = new SessionMessageImpl(getName(),
                         SessionMessage.EVT_SESSION_ACCESSED, null, sessionId,
-                        sessionId + System.currentTimeMillis());
+                        sessionId + "-" + System.currentTimeMillis());
                 if (log.isDebugEnabled()) {
                     log.debug(sm.getString(
                             "deltaManager.createMessage.accessChangePrimary",
@@ -1277,7 +1277,7 @@
                     counterSend_EVT_SESSION_ACCESSED++;
                     msg = new SessionMessageImpl(getName(),
                             SessionMessage.EVT_SESSION_ACCESSED, null,
-                            sessionId, sessionId + System.currentTimeMillis());
+                            sessionId, sessionId + "-" + System.currentTimeMillis());
                     if (log.isDebugEnabled()) {
                         log.debug(sm.getString(
                                 "deltaManager.createMessage.access", getName(),
@@ -1568,15 +1568,18 @@
             log.debug(sm.getString(
                     "deltaManager.receiveMessage.createNewSession",
                     getName(), msg.getSessionID()));
-        DeltaSession session = (DeltaSession) createSession(msg
-                .getSessionID(), false);
+        DeltaSession session = (DeltaSession) createEmptySession();
+        session.setManager(this);
+        session.setValid(true);
+        session.setPrimarySession(false);
+        session.access();
         if(notifySessionListenersOnReplication)
             session.setId(msg.getSessionID());
         else
-            session.getDeltaRequest().setSessionId(msg.getSessionID());
-        session.setNew(false);
-        session.setPrimarySession(false);
+            session.setIdInternal(msg.getSessionID());
         session.resetDeltaRequest();
+        session.endAccess();
+
     }
 
     /**

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java Tue Oct 18 07:08:36 2005
@@ -29,7 +29,9 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Map;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
@@ -89,6 +91,11 @@
     // ----------------------------------------------------- Instance Variables
 
     /**
+     * Type array.
+     */
+    protected static final String EMPTY_ARRAY[] = new String[0];
+
+    /**
      * The dummy attribute value serialized when a NotSerializableException is
      * encountered in <code>writeObject()</code>.
      */
@@ -97,7 +104,7 @@
     /**
      * The collection of user data attributes associated with this Session.
      */
-    private HashMap attributes = new HashMap();
+    private Map attributes = new Hashtable();
 
     /**
      * The authentication type used to authenticate our cached Principal, if
@@ -194,7 +201,7 @@
      * event listeners. <b>IMPLEMENTATION NOTE: </b> This object is <em>not</em>
      * saved and restored across session serializations!
      */
-    private transient HashMap notes = new HashMap();
+    private transient Map notes = new Hashtable();
 
     /**
      * The authenticated Principal associated with this session, if any.
@@ -352,13 +359,12 @@
 
 
     /**
-     * Set the session identifier for this session.
+     * Set the session identifier for this session without notify listeners.
      * 
      * @param id
      *            The new session identifier
      */
-    public void setId(String id) {
-
+    public void setIdInternal(String id) {
         if ((this.id != null) && (manager != null))
             manager.remove(this);
 
@@ -366,12 +372,22 @@
 
         if (manager != null)
             manager.add(this);
-        tellNew();
         if ( deltaRequest == null ) resetDeltaRequest();
         else deltaRequest.setSessionId(id);
     }
 
     /**
+     * Set the session identifier for this session.
+     * 
+     * @param id
+     *            The new session identifier
+     */
+    public void setId(String id) {
+        setIdInternal(id);
+        tellNew();
+     }
+
+    /**
      * Inform the listeners about the new session.
      *  
      */
@@ -763,11 +779,7 @@
      *            Name of the note to be returned
      */
     public Object getNote(String name) {
-
-        synchronized (notes) {
             return (notes.get(name));
-        }
-
     }
 
     /**
@@ -775,11 +787,7 @@
      * exist for this session.
      */
     public Iterator getNoteNames() {
-
-        synchronized (notes) {
             return (notes.keySet().iterator());
-        }
-
     }
 
     /**
@@ -789,9 +797,7 @@
     public void recycle() {
 
         // Reset the instance variables associated with this Session
-        synchronized (attributes) {
-            attributes.clear();
-        }
+        attributes.clear();
         setAuthType(null);
         creationTime = 0L;
         expiring = false;
@@ -799,9 +805,7 @@
         lastAccessedTime = 0L;
         maxInactiveInterval = -1;
         accessCount = 0;
-        synchronized (notes) {
-            notes.clear();
-        }
+        notes.clear();
         setPrincipal(null);
         isNew = false;
         isValid = false;
@@ -818,11 +822,7 @@
      *            Name of the note to be removed
      */
     public void removeNote(String name) {
-
-        synchronized (notes) {
-            notes.remove(name);
-        }
-
+        notes.remove(name);
     }
 
     /**
@@ -846,11 +846,7 @@
      *            Object to be bound to the specified name
      */
     public void setNote(String name, Object value) {
-
-        synchronized (notes) {
-            notes.put(name, value);
-        }
-
+        notes.put(name, value);
     }
 
     /**
@@ -859,7 +855,7 @@
     public String toString() {
 
         StringBuffer sb = new StringBuffer();
-        sb.append("StandardSession[");
+        sb.append("DeltaSession[");
         sb.append(id);
         sb.append("]");
         return (sb.toString());
@@ -986,11 +982,7 @@
         if (!isValid())
             throw new IllegalStateException(sm
                     .getString("standardSession.getAttribute.ise"));
-
-        synchronized (attributes) {
-            return (attributes.get(name));
-        }
-
+        return (attributes.get(name));
     }
 
     /**
@@ -1005,12 +997,7 @@
         if (!isValid())
             throw new IllegalStateException(sm
                     .getString("standardSession.getAttributeNames.ise"));
-
-        synchronized (attributes) {
-            // create a copy from orginal attribute keySet, otherwise internal HaspMap datastructure
-            // can be inconsistence by other threads.
-            return (new Enumerator(new ArrayList(attributes.keySet()), true));
-        }
+        return (new Enumerator(attributes.keySet(), true));
     }
 
     /**
@@ -1258,10 +1245,7 @@
         }
 
         // Replace or add this attribute
-        Object unbound = null ;
-        synchronized (attributes) {
-            unbound = attributes.put(name, value);
-        }
+        Object unbound = attributes.put(name, value);
         // Call the valueUnbound() method if necessary
         if ((unbound != null) && notify
                 && (unbound instanceof HttpSessionBindingListener)) {
@@ -1379,7 +1363,7 @@
 
         // Deserialize the attribute count and attribute values
         if (attributes == null)
-            attributes = new HashMap();
+            attributes = new Hashtable();
         int n = ((Integer) stream.readObject()).intValue();
         boolean isValidSave = isValid;
         isValid = true;
@@ -1388,11 +1372,7 @@
             Object value = (Object) stream.readObject();
             if ((value instanceof String) && (value.equals(NOT_SERIALIZED)))
                 continue;
-            //if (log.isTraceEnabled())
-            //    log.trace(smp.getString("deltaSession.readAttribute", id,name,value));
-            synchronized (attributes) {
-                attributes.put(name, value);
-            }
+            attributes.put(name, value);
         }
         isValid = isValidSave;
         
@@ -1401,7 +1381,7 @@
         }
         
         if (notes == null) {
-            notes = new HashMap();
+            notes = new Hashtable();
         }
     }
 
@@ -1451,9 +1431,7 @@
         ArrayList saveValues = new ArrayList();
         for (int i = 0; i < keys.length; i++) {
             Object value = null;
-            synchronized (attributes) {
-                value = attributes.get(keys[i]);
-            }
+            value = attributes.get(keys[i]);
             if (value == null)
                 continue;
             else if (value instanceof Serializable) {
@@ -1561,23 +1539,14 @@
      * returned.
      */
     protected String[] keys() {
-
-        String results[] = new String[0];
-        synchronized (attributes) {
-            return ((String[]) attributes.keySet().toArray(results));
-        }
-
+        return ((String[]) attributes.keySet().toArray(EMPTY_ARRAY));
     }
 
     /**
      * Return the value of an attribute without a check for validity.
      */
     protected Object getAttributeInternal(String name) {
-
-        synchronized (attributes) {
-            return (attributes.get(name));
-        }
-
+        return (attributes.get(name));  
     }
 
     protected void removeAttributeInternal(String name, boolean notify,

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java Tue Oct 18 07:08:36 2005
@@ -390,6 +390,7 @@
         msg.setBackupSessionID(newSessionID);
         Context context = request.getContext();
         msg.setContextPath(context.getPath());
+        msg.setHost(context.getParent().getName());
         if(manager.isSendClusterDomainOnly())
             cluster.sendClusterDomain(msg);
         else

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java Tue Oct 18 07:08:36 2005
@@ -20,6 +20,7 @@
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Session;
 import org.apache.catalina.cluster.ClusterMessage;
@@ -37,7 +38,7 @@
     /**
      * The descriptive information about this implementation.
      */
-    protected static final String info = "org.apache.catalina.session.JvmRouteSessionIDBinderListener/1.1";
+    protected static final String info = "org.apache.catalina.cluster.session.JvmRouteSessionIDBinderListener/1.1";
 
     //--Instance Variables--------------------------------------
 
@@ -114,7 +115,13 @@
                                 .getOrignalSessionID(), sessionmsg
                                 .getBackupSessionID(), sessionmsg
                                 .getContextPath()));
-            Container host = getCluster().getContainer();
+            Container container = getCluster().getContainer();
+            Container host = null ;
+            if(container instanceof Engine) {
+                host = container.findChild(sessionmsg.getHost());
+            } else {
+                host = container ;
+            }
             if (host != null) {
                 Context context = (Context) host.findChild(sessionmsg
                         .getContextPath());

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/LocalStrings.properties
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/LocalStrings.properties?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/LocalStrings.properties (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/LocalStrings.properties Tue Oct 18 07:08:36 2005
@@ -53,9 +53,9 @@
 jvmRoute.cannotFindSession=Can't find session [{0}]
 jvmRoute.changeSession=Changed session from [{0}] to [{1}]
 jvmRoute.clusterListener.started=Cluster JvmRouteSessionIDBinderListener started
-jvmRoute.clusterListener.stopped=Cluster JvmRouteSessionIDBinderListener stoppedjvmRoute.listener.started=SessionID Binder Listener started
+jvmRoute.clusterListener.stopped=Cluster JvmRouteSessionIDBinderListener stopped
 jvmRoute.configure.warn=Please, setup your JvmRouteBinderValve at host valve, not at context valve!
-jvmRoute.contextNotFound=Context [{0}] not found at note [{1}]!
+jvmRoute.contextNotFound=Context [{0}] not found at node [{1}]!
 jvmRoute.failover=Detected a failover with different jvmRoute - orginal route: [{0}] new one: [{1}] at session id [{2}]
 jvmRoute.foundManager=Found Cluster DeltaManager {0} at {1}
 jvmRoute.hostNotFound=No host found [{0}]

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java Tue Oct 18 07:08:36 2005
@@ -36,6 +36,7 @@
 
 	private String backupSessionID;
 
+	private String host ;
 	private String contextPath;
     private int resend = ClusterMessage.FLAG_DEFAULT ;
     private int compress = ClusterMessage.FLAG_DEFAULT ;
@@ -51,7 +52,9 @@
 	public String getUniqueId() {
 		StringBuffer result = new StringBuffer(getOrignalSessionID());
 		result.append("#-#");
-		result.append(getBackupSessionID());
+		result.append(getHost());
+                result.append("#-#");
+                result.append(getContextPath());
 		result.append("#-#");
 		result.append(getMessageNumber());
 		result.append("#-#");
@@ -59,6 +62,20 @@
 		return result.toString();
 	}
 
+	/**
+         * @return Returns the host.
+         */
+        public String getHost() {
+             return host;
+        }
+    
+        /**
+         * @param host The host to set.
+         */
+         public void setHost(String host) {
+             this.host = host;
+        }
+    
 	/**
 	 * @return Returns the contextPath.
 	 */

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java Tue Oct 18 07:08:36 2005
@@ -85,7 +85,6 @@
      * @param session - the serialized byte array of the session itself
      * @param sessionID - the id that identifies this session
      * @param uniqueID - the id that identifies this message
-
      */
     public SessionMessageImpl( String contextName,
                            int eventtype,
@@ -102,10 +101,12 @@
      * @return one of the event types EVT_XXXX
      */
     public int getEventType() { return mEvtType; }
+
     /**
      * @return the serialized data for the session
      */
     public byte[] getSession() { return mSession;}
+
     /**
      * @return the session ID for the session
      */

Modified: tomcat/container/tc5.5.x/modules/cluster/to-do.txt
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/to-do.txt?rev=326110&r1=326109&r2=326110&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/to-do.txt (original)
+++ tomcat/container/tc5.5.x/modules/cluster/to-do.txt Tue Oct 18 07:08:36 2005
@@ -76,7 +76,7 @@
             - send message
             - current members
             - receive message
-            - active session at differen clustered manager
+            - active session at different clustered manager
             - which app are clusters (registered managers)
             - avg processing times
          
@@ -101,19 +101,17 @@
 
 ================
 problems
-================
-- MemoryUser principal from UserDatabaseRealm not handled to replicated 
-	- look inside DeltaRequest.setPrincipal(Principal,boolean)
-		 detected by Dirk de Kok (tomdev 16.8.2005)
-	- only GenericPrincipal from all other realms are handled well.
-- We not set SimpleTcpCluster Properties when element exists inside config.
-	Element must have all properties!! - Note inside docs!!  
+================ 
 - How we can stop the request traffic when restart an application?
     currently the jk 1.2.10 can only disable the complete loadbalancer,
     but this detect only the new session request desicion.
     Request with sessions marks send to tomcat. 
     Fix: jk > 1.2.11 has a stopped flag, but then all application stop traffic
     and session transfer from other nodes not stopped!!
+    	Stop MembershipService via JMX and after redeploying application,
+    	start MembershipService and restart the application Session Manager or send GETALL Session from backup?
+    	then enable apache worker again !! :-(
+    	easier stop tomcats, deploy new app and start again... 
 - Can't stop message replication for a spezial member and application
    - this need a spezial cluster message and send filter at SimpleTcpCluster 
 - Don't generate cluster message when no member is at cluster!
@@ -124,11 +122,7 @@
 ==============================
 Nice to have:
 ==============================
-- Replication ContextAttributes
-- Cluster config at engine level (user request 06/05)
-	 Register a cluster infrastructur for many vhosts
-	 configure backup systems!
-	 Add Cluster Element to digister		
+- Replication ContextAttributes	
 - Configure the McastService no accept every member.
 	- receive a secret key
 	- have a allow or deny list like RequestFilterValve
@@ -205,7 +199,17 @@
 ==============================   
 COMPLETED
 ==============================
+5.5.11 (pero)
+- MemoryUser principal from UserDatabaseRealm not handled to replicated 
+	- look inside DeltaRequest.setPrincipal(Principal,boolean)
+		 detected by Dirk de Kok (tomdev 16.8.2005)
+	- only GenericPrincipal from all other realms are handled well.
+    - change JAASRealm and UserDatabaseRealm that also used GenericPrincipal
 5.5.10 (pero)
+- Cluster config at engine level (user request 06/05)
+	 Register a cluster infrastructur for many vhosts
+	 configure backup systems!
+	 Add Cluster Element to digister		
 - add mapping sender mapping properties file (IDataSenderFactory)
 	- let advanced people eaiser implemented there own sender mode
 - We register different application with same name from different host?



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org