incease fee as testnet is spammed with tx with high fees. use FxTimer in fx classes (gui). Use scheduledExecutor instead of timer

This commit is contained in:
Manfred Karrer 2016-01-01 19:34:00 +01:00
parent 8716a506e8
commit e456883f9b
19 changed files with 176 additions and 175 deletions

View file

@ -2,9 +2,11 @@ package io.bitsquare.p2p.peers;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import io.bitsquare.app.Log;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.network.Connection;
@ -17,7 +19,11 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
@ -26,12 +32,11 @@ public class MaintenanceManager implements MessageListener {
private static final Logger log = LoggerFactory.getLogger(MaintenanceManager.class);
private static final int INACTIVITY_PERIOD_BEFORE_PING = 5 * 60 * 1000;
private final NetworkNode networkNode;
private final Supplier<Map<Address, Peer>> authenticatedPeersSupplier;
private final Consumer<Address> removePeerConsumer;
private Timer sendPingTimer;
private final ScheduledThreadPoolExecutor executor;
///////////////////////////////////////////////////////////////////////////////////////////
@ -46,15 +51,19 @@ public class MaintenanceManager implements MessageListener {
this.removePeerConsumer = removePeerConsumer;
networkNode.addMessageListener(this);
startMaintenanceTimer();
executor = Utilities.getScheduledThreadPoolExecutor("MaintenanceManager", 1, 10, 5);
executor.schedule(() -> {
UserThread.execute(() -> pingPeers());
return null;
}, 5, TimeUnit.MINUTES);
}
public void shutDown() {
Log.traceCall();
if (sendPingTimer != null)
sendPingTimer.cancel();
networkNode.removeMessageListener(this);
MoreExecutors.shutdownAndAwaitTermination(executor, 500, TimeUnit.MILLISECONDS);
}
@ -94,24 +103,13 @@ public class MaintenanceManager implements MessageListener {
}
}
private void startMaintenanceTimer() {
Log.traceCall();
if (sendPingTimer != null)
sendPingTimer.cancel();
sendPingTimer = UserThread.runAfterRandomDelay(() -> {
pingPeers();
startMaintenanceTimer();
}, 5, 7, TimeUnit.MINUTES);
}
private void pingPeers() {
Set<Peer> connectedPeersList = new HashSet<>(authenticatedPeersSupplier.get().values());
if (!connectedPeersList.isEmpty()) {
Log.traceCall();
connectedPeersList.stream()
.filter(e -> (new Date().getTime() - e.connection.getLastActivityDate().getTime()) > INACTIVITY_PERIOD_BEFORE_PING)
.forEach(e -> UserThread.runAfterRandomDelay(() -> {
.forEach(e -> {
SettableFuture<Connection> future = networkNode.sendMessage(e.connection, new PingMessage(e.pingNonce));
Futures.addCallback(future, new FutureCallback<Connection>() {
@Override
@ -125,7 +123,7 @@ public class MaintenanceManager implements MessageListener {
removePeerConsumer.accept(e.address);
}
});
}, 2, 4, TimeUnit.SECONDS));
});
}
}
}