[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/bisocket ...
Ron Sigal
ron_sigal at yahoo.com
Thu Mar 15 02:15:57 EDT 2007
User: rsigal
Date: 07/03/15 02:15:57
Modified: src/main/org/jboss/remoting/transport/bisocket Tag:
remoting_2_x BisocketServerInvoker.java
Log:
JBREM-721, JBREM-725: Changed synchronization in ControlMonitorTimerTask, other small changes.
Revision Changes Path
No revision
No revision
1.1.2.17 +66 -76 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.16
retrieving revision 1.1.2.17
diff -u -b -r1.1.2.16 -r1.1.2.17
--- BisocketServerInvoker.java 14 Mar 2007 06:15:42 -0000 1.1.2.16
+++ BisocketServerInvoker.java 15 Mar 2007 06:15:57 -0000 1.1.2.17
@@ -58,7 +58,7 @@
/**
*
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.2.16 $
+ * @version $Revision: 1.1.2.17 $
* <p>
* Copyright Nov 23, 2006
* </p>
@@ -129,6 +129,11 @@
clientpool.create();
threadpool = new LinkedList();
checkSocketFactoryWrapper();
+
+ timer = new Timer(true);
+ controlMonitorTimerTask = new ControlMonitorTimerTask(this);
+ timer.schedule(controlMonitorTimerTask, pingFrequency, pingFrequency);
+
running = true;
started = true;
}
@@ -175,7 +180,7 @@
if (clientInvoker == null)
{
- log.warn("Unable to retrieve client invoker: must have disconnected");
+ log.debug("Unable to retrieve client invoker: must have disconnected");
throw new ClientUnavailableException();
}
@@ -259,16 +264,6 @@
thread.start();
log.debug("created control connection: " + socket.toString());
-
- if (controlMonitorTimerTask == null)
- {
- if (timer == null)
- {
- timer = new Timer(true);
- }
- controlMonitorTimerTask = new ControlMonitorTimerTask(this);
- timer.schedule(controlMonitorTimerTask, pingFrequency, pingFrequency);
- }
}
@@ -380,18 +375,16 @@
if (controlMonitorTimerTask != null)
controlMonitorTimerTask.shutdown();
- Iterator it = null;
synchronized (controlConnectionThreadMap)
{
- it = controlConnectionThreadMap.values().iterator();
- }
-
+ Iterator it = controlConnectionThreadMap.values().iterator();
while (it.hasNext())
{
ControlConnectionThread t = (ControlConnectionThread) it.next();
it.remove();
t.shutdown();
}
+ }
if (secondaryServerSocketThread != null)
secondaryServerSocketThread.shutdown();
@@ -556,10 +549,7 @@
void shutdown()
{
running = false;
- synchronized (controlConnectionThreadMap)
- {
- controlConnectionThreadMap.remove(this);
- }
+
try
{
controlSocket.close();
@@ -818,6 +808,12 @@
synchronized void shutdown()
{
+ // Note that there is a race between shutdown() and run(). But if run()
+ // were synchronized, then shutdown() could be held up waiting on network
+ // i/o, including invocations on a server that no longer is accessible.
+ // So only minimal synchronization is imposed on run(), enough to avoid
+ // NullPointerExceptions.
+
running = false;
invoker = null;
listenerIdToInvokerLocatorMap = null;
@@ -825,7 +821,7 @@
cancel();
}
- public synchronized void run()
+ public void run()
{
if (!running)
return;
@@ -834,70 +830,63 @@
log.trace("checking connections");
Collection controlConnectionThreads = null;
- synchronized (controlConnectionThreadMap)
- {
- controlConnectionThreads = new HashSet(controlConnectionThreadMap.values());
- }
-
- if (controlConnectionThreads.isEmpty())
+ synchronized (this)
{
- shutdown();
+ if (!running)
return;
+
+ controlConnectionThreads = new HashSet(controlConnectionThreadMap.values());
}
Iterator it = controlConnectionThreads.iterator();
while (it.hasNext())
{
final ControlConnectionThread t = (ControlConnectionThread) it.next();
+ final String listenerId = t.getListenerId();
+ final Object locator;
+
+ synchronized (this)
+ {
+ if (!running)
+ return;
+
+ locator = listenerIdToInvokerLocatorMap.get(listenerId);
+ }
+
if (!t.checkConnection())
{
log.warn(this + ": detected failure on control connection " + t + ": requesting new control connection");
t.shutdown();
- synchronized (controlConnectionThreadMap)
+ synchronized (this)
{
- controlConnectionThreadMap.remove(t.getListenerId());
+ if (!running)
+ return;
+
+ controlConnectionThreadMap.remove(listenerId);
}
Thread t2 = new Thread()
{
public void run()
{
- synchronized (ControlMonitorTimerTask.this)
- {
if (!running)
return;
try
{
- invoker.createControlConnection(t.getListenerId(), null);
+ invoker.createControlConnection(listenerId, null);
}
catch (ClientUnavailableException e)
{
- if (running)
- {
- Object locator = listenerIdToInvokerLocatorMap.get(t.getListenerId());
- log.warn("Unable to recreate control connection: " + locator);
- }
- else
- {
- Object locator = listenerIdToInvokerLocatorMap.get(t.getListenerId());
- log.debug("Unable to recreate control connection: " + locator);
- }
+ log.debug("Unable to recreate control connection: " + locator, e);
}
catch (IOException e)
{
if (running)
- {
- Object locator = listenerIdToInvokerLocatorMap.get(t.getListenerId());
log.error("Unable to recreate control connection: " + locator, e);
- }
else
- {
- Object locator = listenerIdToInvokerLocatorMap.get(t.getListenerId());
- log.debug("Unable to recreate control connection: " + locator);
- }
- }
+ log.debug("Unable to recreate control connection: " + locator, e);
}
}
};
@@ -911,5 +900,6 @@
static class ClientUnavailableException extends IOException
{
+ private static final long serialVersionUID = 2846502029152028732L;
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list