Fixed manager registration and how manager names are handled. Make sure the manager...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 16 Oct 2006 19:23:34 +0000 (19:23 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 16 Oct 2006 19:23:34 +0000 (19:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@464632 13f79535-47bb-0310-9956-ffa450edef68

conf/server.xml
java/org/apache/catalina/core/StandardContext.java
java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
webapps/docs/cluster-howto.xml
webapps/docs/config/cluster-receiver.xml

index 779f216..8eb2dca 100644 (file)
     <!-- Define the top level container in our container hierarchy -->
     <Engine name="Catalina" defaultHost="localhost">
 
+      <!--
+      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
+               channelSendOptions="11">
+        <Manager className="org.apache.catalina.ha.session.DeltaManager"
+                 expireSessionsOnShutdown="false"
+                 notifyListenersOnReplication="true"/>
+      
+        <Channel className="org.apache.catalina.tribes.group.GroupChannel">
+          <Membership className="org.apache.catalina.tribes.membership.McastService"
+                      address="228.0.0.4"
+                      port="45564"
+                      frequency="500"
+                      dropTime="3000"/>
+          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
+                    address="auto"
+                    port="auto"
+                    selectorTimeout="100"
+                    maxThreads="6"/>
+          <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
+            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
+          </Sender>
+          <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
+          <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
+          <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
+        </Channel>
+
+        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
+               filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
+
+        <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
+                  tempDir="/tmp/war-temp/"
+                  deployDir="/tmp/war-deploy/"
+                  watchDir="/tmp/war-listen/"
+                  watchEnabled="false"/>
+        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
+      </Cluster>
+      -->        
+
+
       <!-- The request dumper valve dumps useful debugging information about
            the request headers and cookies that were received, and the response
            headers and cookies that were sent, for all requests received by
         <!-- Place holder for brief cluster documentation, the rest will be online
         -->
         
-        <!--
-        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
-                 channelSendOptions="11">
-          <Manager className="org.apache.catalina.ha.session.DeltaManager"
-                   expireSessionsOnShutdown="false"
-                   notifyListenersOnReplication="true"/>
-        
-          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
-            <Membership className="org.apache.catalina.tribes.membership.McastService"
-                        address="228.0.0.4"
-                        port="45564"
-                        frequency="500"
-                        dropTime="3000"/>
-            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
-                      address="auto"
-                      port="auto"
-                      selectorTimeout="100"
-                      maxThreads="6"/>
-
-            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
-              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
-            </Sender>
-            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
-            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
-            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
-          </Channel>
-
-          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
-                 filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
-
-          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
-                    tempDir="/tmp/war-temp/"
-                    deployDir="/tmp/war-deploy/"
-                    watchDir="/tmp/war-listen/"
-                    watchEnabled="false"/>
-
-          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
-        </Cluster>
-        -->        
-
-
-
         <!-- Normally, users must authenticate themselves to each web app
              individually.  Uncomment the following entry if you would like
              a user to be authenticated the first time they encounter a
index afac9f3..5031d85 100644 (file)
@@ -4249,16 +4249,19 @@ public class StandardContext
                     } else {
                         contextManager = new StandardManager();
                     }
-                } else if ( (getCluster() != null) && distributable) {
+                } 
+                
+                // Configure default manager if none was specified
+                if (contextManager != null) {
+                    setManager(contextManager);
+                }
+
+                if (manager!=null && (getCluster() != null) && distributable) {
                     //let the cluster know that there is a context that is distributable
                     //and that it has its own manager
                     getCluster().registerManager(manager);
                 }
 
-                // Configure default manager if none was specified
-                if (contextManager != null) {
-                       setManager(contextManager);
-                }
                 
                 // Start manager
                 if ((manager != null) && (manager instanceof Lifecycle)) {
index 4577d34..691f1e5 100644 (file)
@@ -221,8 +221,8 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life
             long t1 = System.currentTimeMillis();
             String jvmRoute = getLocalJvmRoute(request);
             if (jvmRoute == null) {
-                if (log.isWarnEnabled())
-                    log.warn(sm.getString("jvmRoute.missingJvmRouteAttribute"));
+                if (log.isDebugEnabled())
+                    log.debug(sm.getString("jvmRoute.missingJvmRouteAttribute"));
                 return;
             }
             handleJvmRoute( request, response,session.getIdInternal(), jvmRoute);
index 753c91b..6812302 100644 (file)
@@ -53,6 +53,11 @@ import org.apache.catalina.util.StringManager;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.catalina.ha.session.ClusterSessionListener;
+import org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor;
+import org.apache.catalina.tribes.group.interceptors.TcpFailureDetector;
+import org.apache.catalina.ha.session.JvmRouteBinderValve;
+import org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener;
 
 /**
  * A <b>Cluster </b> implementation using simple multicast. Responsible for
@@ -167,10 +172,7 @@ public class SimpleTcpCluster
      */
     private Map properties = new HashMap();
     
-    private int channelSendOptions = 
-        Channel.SEND_OPTIONS_ASYNCHRONOUS |
-        Channel.SEND_OPTIONS_SYNCHRONIZED_ACK |
-        Channel.SEND_OPTIONS_USE_ACK;
+    private int channelSendOptions = Channel.SEND_OPTIONS_ASYNCHRONOUS;
 
     // ------------------------------------------------------------- Properties
 
@@ -272,7 +274,7 @@ public class SimpleTcpCluster
      * @param valve The new cluster Valve.
      */
     public void addValve(Valve valve) {
-        if (valve instanceof ClusterValve)
+        if (valve instanceof ClusterValve && (!valves.contains(valve)))
             valves.add(valve);
     }
 
@@ -506,7 +508,7 @@ public class SimpleTcpCluster
             log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x);
             manager = new org.apache.catalina.ha.session.DeltaManager();
         } finally {
-            if(manager != null) registerManager(manager);
+            if ( manager != null && (manager instanceof ClusterManager)) ((ClusterManager)manager).setCluster(this);
         }
         return manager;
     }
@@ -560,8 +562,8 @@ public class SimpleTcpCluster
             Container context = manager.getContainer() ;
             if(context != null && context instanceof Context) {
                 Container host = ((Context)context).getParent();
-                if(host != null && host instanceof Host)
-                    clusterName = host.getName() +"#" + name ;
+                if(host != null && host instanceof Host && clusterName!=null && !(clusterName.indexOf("#")>=0))
+                    clusterName = host.getName() +"#" + clusterName ;
             }
         }
         return clusterName;
@@ -656,9 +658,8 @@ public class SimpleTcpCluster
         // Notify our interested LifecycleListeners
         lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, this);
         try {
-            if ( clusterDeployer != null ) clusterDeployer.setCluster(this);
-            this.registerClusterValve();
-            if ( channel == null ) channel = new GroupChannel();
+            checkDefaults();
+            registerClusterValve();
             channel.addMembershipListener(this);
             channel.addChannelListener(this);
             channel.start(channel.DEFAULT);
@@ -672,6 +673,23 @@ public class SimpleTcpCluster
         }
     }
 
+    protected void checkDefaults() {
+        if ( clusterListeners.size() == 0 ) {
+            addClusterListener(new JvmRouteSessionIDBinderListener()); 
+            addClusterListener(new ClusterSessionListener());
+        }
+        if ( valves.size() == 0 ) {
+            addValve(new JvmRouteBinderValve());
+            addValve(new ReplicationValve());
+        }
+        if ( clusterDeployer != null ) clusterDeployer.setCluster(this);
+        if ( channel == null ) channel = new GroupChannel();
+        if ( channel instanceof GroupChannel && !((GroupChannel)channel).getInterceptors().hasNext()) {
+            channel.addInterceptor(new MessageDispatch15Interceptor());
+            channel.addInterceptor(new TcpFailureDetector());
+        }
+    }
+
     /**
      * register all cluster valve to host or engine
      * @throws Exception
index 3ae54b2..048315e 100644 (file)
 </p>
 </section>
 
-<section name="Quick Start">
+<section name="For the impatient">
+  <p>
+    Simply add <source>&lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;/&gt;</source>
+    to your <code>&lt;Engine&gt;</code> or your <code>&lt;Host&gt;</code> element to enable clustering.
+  </p>
+  <p>
+    Using the above configuration will enable all to all session replication
+    using the <code>DeltaManager</code> to replicate session deltas.<br/>
+    Here are some of the important default values:<br/>
+    1. Multicast address is 228.0.0.4<br/>
+    2. Multicast port is 45564<br/>
+    3. The IP broadcasted is <code>java.net.InetAddress.getLocalHost().getHostAddress()</code><br/>
+    4. The TCP port listening for replication messages is the first available server socket in range <code>4000-4100</code><br/>
+  </p>
+</section>
+
+<section name="Cluster Basics">
 
-<p>To run session replication in your Tomcat 5.5 container, the following steps
+<p>To run session replication in your Tomcat 6.0 container, the following steps
 should be completed:</p>
 <ul>
 <li>All your session attributes must implement <code>java.io.Serializable</code></li>
@@ -41,7 +57,7 @@ should be completed:</p>
 <a href="balancer-howto.html">Load Balancing</a> chapter.</p>
 <p>Note: Remember that your session state is tracked by a cookie, so your URL must look the same from the out
    side otherwise, a new session will be created.</p>
-<p>Note: Clustering support currently requires the JDK version 1.4 or later.</p>
+<p>Note: Clustering support currently requires the JDK version 1.5 or later.</p>
 </section>
 
 
index 84a7f5f..ed0abe2 100644 (file)
@@ -63,7 +63,7 @@
       To avoid port conflicts the receiver will automatically bind to a free port within the range of 
       <code> port &lt;= bindPort &lt;= port+autoBind</code>
       So for example, if port is 4000, and autoBind is set to 10, then the receiver will open up 
-      a server socket on the first available port in the range 4000-4010.
+      a server socket on the first available port in the range 4000-4100.
     </attribute>
     <attribute name="autoBind" required="false">
       Default value is <code>100</code>.