Author: toad
Date: 2008-01-25 14:50:26 +0000 (Fri, 25 Jan 2008)
New Revision: 17272

Modified:
   trunk/freenet/src/freenet/io/comm/AsyncMessageFilterCallback.java
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
   trunk/freenet/src/freenet/io/comm/NullAsyncMessageFilterCallback.java
   trunk/freenet/src/freenet/io/xfer/BlockReceiver.java
   trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
   trunk/freenet/src/freenet/node/CHKInsertSender.java
Log:
Complete the AsyncMessageFilterCallback API by adding:
onDisconnect(PeerContext)
onRestarted(PeerContext)
CHKInsertSender needs this to avoid waiting forever.

Modified: trunk/freenet/src/freenet/io/comm/AsyncMessageFilterCallback.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/AsyncMessageFilterCallback.java   
2008-01-25 14:40:48 UTC (rev 17271)
+++ trunk/freenet/src/freenet/io/comm/AsyncMessageFilterCallback.java   
2008-01-25 14:50:26 UTC (rev 17272)
@@ -28,4 +28,16 @@
         * Called when the filter times out and is removed from the list of 
filters to match.
         */
        void onTimeout();
+
+       /**
+        * Called when the filter is dropped because a connection is dropped.
+        * @param ctx
+        */
+       void onDisconnect(PeerContext ctx);
+
+       /**
+        * Called when the filter is dropped because a connection is restarted.
+        * @param ctx
+        */
+       void onRestarted(PeerContext ctx);
 }

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-01-25 
14:40:48 UTC (rev 17271)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2008-01-25 
14:50:26 UTC (rev 17272)
@@ -253,9 +253,13 @@
      * Caller must verify _matchesDroppedConnection and _source.
      * @param ctx
      */
-    public synchronized void onDroppedConnection(PeerContext ctx) {
-       _droppedConnection = ctx;
-               notifyAll();
+    public void onDroppedConnection(PeerContext ctx) {
+       synchronized(this) {
+               _droppedConnection = ctx;
+               notifyAll();
+       }
+       if(_callback != null)
+               _callback.onDisconnect(ctx);
     }

     /**
@@ -263,9 +267,13 @@
      * Caller must verify _matchesDroppedConnection and _source.
      * @param ctx
      */
-    public synchronized void onRestartedConnection(PeerContext ctx) {
-       _droppedConnection = ctx;
-               notifyAll();
+    public void onRestartedConnection(PeerContext ctx) {
+       synchronized(this) {
+               _droppedConnection = ctx;
+               notifyAll();
+       }
+       if(_callback != null)
+               _callback.onRestarted(ctx);
     }

     /**

Modified: trunk/freenet/src/freenet/io/comm/NullAsyncMessageFilterCallback.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/NullAsyncMessageFilterCallback.java       
2008-01-25 14:40:48 UTC (rev 17271)
+++ trunk/freenet/src/freenet/io/comm/NullAsyncMessageFilterCallback.java       
2008-01-25 14:50:26 UTC (rev 17272)
@@ -16,4 +16,12 @@
                // Do nothing
        }

+       public void onDisconnect(PeerContext ctx) {
+               // Do nothing
+       }
+
+       public void onRestarted(PeerContext ctx) {
+               // Do nothing
+       }
+
 }

Modified: trunk/freenet/src/freenet/io/xfer/BlockReceiver.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BlockReceiver.java        2008-01-25 
14:40:48 UTC (rev 17271)
+++ trunk/freenet/src/freenet/io/xfer/BlockReceiver.java        2008-01-25 
14:50:26 UTC (rev 17272)
@@ -208,5 +208,13 @@
        public void onTimeout() {
                //ignore
        }
+
+       public void onDisconnect(PeerContext ctx) {
+               // Ignore
+       }
+
+       public void onRestarted(PeerContext ctx) {
+               // Ignore
+       }

 }

Modified: trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java      2008-01-25 
14:40:48 UTC (rev 17271)
+++ trunk/freenet/src/freenet/io/xfer/BulkTransmitter.java      2008-01-25 
14:50:26 UTC (rev 17272)
@@ -89,6 +89,12 @@
                                                public void onTimeout() {
                                                        // Ignore
                                                }
+                                               public void 
onDisconnect(PeerContext ctx) {
+                                                       // Ignore
+                                               }
+                                               public void 
onRestarted(PeerContext ctx) {
+                                                       // Ignore
+                                               }
                        });
                        
prb.usm.addAsyncFilter(MessageFilter.create().setNoTimeout().setSource(peer).setType(DMT.FNPBulkReceivedAll).setField(DMT.UID,
 uid),
                                        new AsyncMessageFilterCallback() {
@@ -106,6 +112,12 @@
                                                public void onTimeout() {
                                                        // Ignore
                                                }
+                                               public void 
onDisconnect(PeerContext ctx) {
+                                                       // Ignore
+                                               }
+                                               public void 
onRestarted(PeerContext ctx) {
+                                                       // Ignore
+                                               }
                        });
                } catch (DisconnectedException e) {
                        cancel();

Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2008-01-25 14:40:48 UTC 
(rev 17271)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2008-01-25 14:50:26 UTC 
(rev 17272)
@@ -13,6 +13,7 @@
 import freenet.io.comm.Message;
 import freenet.io.comm.MessageFilter;
 import freenet.io.comm.NotConnectedException;
+import freenet.io.comm.PeerContext;
 import freenet.io.xfer.AbortedException;
 import freenet.io.xfer.BlockTransmitter;
 import freenet.io.xfer.PartiallyReceivedBlock;
@@ -145,6 +146,16 @@
                        Logger.error(this, "Timed out waiting for a final ack 
from: "+pn+" on "+this);
                        receivedNotice(false);
                }
+
+               public void onDisconnect(PeerContext ctx) {
+                       Logger.error(this, "Disconnected "+ctx+" for "+this);
+                       receivedNotice(true); // as far as we know
+               }
+
+               public void onRestarted(PeerContext ctx) {
+                       Logger.error(this, "Restarted "+ctx+" for "+this);
+                       receivedNotice(true);
+               }
        }

        CHKInsertSender(NodeCHK myKey, long uid, byte[] headers, short htl, 


Reply via email to