You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kf...@apache.org on 2013/05/15 07:46:13 UTC

svn commit: r1482684 - in /tomcat/tc7.0.x/trunk: java/org/apache/catalina/ha/tcp/ReplicationValve.java webapps/docs/changelog.xml

Author: kfujino
Date: Wed May 15 05:46:13 2013
New Revision: 1482684

URL: http://svn.apache.org/r1482684
Log:
- Rather than get cluster instance from container on every request, use instance variable.
- Reduce nest.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/ReplicationValve.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/ReplicationValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/ReplicationValve.java?rev=1482684&r1=1482683&r2=1482684&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/ReplicationValve.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/ReplicationValve.java Wed May 15 05:46:13 2013
@@ -26,7 +26,9 @@ import java.util.regex.PatternSyntaxExce
 
 import javax.servlet.ServletException;
 
+import org.apache.catalina.Cluster;
 import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Manager;
 import org.apache.catalina.Session;
 import org.apache.catalina.connector.Request;
@@ -331,26 +333,19 @@ public class ReplicationValve
                 crossContextSessions.set(new ArrayList<DeltaSession>());
             }
             getNext().invoke(request, response);
-            if(context != null) {
-                Manager manager = context.getManager();            
-                if (manager != null && manager instanceof ClusterManager) {
-                    ClusterManager clusterManager = (ClusterManager) manager;
-                    CatalinaCluster containerCluster = (CatalinaCluster) getContainer().getCluster();
-                    if (containerCluster == null) {
-                        if (log.isWarnEnabled())
-                            log.warn(sm.getString("ReplicationValve.nocluster"));
-                        return;
-                    }
-                    // valve cluster can access manager - other cluster handle replication 
-                    // at host level - hopefully!
-                    if(containerCluster.getManager(clusterManager.getName()) == null)
-                        return ;
-                    if(containerCluster.hasMembers()) {
-                        sendReplicationMessage(request, totalstart, isCrossContext, clusterManager, containerCluster);
-                    } else {
-                        resetReplicationRequest(request,isCrossContext);
-                    }        
-                }
+            if(context != null && cluster != null
+                    && context.getManager() instanceof ClusterManager) {
+                ClusterManager clusterManager = (ClusterManager) context.getManager();
+
+                // valve cluster can access manager - other cluster handle replication 
+                // at host level - hopefully!
+                if(cluster.getManager(clusterManager.getName()) == null)
+                    return ;
+                if(cluster.hasMembers()) {
+                    sendReplicationMessage(request, totalstart, isCrossContext, clusterManager, cluster);
+                } else {
+                    resetReplicationRequest(request,isCrossContext);
+                }        
             }
         } finally {
             // Array must be remove: Current master request send endAccess at recycle. 
@@ -378,7 +373,29 @@ public class ReplicationValve
         nrOfSendRequests = 0;
         nrOfCrossContextSendRequests = 0;
     }
-    
+
+    /**
+     * Start this component and implement the requirements
+     * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
+     *
+     * @exception LifecycleException if this component detects a fatal error
+     *  that prevents this component from being used
+     */
+    @Override
+    protected synchronized void startInternal() throws LifecycleException {
+        if (cluster == null) {
+            Cluster containerCluster = getContainer().getCluster();
+            if (containerCluster instanceof CatalinaCluster) {
+                setCluster((CatalinaCluster)containerCluster);
+            } else {
+                if (log.isWarnEnabled()) {
+                    log.warn(sm.getString("ReplicationValve.nocluster"));
+                }
+            }
+        }
+        super.startInternal();
+    }
+
 
     // --------------------------------------------------------- Protected Methods
 

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1482684&r1=1482683&r2=1482684&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed May 15 05:46:13 2013
@@ -83,6 +83,11 @@
         <code>FileMessageFactory</code> in <code>FarmWarDeployer</code>.
         (kfujino)
       </add>
+      <scode>
+        Simplify the code of <code>ReplicationValve</code>: Rather than get
+        cluster instance from container on every request, use instance variable.
+        (kfujino)
+      </scode>
     </changelog>
   </subsection>
 </section>



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