[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/bisocket ...
Ron Sigal
ron_sigal at yahoo.com
Sun Mar 11 16:09:28 EDT 2007
User: rsigal
Date: 07/03/11 16:09:28
Modified: src/main/org/jboss/remoting/transport/bisocket Tag:
remoting_2_x BisocketServerInvoker.java
Log:
JBREM-721, JBREM-722, JBREM-723: (1) Made ControlMonitorTimerTask static; (2) added destroyControlConnection(); (3) handleInternalInvocation() looks for REMOVECLIENTLISTENER messages; (4) ControlConnectionThread gives a new control connection 5 ping cycles before declaring it nonfunctional.
Revision Changes Path
No revision
No revision
1.1.2.11 +71 -22 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.10
retrieving revision 1.1.2.11
diff -u -b -r1.1.2.10 -r1.1.2.11
--- BisocketServerInvoker.java 25 Feb 2007 21:20:39 -0000 1.1.2.10
+++ BisocketServerInvoker.java 11 Mar 2007 20:09:28 -0000 1.1.2.11
@@ -57,7 +57,7 @@
/**
*
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.2.10 $
+ * @version $Revision: 1.1.2.11 $
* <p>
* Copyright Nov 23, 2006
* </p>
@@ -149,15 +149,16 @@
{
boolean firstConnection;
- // restarting connection
if (locator == null)
{
+ // restarting connection
firstConnection = false;
BisocketClientInvoker clientInvoker = BisocketClientInvoker.getBisocketClientInvoker(listenerId);
try
{
locator = clientInvoker.getSecondaryLocator();
+ listenerIdToInvokerLocatorMap.put(listenerId, locator);
}
catch (Throwable t)
{
@@ -165,9 +166,9 @@
throw new IOException("unable to get secondary locator: " + t.getMessage());
}
}
- // first connection
else
{
+ // first connection
firstConnection = true;
listenerIdToInvokerLocatorMap.put(listenerId, locator);
}
@@ -208,12 +209,22 @@
{
timer = new Timer(true);
}
- controlMonitorTimerTask = new ControlMonitorTimerTask();
+ controlMonitorTimerTask = new ControlMonitorTimerTask(this);
timer.schedule(controlMonitorTimerTask, pingFrequency, pingFrequency);
}
}
+ public void destroyControlConnection(String listenerId) throws IOException
+ {
+ listenerIdToInvokerLocatorMap.remove(listenerId);
+ Thread t = (Thread) controlConnectionThreadMap.remove(listenerId);
+ ((ControlConnectionThread)t).shutdown();
+ controlMonitorTimerTask.shutdown();
+ controlMonitorTimerTask = null;
+ }
+
+
public int getPingFrequency()
{
return pingFrequency;
@@ -432,6 +443,18 @@
}
}
}
+ else if(InternalInvocation.REMOVECLIENTLISTENER.equals(ii.getMethodName()))
+ {
+ Map metadata = ir.getRequestPayload();
+ if(metadata != null)
+ {
+ String listenerId = (String) metadata.get(Client.LISTENER_ID_KEY);
+ if (listenerId != null)
+ {
+ listenerIdToServerInvokerMap.remove(listenerId);
+ }
+ }
+ }
return response;
}
@@ -439,12 +462,14 @@
class ControlConnectionThread extends Thread
{
+ private static final int MAX_INITIAL_ATTEMPTS = 5;
private Socket controlSocket;
private String listenerId;
private DataInputStream dis;
private boolean running;
private int errorCount;
private long lastPing = -1;
+ private int initialAttempts;
ControlConnectionThread(Socket socket, String listenerId) throws IOException
{
@@ -473,10 +498,15 @@
boolean checkConnection()
{
- if (lastPing < 0)
+ if (lastPing < 0 && initialAttempts++ < MAX_INITIAL_ATTEMPTS)
{
return true;
}
+ else if (lastPing < 0)
+ {
+ return false;
+ }
+
long currentTime = System.currentTimeMillis();
if (log.isTraceEnabled())
@@ -679,18 +709,34 @@
}
- class ControlMonitorTimerTask extends TimerTask
+ static class ControlMonitorTimerTask extends TimerTask
{
private boolean running = true;
+ private BisocketServerInvoker invoker;
+ private Map listenerIdToInvokerLocatorMap;
+ private Map controlConnectionThreadMap;
- void shutdown()
+ ControlMonitorTimerTask(BisocketServerInvoker invoker)
+ {
+ this.invoker = invoker;
+ listenerIdToInvokerLocatorMap = invoker.listenerIdToInvokerLocatorMap;
+ controlConnectionThreadMap = invoker.controlConnectionThreadMap;
+ }
+
+ synchronized void shutdown()
{
running = false;
+ invoker = null;
+ listenerIdToInvokerLocatorMap = null;
+ controlConnectionThreadMap = null;
cancel();
}
- public void run()
+ public synchronized void run()
{
+ if (!running)
+ return;
+
if (log.isTraceEnabled())
log.trace("checking connections");
@@ -701,10 +747,10 @@
}
if (controlConnectionThreads.isEmpty())
- cancel();
+ shutdown();
Iterator it = controlConnectionThreads.iterator();
- while (it.hasNext() & running)
+ while (it.hasNext())
{
final ControlConnectionThread t = (ControlConnectionThread) it.next();
if (!t.checkConnection())
@@ -717,16 +763,18 @@
controlConnectionThreadMap.remove(t.getListenerId());
}
- if (!running)
- return;
-
new Thread()
{
public void run()
{
+ synchronized (ControlMonitorTimerTask.this)
+ {
+ if (!running)
+ return;
+
try
{
- createControlConnection(t.getListenerId(), null);
+ invoker.createControlConnection(t.getListenerId(), null);
}
catch (IOException e)
{
@@ -734,6 +782,7 @@
log.error("Unable to recreate control connection: " + locator, e);
}
}
+ }
}.start();
}
More information about the jboss-cvs-commits
mailing list