Author: toad
Date: 2007-06-01 09:32:10 +0000 (Fri, 01 Jun 2007)
New Revision: 13431

Modified:
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
   trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
Log:
Improve filter/USM changes.

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
09:16:34 UTC (rev 13430)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
09:32:10 UTC (rev 13431)
@@ -204,14 +204,17 @@
         _or = null;
     }

-    public boolean matchesDroppedConnection() {
-        return _matchesDroppedConnections;
+    public boolean matchesDroppedConnection(PeerContext ctx) {
+        return _matchesDroppedConnections && _source == ctx;
     }

-    public void onDroppedConnection(PeerContext ctx) {
-        if(_matchesDroppedConnections && (_source == ctx)) {
-            _droppedConnection = ctx;
-        }
+    /**
+     * Notify because of a dropped connection.
+     * Caller must verify _matchesDroppedConnection and _source.
+     * @param ctx
+     */
+    public synchronized void onDroppedConnection(PeerContext ctx) {
+               notifyAll();
     }

     /**

Modified: trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2007-06-01 
09:16:34 UTC (rev 13430)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2007-06-01 
09:32:10 UTC (rev 13431)
@@ -325,9 +325,6 @@
                        MessageFilter f = (MessageFilter) 
_timedOutFilters.get(i);
                        f.setMessage(null);
                        f.onTimedOut();
-                       synchronized (f) {
-                               f.notifyAll();
-                       }
                }
                _timedOutFilters.clear();

@@ -454,20 +451,25 @@

        /** IncomingPacketFilter should call this when a node is disconnected. 
*/
        public void onDisconnect(PeerContext ctx) {
+               Vector droppedFilters = null; // rare operation, we can waste 
objects for better locking
            synchronized(_filters) {
                        ListIterator i = _filters.listIterator();
                        while (i.hasNext()) {
                            MessageFilter f = (MessageFilter) i.next();
-                           if(f.matchesDroppedConnection() && (f._source == 
ctx)) {
-                               f.onDroppedConnection(ctx);
-                               if(f.droppedConnection() != null) {
-                                   synchronized(f) {
-                                       f.notifyAll();
-                                   }
-                               }
+                           if(f.matchesDroppedConnection(ctx)) {
+                               if(droppedFilters == null)
+                                       droppedFilters = new Vector();
+                               droppedFilters.add(f);
+                               i.remove();
                            }
                        }
            }
+           if(droppedFilters != null) {
+               for(int i=0;i<droppedFilters.size();i++) {
+                       MessageFilter mf = (MessageFilter) 
droppedFilters.get(i);
+                       mf.onDroppedConnection(ctx);
+               }
+           }
        }


@@ -477,7 +479,7 @@
                if(logDEBUG) Logger.debug(this, "Adding async filter "+filter+" 
for "+callback);
                Message ret = null;
                if((lowLevelFilter != null) && (filter._source != null) && 
-                       filter.matchesDroppedConnection() &&
+                       filter.matchesDroppedConnection(filter._source) &&
                        lowLevelFilter.isDisconnected(filter._source))
                    throw new DisconnectedException();
                // Check to see whether the filter matches any of the recently 
_unclaimed messages
@@ -544,7 +546,7 @@
                long startTime = System.currentTimeMillis();
                Message ret = null;
                if((lowLevelFilter != null) && (filter._source != null) && 
-                       filter.matchesDroppedConnection() &&
+                       filter.matchesDroppedConnection(filter._source) &&
                        lowLevelFilter.isDisconnected(filter._source))
                    throw new DisconnectedException();
                // Check to see whether the filter matches any of the recently 
_unclaimed messages


Reply via email to