Author: ron.sigal(a)jboss.com
Date: 2008-03-28 02:32:29 -0400 (Fri, 28 Mar 2008)
New Revision: 3805
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java
Log:
JBREM-944: Eliminated race in connectionLost() and connectionTerminated().
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java 2008-03-28
06:31:04 UTC (rev 3804)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java 2008-03-28
06:32:29 UTC (rev 3805)
@@ -1,5 +1,7 @@
package org.jboss.remoting;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
@@ -13,7 +15,7 @@
*/
public class ConnectionNotifier
{
- private List listeners = new ArrayList();
+ private List listeners = Collections.synchronizedList(new ArrayList());
private static final Logger log = Logger.getLogger(ConnectionNotifier.class);
@@ -44,10 +46,14 @@
log.debug("Server connection lost to client (session id = " +
clientSessionId);
Client client = new Client(new InvokerLocator(locatorurl), requestPayload);
client.setSessionId(clientSessionId);
- ConnectionListener[] list = (ConnectionListener[])listeners.toArray(new
ConnectionListener[listeners.size()]);
- for(int x = 0; x < list.length; x++)
+
+ synchronized (listeners)
{
- list[x].handleConnectionException(null, client);
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ ((ConnectionListener) it.next()).handleConnectionException(null, client);
+ }
}
}
catch(Exception e)
@@ -67,11 +73,14 @@
Client client = new Client(new InvokerLocator(locatorURL), requestPayload);
client.setSessionId(clientSessionId);
ClientDisconnectedException ex = new ClientDisconnectedException();
-
- ConnectionListener[] list = (ConnectionListener[])listeners.toArray(new
ConnectionListener[listeners.size()]);
- for(int x = 0; x < list.length; x++)
+
+ synchronized (listeners)
{
- list[x].handleConnectionException(ex, client);
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ ((ConnectionListener) it.next()).handleConnectionException(ex, client);
+ }
}
}
catch(Exception e)
Show replies by date