Author: toad
Date: 2007-12-21 23:27:56 +0000 (Fri, 21 Dec 2007)
New Revision: 16767

Modified:
   trunk/freenet/src/freenet/node/CHKInsertSender.java
Log:
Factor out BackgroundTransfer.realRun() and properly handle the one exception 
thrown here.
try { ... } catch (Throwable e) { ... } is bad, we should always catch the 
declared exceptions *first*.

Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-12-21 23:25:41 UTC 
(rev 16766)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-12-21 23:27:56 UTC 
(rev 16767)
@@ -55,15 +55,7 @@
                public void run() {
                        freenet.support.Logger.OSThread.logPID(this);
                        try {
-                               this.completedTransfer(bt.send(node.executor));
-                               // Double-check that the node is still 
connected. Pointless to wait otherwise.
-                               if (pn.isConnected() && transferSucceeded) {
-                                       //synch-version: 
this.receivedNotice(waitForReceivedNotification(this));
-                                       //Add ourselves as a listener for the 
longterm completion message of this transfer, then gracefully exit.
-                                       
node.usm.addAsyncFilter(getNotificationMessageFilter(), this);
-                               } else {
-                                       this.receivedNotice(false);
-                               }
+                               this.realRun();
                        } catch (Throwable t) {
                                this.completedTransfer(false);
                                this.receivedNotice(false);
@@ -71,6 +63,26 @@
                        }
                }

+               private void realRun() {
+                       this.completedTransfer(bt.send(node.executor));
+                       // Double-check that the node is still connected. 
Pointless to wait otherwise.
+                       if (pn.isConnected() && transferSucceeded) {
+                               //synch-version: 
this.receivedNotice(waitForReceivedNotification(this));
+                               //Add ourselves as a listener for the longterm 
completion message of this transfer, then gracefully exit.
+                               try {
+                                       
node.usm.addAsyncFilter(getNotificationMessageFilter(), this);
+                               } catch (DisconnectedException e) {
+                                       // Normal
+                                       if(logMINOR)
+                                               Logger.minor(this, 
"Disconnected while adding filter");
+                                       this.completedTransfer(false);
+                                       this.receivedNotice(false);
+                               }
+                       } else {
+                               this.receivedNotice(false);
+                       }
+               }
+               
                private void completedTransfer(boolean success) {
                        synchronized(this) {
                                transferSucceeded = success;


Reply via email to