Author: toad
Date: 2008-11-28 15:53:08 +0000 (Fri, 28 Nov 2008)
New Revision: 23944
Modified:
trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
Log:
Refactor to share code between handleRequestExt and handleRequestMain
Modified: trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
2008-11-28 15:52:29 UTC (rev 23943)
+++ trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
2008-11-28 15:53:08 UTC (rev 23944)
@@ -938,14 +938,16 @@
updateManager.node.clientCore.alerts.unregister(alert);
}
- public boolean handleRequestExt(Message m, final PeerNode source) {
+ public boolean handleRequestJar(Message m, final PeerNode source,
boolean isExt) {
// Do we have the data?
- int version = updateManager.newExtJarVersion();
- File data = updateManager.getExtBlob(version);
+ int version = isExt ? updateManager.newExtJarVersion() :
updateManager.newMainJarVersion();
+ File data = isExt ? updateManager.getExtBlob(version) :
updateManager.getMainBlob(version);
+
+ final String name = isExt ? "ext" : "main";
if(data == null) {
- Logger.normal(this, "Peer " + source + " asked us for
the blob file for the ext jar but we don't have it!");
+ Logger.normal(this, "Peer " + source + " asked us for
the blob file for the "+name+" jar but we don't have it!");
// Probably a race condition on reconnect, hopefully
we'll be asked again
return true;
}
@@ -956,7 +958,7 @@
try {
raf = new RandomAccessFileWrapper(data, "r");
} catch(FileNotFoundException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the ext jar, we have downloaded it but don't have the file
even though we did have it when we checked!: " + e, e);
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the "+name+" jar, we have downloaded it but don't have the
file even though we did have it when we checked!: " + e, e);
return true;
}
@@ -967,7 +969,7 @@
prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
Node.PACKET_SIZE, raf, true);
} catch(IOException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the ext jar, we have downloaded it but we can't determine the
file size: " + e, e);
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the "+name+" jar, we have downloaded it but we can't
determine the file size: " + e, e);
return true;
}
@@ -975,7 +977,7 @@
try {
bt = new BulkTransmitter(prb, source, uid, false,
updateManager.ctr);
} catch(DisconnectedException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the ext jar, then disconnected: " + e, e);
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the "+name+" jar, then disconnected: " + e, e);
return true;
}
@@ -983,13 +985,15 @@
public void run() {
if(!bt.send())
- Logger.error(this, "Failed to send ext
jar blob to " + source.userToString() + " : " + bt.getCancelReason());
+ Logger.error(this, "Failed to send
"+name+" jar blob to " + source.userToString() + " : " + bt.getCancelReason());
else
- Logger.normal(this, "Sent ext jar blob
to " + source.userToString());
+ Logger.normal(this, "Sent "+name+" jar
blob to " + source.userToString());
}
};
- Message msg = DMT.createUOMSendingExtra(uid, length,
updateManager.updateURI.toString(), version);
+ Message msg =
+ isExt ? DMT.createUOMSendingExtra(uid, length,
updateManager.updateURI.toString(), version) :
+ DMT.createUOMSendingMain(uid, length,
updateManager.updateURI.toString(), version);
try {
source.sendAsync(msg, new AsyncMessageCallback() {
@@ -999,17 +1003,17 @@
Logger.minor(this, "Sending
data...");
// Send the data
- updateManager.node.executor.execute(r,
"Ext jar send for " + uid + " to " + source.userToString());
+ updateManager.node.executor.execute(r,
name+" jar send for " + uid + " to " + source.userToString());
}
public void disconnected() {
// Argh
- Logger.error(this, "Peer " + source + "
asked us for the blob file for the ext jar, then disconnected when we tried to
send the UOMSendingMain");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the "+name+" jar, then disconnected when we
tried to send the UOMSendingMain");
}
public void fatalError() {
// Argh
- Logger.error(this, "Peer " + source + "
asked us for the blob file for the ext jar, then got a fatal error when we
tried to send the UOMSendingMain");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the "+name+" jar, then got a fatal error when we
tried to send the UOMSendingMain");
}
public void sent() {
@@ -1023,104 +1027,21 @@
}
}, updateManager.ctr);
} catch(NotConnectedException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the ext jar, then disconnected when we tried to send the
UOMSendingExt: " + e, e);
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the "+name+" jar, then disconnected when we tried to send the
UOMSendingExt: " + e, e);
return true;
}
return true;
+
}
+ public boolean handleRequestExt(Message m, final PeerNode source) {
+ return handleRequestJar(m, source, true);
+ }
+
public boolean handleRequestMain(Message m, final PeerNode source) {
- // Do we have the data?
-
- int version = updateManager.newMainJarVersion();
- File data = updateManager.getMainBlob(version);
-
- if(data == null) {
- Logger.normal(this, "Peer " + source + " asked us for
the blob file for the main jar but we don't have it!");
- // Probably a race condition on reconnect, hopefully
we'll be asked again
- return true;
- }
-
- final long uid = m.getLong(DMT.UID);
-
- RandomAccessFileWrapper raf;
- try {
- raf = new RandomAccessFileWrapper(data, "r");
- } catch(FileNotFoundException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, we have downloaded it but don't have the file
even though we did have it when we checked!: " + e, e);
- return true;
- }
-
- final PartiallyReceivedBulk prb;
- long length;
- try {
- length = raf.size();
- prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
- Node.PACKET_SIZE, raf, true);
- } catch(IOException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, we have downloaded it but we can't determine
the file size: " + e, e);
- return true;
- }
-
- final BulkTransmitter bt;
- try {
- bt = new BulkTransmitter(prb, source, uid, false,
updateManager.ctr);
- } catch(DisconnectedException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, then disconnected: " + e, e);
- return true;
- }
-
- final Runnable r = new Runnable() {
-
- public void run() {
- if(!bt.send())
- Logger.error(this, "Failed to send main
jar blob to " + source.userToString() + " : " + bt.getCancelReason());
- else
- Logger.normal(this, "Sent main jar blob
to " + source.userToString());
- }
- };
-
- Message msg = DMT.createUOMSendingMain(uid, length,
updateManager.updateURI.toString(), version);
-
- try {
- source.sendAsync(msg, new AsyncMessageCallback() {
-
- public void acknowledged() {
- if(logMINOR)
- Logger.minor(this, "Sending
data...");
- // Send the data
-
- updateManager.node.executor.execute(r,
"Main jar send for " + uid + " to " + source.userToString());
- }
-
- public void disconnected() {
- // Argh
- Logger.error(this, "Peer " + source + "
asked us for the blob file for the main jar, then disconnected when we tried to
send the UOMSendingMain");
- }
-
- public void fatalError() {
- // Argh
- Logger.error(this, "Peer " + source + "
asked us for the blob file for the main jar, then got a fatal error when we
tried to send the UOMSendingMain");
- }
-
- public void sent() {
- if(logMINOR)
- Logger.minor(this, "Message
sent, data soon");
- }
-
- @Override
- public String toString() {
- return super.toString() + "(" + uid +
":" + source.getPeer() + ")";
- }
- }, updateManager.ctr);
- } catch(NotConnectedException e) {
- Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, then disconnected when we tried to send the
UOMSendingMain: " + e, e);
- return true;
- }
-
- return true;
+ return handleRequestJar(m, source, false);
}
public boolean handleSendingMain(Message m, final PeerNode source) {
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs