PeerGroup: Locking fix in newly added method. A bit more logging.

This commit is contained in:
Mike Hearn
2015-01-10 00:51:00 +01:00
parent 11463e729f
commit 7970b52504

View File

@@ -884,6 +884,7 @@ public class PeerGroup implements TransactionBroadcaster {
torClient.stop();
}
vRunning = false;
log.info("Stopped.");
} catch (Throwable e) {
log.error("Exception when shutting down", e); // The executor swallows exceptions :(
}
@@ -897,6 +898,7 @@ public class PeerGroup implements TransactionBroadcaster {
public void stop() {
try {
stopAsync();
log.info("Awaiting PeerGroup shutdown ...");
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
@@ -1525,6 +1527,8 @@ public class PeerGroup implements TransactionBroadcaster {
* @return a future that will be triggered when the number of connected peers implementing protocolVersion or higher >= numPeers
*/
public ListenableFuture<List<Peer>> waitForPeersWithServiceMask(final int numPeers, final int mask) {
lock.lock();
try {
List<Peer> foundPeers = findPeersWithServiceMask(mask);
if (foundPeers.size() >= numPeers)
return Futures.immediateFuture(foundPeers);
@@ -1540,6 +1544,9 @@ public class PeerGroup implements TransactionBroadcaster {
}
});
return future;
} finally {
lock.unlock();
}
}
/**