Author: fhanik Date: Mon Oct 16 12:23:34 2006 New Revision: 464632 URL: http://svn.apache.org/viewvc?view=rev&rev=464632 Log: Fixed manager registration and how manager names are handled. Make sure the manager has a reference to its container before its registered
Modified: tomcat/tc6.0.x/trunk/conf/server.xml tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java tomcat/tc6.0.x/trunk/webapps/docs/cluster-howto.xml tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-receiver.xml Modified: tomcat/tc6.0.x/trunk/conf/server.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/conf/server.xml?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/conf/server.xml (original) +++ tomcat/tc6.0.x/trunk/conf/server.xml Mon Oct 16 12:23:34 2006 @@ -119,6 +119,45 @@ <!-- 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 @@ -191,48 +230,6 @@ <!-- 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 Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Mon Oct 16 12:23:34 2006 @@ -4249,16 +4249,19 @@ } 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)) { Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java Mon Oct 16 12:23:34 2006 @@ -221,8 +221,8 @@ 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); Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Mon Oct 16 12:23:34 2006 @@ -53,6 +53,11 @@ 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 @@ */ 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 @@ * @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 @@ 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 @@ 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 @@ // 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); @@ -669,6 +670,23 @@ } catch (Exception x) { log.error("Unable to start cluster.", x); throw new LifecycleException(x); + } + } + + 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()); } } Modified: tomcat/tc6.0.x/trunk/webapps/docs/cluster-howto.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/cluster-howto.xml?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/cluster-howto.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/cluster-howto.xml Mon Oct 16 12:23:34 2006 @@ -21,9 +21,25 @@ </p> </section> -<section name="Quick Start"> +<section name="For the impatient"> + <p> + Simply add <source><Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/></source> + to your <code><Engine></code> or your <code><Host></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> -<p>To run session replication in your Tomcat 5.5 container, the following steps +<section name="Cluster Basics"> + +<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 @@ <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> Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-receiver.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-receiver.xml?view=diff&rev=464632&r1=464631&r2=464632 ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-receiver.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-receiver.xml Mon Oct 16 12:23:34 2006 @@ -63,7 +63,7 @@ To avoid port conflicts the receiver will automatically bind to a free port within the range of <code> port <= bindPort <= 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>. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]