[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/bisocket ...
Ron Sigal
ron_sigal at yahoo.com
Sat Apr 7 04:24:08 EDT 2007
User: rsigal
Date: 07/04/07 04:24:08
Modified: src/main/org/jboss/remoting/transport/bisocket Tag:
remoting_2_x BisocketServerInvoker.java
Log:
JBREM-731: Count control connection restarts only after secondary server socket address changes.
Revision Changes Path
No revision
No revision
1.1.2.19 +35 -21 JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BisocketServerInvoker.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -b -r1.1.2.18 -r1.1.2.19
--- BisocketServerInvoker.java 7 Apr 2007 04:05:47 -0000 1.1.2.18
+++ BisocketServerInvoker.java 7 Apr 2007 08:24:07 -0000 1.1.2.19
@@ -58,7 +58,7 @@
/**
*
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.2.18 $
+ * @version $Revision: 1.1.2.19 $
* <p>
* Copyright Nov 23, 2006
* </p>
@@ -75,7 +75,7 @@
private InvokerLocator secondaryLocator;
private SecondaryServerSocketThread secondaryServerSocketThread;
private Map controlConnectionThreadMap = new HashMap();
- private Map controlConnectionRestartsMap = new HashMap();
+ private Map controlConnectionRestartsMap = Collections.synchronizedMap(new HashMap());
private int pingFrequency = Bisocket.PING_FREQUENCY_DEFAULT;
private int pingWindowFactor = Bisocket.PING_WINDOW_FACTOR_DEFAULT;
private int pingWindow = pingWindowFactor * pingFrequency;
@@ -196,11 +196,12 @@
throw new ClientUnavailableException();
}
- InvokerLocator locator = null;
+ InvokerLocator oldLocator = (InvokerLocator) listenerIdToInvokerLocatorMap.get(listenerId);
+ InvokerLocator newLocator = null;
try
{
- locator = clientInvoker.getSecondaryLocator();
+ newLocator = clientInvoker.getSecondaryLocator();
}
catch (Throwable t)
{
@@ -208,8 +209,17 @@
throw new IOException("unable to get secondary locator: " + t.getMessage());
}
- listenerIdToInvokerLocatorMap.put(listenerId, locator);
- log.trace("creating control connection: " + locator);
+
+ // If a server restarts, it is likely that it creates a new secondary server socket on
+ // a different port. It will possible to recreate the control connection, but if
+ // there is no PingTimerTask running in the new server to keep it alive, it will just
+ // die again. Once a new secondary server socket address is detected, a count is kept
+ // of the number of times the control connection is restarted, and when it hits a
+ // configured maximum, it is allowed to die. See JBREM-731.
+
+ boolean locatorChanged = !newLocator.equals(oldLocator);
+ listenerIdToInvokerLocatorMap.put(listenerId, newLocator);
+ log.debug("creating control connection: " + newLocator);
Socket socket = null;
IOException savedException = null;
@@ -219,9 +229,9 @@
try
{
if (socketFactory != null)
- socket = socketFactory.createSocket(locator.getHost(), locator.getPort());
+ socket = socketFactory.createSocket(newLocator.getHost(), newLocator.getPort());
else
- socket = new Socket(locator.getHost(), locator.getPort());
+ socket = new Socket(newLocator.getHost(), newLocator.getPort());
}
catch (IOException e)
{
@@ -267,17 +277,19 @@
synchronized (controlConnectionThreadMap)
{
controlConnectionThreadMap.put(listenerId, thread);
+ }
+
Object o = controlConnectionRestartsMap.get(listenerId);
if (o != null)
{
int restarts = ((Integer) o).intValue();
+ if (locatorChanged || restarts > 0)
controlConnectionRestartsMap.put(listenerId, new Integer(++restarts));
}
else
{
controlConnectionRestartsMap.put(listenerId, new Integer(0));
}
- }
thread.start();
log.debug("created control connection: " + socket.toString());
@@ -287,12 +299,12 @@
public void destroyControlConnection(String listenerId) throws IOException
{
listenerIdToInvokerLocatorMap.remove(listenerId);
+ controlConnectionRestartsMap.remove(listenerId);
Thread t = null;
synchronized (controlConnectionThreadMap)
{
t = (Thread) controlConnectionThreadMap.remove(listenerId);
- controlConnectionRestartsMap.remove(listenerId);
}
if (t != null)
@@ -877,7 +889,6 @@
if (!t.checkConnection())
{
- log.warn(this + ": detected failure on control connection " + t + ": requesting new control connection");
t.shutdown();
synchronized (this)
@@ -889,13 +900,16 @@
Object o = controlConnectionRestartsMap.get(listenerId);
int restarts = ((Integer)o).intValue();
- if (restarts + 1 >= controlConnectionRestarts)
+ if (restarts + 1 > controlConnectionRestarts)
{
+ log.warn(this + ": detected failure on control connection " + t);
log.warn("Control connection " + listenerId + " has been recreated " + restarts + " times.");
log.warn("Assuming it is a connection to an old server, will not restart");
controlConnectionRestartsMap.remove(listenerId);
continue;
}
+
+ log.warn(this + ": detected failure on control connection " + t + ": requesting new control connection");
}
Thread t2 = new Thread()
More information about the jboss-cvs-commits
mailing list