PATCH, Demultiplexer

Andre Gebers <[email protected]> Fri, 21 May 2004 10:02:34 +0200
Newsgroups gmane.comp.java.openjms.devel
Message-ID <[email protected]>
Hello,

i sporadically get a java.util.ConcurrentModificationException on the 
client side when i shut down the openjms server. This is annoying 
because my ExceptionListener won't get called and this in turn prevents 
my failover to be triggered. I'm using openjms-0.7.6.1.

2004-05-19 12:12:53,473 [MultiplexConnection-XXX.XXX.XXX.XXX:36342] 
DEBUG org.exolab.core.mipc.Demultiplexer - Demultiplexer terminating on 
exception
java.io.EOFException
         at java.io.DataInputStream.readInt(DataInputStream.java:397)
         at 
org.exolab.core.mipc.MessageInputStream.receive(MessageInputStream.java:95)
         at org.exolab.core.mipc.Demultiplexer.run(Demultiplexer.java:153)
         at 
org.exolab.core.mipc.MultiplexConnection.run(MultiplexConnection.java:240)
2004-05-19 12:12:53,478 [MultiplexConnection-XXX.XXX.XXX.XXX:36342] 
DEBUG org.exolab.core.mipc.MultiplexConnection - MultiplexConnection 
terminating on exception
java.util.ConcurrentModificationException
         at java.util.Hashtable$Enumerator.next(Hashtable.java:976)
         at org.exolab.core.mipc.Demultiplexer.run(Demultiplexer.java:172)
         at 
org.exolab.core.mipc.MultiplexConnection.run(MultiplexConnection.java:240)


I had a look at org.exolab.core.mipc.Demultiplexer and after adding a 
bit of synchronisation it worked fine.

Regards
Andre Gebers

-- 
Software-Entwicklung

Tipp24 AG
Kleine Johannisstrasse 2-4
20457 Hamburg | Germany
phone +49 (0)40 32 55 33-37
fax   +49 (0)40 32 55 33-99

Tipp24.de - Lotto im Internet. Clever gemacht.
www.tipp24.de
Demultiplexer.patch (text/plain, 1.8 KB)
diff -ruN exolabcore/src/main/org/exolab/core/mipc/Demultiplexer.java exolabcore_patched/src/main/org/exolab/core/mipc/Demultiplexer.java
--- exolabcore/src/main/org/exolab/core/mipc/Demultiplexer.java	2004-01-20 01:49:39.000000000 +0100
+++ exolabcore_patched/src/main/org/exolab/core/mipc/Demultiplexer.java	2004-05-19 14:59:26.000000000 +0200
@@ -116,7 +116,7 @@
      * @param channel the name of the channel.
      * @param out messages received on the channel are sent here
      */
-    public void register(String channel, MessageOutput out) {
+    public synchronized void register(String channel, MessageOutput out) {
         _targets.put(channel, out);
     }
 
@@ -125,7 +125,7 @@
      *
      * @param channel the name of the channel
      */
-    public void deregister(String channel) {
+    public synchronized void deregister(String channel) {
         _targets.remove(channel);
     }
 
@@ -167,13 +167,15 @@
                            exception);
             }
         } finally {
-            Iterator iterator = _targets.values().iterator();
-            while (iterator.hasNext()) {
-                MessageOutput output = (MessageOutput) iterator.next();
-                try {
-                    output.close();
-                } catch (Exception exception) {
-                    _log.debug("Error closing channel", exception);
+            synchronized (this) {
+                Iterator iterator = _targets.values().iterator();
+                while (iterator.hasNext()) {
+                    MessageOutput output = (MessageOutput) iterator.next();
+                    try {
+                        output.close();
+                    } catch (Exception exception) {
+                        _log.debug("Error closing channel", exception);
+                    }
                 }
             }
             _owner.disconnected();