Attempt to disconnect on thread interrupt

This commit is contained in:
Christian Basler 2015-10-29 12:34:29 +01:00
parent 9c2d8589bf
commit c9c0806e0d
3 changed files with 8 additions and 1 deletions

View File

@ -206,7 +206,8 @@ public class BitmessageContext {
try { try {
t.join(); t.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e); LOG.info("Thread was interrupted. Trying to shut down synchronization and returning.");
t.interrupt();
} }
} }
} }

View File

@ -29,6 +29,9 @@ import java.net.InetAddress;
public interface NetworkHandler { public interface NetworkHandler {
/** /**
* Connects to the trusted host, fetches and offers new messages and disconnects afterwards. * Connects to the trusted host, fetches and offers new messages and disconnects afterwards.
* <p>
* An implementation should disconnect if either the timeout is reached or the returned thread is interrupted.
* </p>
*/ */
Thread synchronize(InetAddress trustedHost, int port, MessageListener listener, long timeoutInSeconds); Thread synchronize(InetAddress trustedHost, int port, MessageListener listener, long timeoutInSeconds);

View File

@ -130,6 +130,9 @@ public class Connection {
@SuppressWarnings("RedundantIfStatement") @SuppressWarnings("RedundantIfStatement")
private boolean syncFinished(NetworkMessage msg) { private boolean syncFinished(NetworkMessage msg) {
if (Thread.interrupted()) {
return true;
}
if (syncTimeout == 0 || state != ACTIVE) { if (syncTimeout == 0 || state != ACTIVE) {
return false; return false;
} }