Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51736.
authorkfujino <kfujino@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Aug 2011 10:30:38 +0000 (10:30 +0000)
committerkfujino <kfujino@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 29 Aug 2011 10:30:38 +0000 (10:30 +0000)
Make rpcTimeout configurable in BackupManager.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1162721 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/ha/session/BackupManager.java
java/org/apache/catalina/ha/session/mbeans-descriptors.xml
java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java
webapps/docs/config/cluster-manager.xml

index 316cac5..2d0a53a 100644 (file)
@@ -67,6 +67,11 @@ public class BackupManager extends ClusterManagerBase
     private int mapSendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK;
 
     /**
+     * Timeout for RPC messages.
+     */
+    private long rpcTimeout = DEFAULT_REPL_TIMEOUT;
+
+    /**
      * Constructor, just calls super()
      *
      */
@@ -158,7 +163,7 @@ public class BackupManager extends ClusterManagerBase
             CatalinaCluster catclust = cluster;
             LazyReplicatedMap map = new LazyReplicatedMap(this,
                                                           catclust.getChannel(),
-                                                          DEFAULT_REPL_TIMEOUT,
+                                                          rpcTimeout,
                                                           getMapName(),
                                                           getClassLoaders());
             map.setChannelSendOptions(mapSendOptions);
@@ -238,6 +243,14 @@ public class BackupManager extends ClusterManagerBase
         return mapSendOptions;
     }
 
+    public void setRpcTimeout(long rpcTimeout) {
+        this.rpcTimeout = rpcTimeout;
+    }
+
+    public long getRpcTimeout() {
+        return rpcTimeout;
+    }
+
     @Override
     public String[] getInvalidatedSessions() {
         return new String[0];
@@ -252,6 +265,7 @@ public class BackupManager extends ClusterManagerBase
         result.notifyListenersOnReplication = notifyListenersOnReplication;
         result.mapSendOptions = mapSendOptions;
         result.maxActiveSessions = maxActiveSessions;
+        result.rpcTimeout = rpcTimeout;
         return result;
     }
 
index 3ece61d..4c6fc5c 100644 (file)
       name="rejectedSessions"
       description="Number of sessions we rejected due to maxActive beeing reached"
       type="int"/>
+    <attribute
+      name="rpcTimeout"
+      description="Timeout for RPC messages, how long we will wait for a reply"
+      type="long"/>
     <operation
       name="expireSession"
       description="Expired the given session"
index 78efcf1..b6df43c 100644 (file)
@@ -305,14 +305,20 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
      * @throws ChannelException
      */
     protected void broadcast(int msgtype, boolean rpc) throws ChannelException {
+        // No destination.
+        if (channel.getMembers().length == 0 ) return;
         //send out a map membership message, only wait for the first reply
         MapMessage msg = new MapMessage(this.mapContextName, msgtype,
                                         false, null, null, null, channel.getLocalMember(false), null);
         if ( rpc) {
             Response[] resp = rpcChannel.send(channel.getMembers(), msg, RpcChannel.FIRST_REPLY, (channelSendOptions),rpcTimeout);
-            for (int i = 0; i < resp.length; i++) {
-                mapMemberAdded(resp[i].getSource());
-                messageReceived(resp[i].getMessage(), resp[i].getSource());
+            if (resp.length > 0) {
+                for (int i = 0; i < resp.length; i++) {
+                    mapMemberAdded(resp[i].getSource());
+                    messageReceived(resp[i].getMessage(), resp[i].getSource());
+                }
+            } else {
+                log.warn("broadcast 0 replies, probably a timeout.");
             }
         } else {
             channel.send(channel.getMembers(),msg,channelSendOptions);
index 054c71e..8e92c71 100644 (file)
         sessions where the current node is the primary node for the session are
         considered active sessions.
       </attribute>
+      <attribute name="rpcTimeout" required="false">
+        Timeout for RPC message used for broadcast and transfer state from 
+        another map.
+        Default value is <code>15000</code> milliseconds.
+      </attribute>
     </attributes>
   </subsection>
 </section>