fix wrong timer behaviour

This commit is contained in:
Manfred Karrer 2016-01-14 11:40:06 +01:00
parent 7c3732c0e5
commit db128c6815
4 changed files with 14 additions and 10 deletions

View file

@ -135,8 +135,9 @@ public class ArbitratorManager {
} }
// re-publish periodically // re-publish periodically
republishArbitratorExecutor = Utilities.getScheduledThreadPoolExecutor("", 1, 5, 5); republishArbitratorExecutor = Utilities.getScheduledThreadPoolExecutor("republishArbitrator", 1, 5, 5);
republishArbitratorExecutor.schedule(() -> republishArbitrator(), Arbitrator.TTL / 2, TimeUnit.MILLISECONDS); long delay = Arbitrator.TTL / 2;
republishArbitratorExecutor.scheduleAtFixedRate(() -> republishArbitrator(), delay, delay, TimeUnit.MILLISECONDS);
} }
applyArbitrators(); applyArbitrators();

View file

@ -53,9 +53,9 @@ public class MaintenanceManager implements MessageListener {
networkNode.addMessageListener(this); networkNode.addMessageListener(this);
executor = Utilities.getScheduledThreadPoolExecutor("MaintenanceManager", 1, 10, 5); executor = Utilities.getScheduledThreadPoolExecutor("MaintenanceManager", 1, 10, 5);
executor.schedule(() -> { executor.scheduleAtFixedRate(() -> {
UserThread.execute(() -> pingPeers()); UserThread.execute(() -> pingPeers());
}, 5, TimeUnit.MINUTES); }, 5, 5, TimeUnit.MINUTES);
} }
public void shutDown() { public void shutDown() {

View file

@ -60,7 +60,7 @@ public class PeerExchangeManager implements MessageListener {
networkNode.addMessageListener(this); networkNode.addMessageListener(this);
executor = Utilities.getScheduledThreadPoolExecutor("PeerExchangeManager", 1, 10, 5); executor = Utilities.getScheduledThreadPoolExecutor("PeerExchangeManager", 1, 10, 5);
executor.schedule(() -> UserThread.execute(() -> trySendGetPeersRequest()), 4, TimeUnit.MINUTES); executor.scheduleAtFixedRate(() -> UserThread.execute(() -> trySendGetPeersRequest()), 4, 4, TimeUnit.MINUTES);
} }
public void shutDown() { public void shutDown() {

View file

@ -118,7 +118,7 @@ public class PeerManager implements MessageListener, ConnectionListener {
@Override @Override
public void onDisconnect(Reason reason, Connection connection) { public void onDisconnect(Reason reason, Connection connection) {
log.debug("onDisconnect connection=" + connection + " / reason=" + reason); log.debug("onDisconnect reason=" + reason + " / connection=" + connection);
connection.getPeerAddressOptional().ifPresent(peerAddress -> { connection.getPeerAddressOptional().ifPresent(peerAddress -> {
// We only remove the peer from the authenticationHandshakes and the reportedPeers // We only remove the peer from the authenticationHandshakes and the reportedPeers
@ -445,8 +445,8 @@ public class PeerManager implements MessageListener, ConnectionListener {
} }
protected void startCheckSeedNodeConnectionTask() { protected void startCheckSeedNodeConnectionTask() {
checkSeedNodeConnectionExecutor.schedule(() -> UserThread.execute(() checkSeedNodeConnectionExecutor.scheduleAtFixedRate(() -> UserThread.execute(()
-> checkSeedNodeConnections()), 2, TimeUnit.MINUTES); -> checkSeedNodeConnections()), 2, 2, TimeUnit.MINUTES);
} }
// We want to stay connected to at least one seed node to avoid to get isolated with a group of peers // We want to stay connected to at least one seed node to avoid to get isolated with a group of peers
@ -530,8 +530,8 @@ public class PeerManager implements MessageListener, ConnectionListener {
authenticateToRemainingSeedNode(); authenticateToRemainingSeedNode();
} else if (!persistedPeers.isEmpty()) { } else if (!persistedPeers.isEmpty()) {
log.info("We don't have seed nodes or reported peers available. " + log.info("We don't have seed nodes or reported peers available. " +
"We will add 5 peers from our persistedReportedPeers to our reportedPeers list and " + "We will try to add 5 peers from our persistedPeers to our reportedPeers list and " +
"try authenticateToRemainingReportedPeer again."); "try authenticateToRemainingReportedPeer again. All persistedPeers=" + persistedPeers);
List<ReportedPeer> list = new ArrayList<>(persistedPeers); List<ReportedPeer> list = new ArrayList<>(persistedPeers);
authenticationHandshakes.keySet().stream().forEach(e -> list.remove(new ReportedPeer(e))); authenticationHandshakes.keySet().stream().forEach(e -> list.remove(new ReportedPeer(e)));
@ -543,7 +543,10 @@ public class PeerManager implements MessageListener, ConnectionListener {
persistedPeers.remove(reportedPeer); persistedPeers.remove(reportedPeer);
reportedPeers.add(reportedPeer); reportedPeers.add(reportedPeer);
} }
log.info("We have added some of our persistedPeers to our reportedPeers. reportedPeers=" + reportedPeers);
authenticateToRemainingReportedPeer(); authenticateToRemainingReportedPeer();
} else {
log.info("We don't have any persistedPeers available which are not authenticating or authenticated.");
} }
} else { } else {
log.info("We don't have seed nodes, reported peers nor persistedReportedPeers available. " + log.info("We don't have seed nodes, reported peers nor persistedReportedPeers available. " +