Synchronisation API - added option to wait for the synchronization to finish
This commit is contained in:
parent
f9ff22bebe
commit
ea1419eda1
@ -192,8 +192,22 @@ public class BitmessageContext {
|
|||||||
ctx.getNetworkHandler().stop();
|
ctx.getNetworkHandler().stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void synchronize(InetAddress host, int port, long timeoutInSeconds) {
|
/**
|
||||||
ctx.getNetworkHandler().synchronize(host, port, networkListener, timeoutInSeconds);
|
* @param host a trusted node that must be reliable (it's used for every synchronization)
|
||||||
|
* @param port of the trusted host, default is 8444
|
||||||
|
* @param timeoutInSeconds synchronization should end no later than about 5 seconds after the timeout elapsed, even
|
||||||
|
* if not all objects were fetched
|
||||||
|
* @param wait waits for the synchronization thread to finish
|
||||||
|
*/
|
||||||
|
public void synchronize(InetAddress host, int port, long timeoutInSeconds, boolean wait) {
|
||||||
|
Thread t = ctx.getNetworkHandler().synchronize(host, port, networkListener, timeoutInSeconds);
|
||||||
|
if (wait) {
|
||||||
|
try {
|
||||||
|
t.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
|
@ -204,6 +204,7 @@ public class Connection implements Runnable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (syncTimeout < UnixTime.now()) {
|
if (syncTimeout < UnixTime.now()) {
|
||||||
|
LOG.info("Synchronization timed out");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
@ -213,6 +214,7 @@ public class Connection implements Runnable {
|
|||||||
readTimeoutCounter = 0;
|
readTimeoutCounter = 0;
|
||||||
if (!(msg.getPayload() instanceof Addr) && !(msg.getPayload() instanceof GetData)
|
if (!(msg.getPayload() instanceof Addr) && !(msg.getPayload() instanceof GetData)
|
||||||
&& requestedObjects.isEmpty() && sendingQueue.isEmpty()) {
|
&& requestedObjects.isEmpty() && sendingQueue.isEmpty()) {
|
||||||
|
LOG.info("Synchronisation completed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user