mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-22 08:29:16 -04:00
Add more logging, don't throw exception at timers
This commit is contained in:
parent
d506a1acfc
commit
8b1c0e5e6f
@ -7,9 +7,6 @@ import java.time.Duration;
|
||||
import java.util.Random;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class DefaultJavaTimer implements Timer {
|
||||
private final Logger log = LoggerFactory.getLogger(DefaultJavaTimer.class);
|
||||
private java.util.Timer timer;
|
||||
@ -20,46 +17,53 @@ public class DefaultJavaTimer implements Timer {
|
||||
|
||||
@Override
|
||||
public Timer runLater(Duration delay, Runnable runnable) {
|
||||
checkArgument(timer == null, "runLater or runPeriodically already called on that timer");
|
||||
timer = new java.util.Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
if (timer != null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, delay.toMillis());
|
||||
}, delay.toMillis());
|
||||
} else {
|
||||
log.warn("runLater called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer runPeriodically(java.time.Duration interval, Runnable runnable) {
|
||||
checkArgument(timer == null, "runLater or runPeriodically already called on that timer");
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
if (timer != null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, interval.toMillis(), interval.toMillis());
|
||||
}, interval.toMillis(), interval.toMillis());
|
||||
} else {
|
||||
log.warn("runLater called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
checkNotNull(timer, "Timer must not be null");
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +61,6 @@ import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
public class OpenOfferManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenOfferManager.class);
|
||||
|
||||
private static final int MAX_MSG_SIZE = 100 * 1024;
|
||||
|
||||
private final KeyRing keyRing;
|
||||
private final User user;
|
||||
private final P2PService p2PService;
|
||||
@ -205,6 +203,7 @@ public class OpenOfferManager {
|
||||
|
||||
//republishOffers();
|
||||
// run again after 5 sec as it might be that the app needs a bit for getting all re-animated again
|
||||
log.error("We got re-connected again after loss of all connection. We re-publish our offers now.");
|
||||
republishOffersTimer = UserThread.runAfter(OpenOfferManager.this::republishOffers, 5);
|
||||
}
|
||||
}
|
||||
@ -212,8 +211,10 @@ public class OpenOfferManager {
|
||||
@Override
|
||||
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
||||
lostAllConnections = networkNode.getAllConnections().isEmpty();
|
||||
if (lostAllConnections)
|
||||
if (lostAllConnections) {
|
||||
allowRefreshOffers = false;
|
||||
log.error("We got disconnected from all peers");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,9 +7,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class UITimer implements Timer {
|
||||
private final Logger log = LoggerFactory.getLogger(UITimer.class);
|
||||
private org.reactfx.util.Timer timer;
|
||||
@ -19,24 +16,31 @@ public class UITimer implements Timer {
|
||||
|
||||
@Override
|
||||
public Timer runLater(Duration delay, Runnable runnable) {
|
||||
checkArgument(timer == null, "runLater or runPeriodically already called on that timer");
|
||||
timer = FxTimer.create(delay, runnable);
|
||||
timer.restart();
|
||||
if (timer != null) {
|
||||
timer = FxTimer.create(delay, runnable);
|
||||
timer.restart();
|
||||
} else {
|
||||
log.warn("runLater called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer runPeriodically(Duration interval, Runnable runnable) {
|
||||
checkArgument(timer == null, "runLater or runPeriodically already called on that timer");
|
||||
timer = FxTimer.createPeriodic(interval, runnable);
|
||||
timer.restart();
|
||||
if (timer != null) {
|
||||
timer = FxTimer.createPeriodic(interval, runnable);
|
||||
timer.restart();
|
||||
} else {
|
||||
log.warn("runPeriodically called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
checkNotNull(timer, "Timer must not be null");
|
||||
timer.stop();
|
||||
timer = null;
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ public class OfferBook {
|
||||
offerBookService.addOfferBookChangedListener(new OfferBookService.OfferBookChangedListener() {
|
||||
@Override
|
||||
public void onAdded(Offer offer) {
|
||||
log.debug("onAdded " + offer);
|
||||
OfferBookListItem offerBookListItem = new OfferBookListItem(offer);
|
||||
if (!offerBookListItems.contains(offerBookListItem))
|
||||
offerBookListItems.add(offerBookListItem);
|
||||
@ -62,7 +61,6 @@ public class OfferBook {
|
||||
|
||||
@Override
|
||||
public void onRemoved(Offer offer) {
|
||||
log.debug("onRemoved " + offer);
|
||||
// Update state in case that that offer is used in the take offer screen, so it gets updated correctly
|
||||
offer.setState(Offer.State.REMOVED);
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class Connection implements MessageListener {
|
||||
private static final int MSG_THROTTLE_PER_10SEC = 50; // With MAX_MSG_SIZE of 100kb results in bandwidth of 5 mbit/sec for 10 sec
|
||||
// private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
|
||||
//TODO
|
||||
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
|
||||
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
public static int getMaxMsgSize() {
|
||||
return MAX_MSG_SIZE;
|
||||
|
@ -46,7 +46,7 @@ public class PeerManager implements ConnectionListener, MessageListener {
|
||||
}
|
||||
|
||||
static {
|
||||
setMaxConnections(12);
|
||||
setMaxConnections(1);
|
||||
}
|
||||
|
||||
private static final int MAX_REPORTED_PEERS = 1000;
|
||||
|
@ -120,7 +120,7 @@ public class RequestDataHandshake implements MessageListener {
|
||||
shutDown();
|
||||
listener.onFault(errorMessage, null);
|
||||
},
|
||||
10, TimeUnit.SECONDS);
|
||||
10);
|
||||
}
|
||||
|
||||
public void onDataRequest(Message message, final Connection connection) {
|
||||
|
@ -24,7 +24,6 @@ import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class PeerExchangeHandler implements MessageListener {
|
||||
private static final Logger log = LoggerFactory.getLogger(PeerExchangeHandler.class);
|
||||
@ -82,42 +81,44 @@ class PeerExchangeHandler implements MessageListener {
|
||||
|
||||
public void sendGetPeersRequest(NodeAddress nodeAddress) {
|
||||
Log.traceCall("nodeAddress=" + nodeAddress + " / this=" + this);
|
||||
checkNotNull(networkNode.getNodeAddress(), "PeerExchangeHandler.requestReportedPeers: My node address must " +
|
||||
"not be null at requestReportedPeers");
|
||||
GetPeersRequest getPeersRequest = new GetPeersRequest(networkNode.getNodeAddress(), nonce, peerManager.getConnectedPeersNonSeedNodes(nodeAddress));
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getPeersRequest);
|
||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||
@Override
|
||||
public void onSuccess(Connection connection) {
|
||||
if (!connection.getPeersNodeAddressOptional().isPresent()) {
|
||||
connection.setPeersNodeAddress(nodeAddress);
|
||||
//TODO remove setPeersNodeAddress if never needed
|
||||
log.warn("sendGetPeersRequest: !connection.getPeersNodeAddressOptional().isPresent()");
|
||||
if (networkNode.getNodeAddress() != null) {
|
||||
GetPeersRequest getPeersRequest = new GetPeersRequest(networkNode.getNodeAddress(), nonce, peerManager.getConnectedPeersNonSeedNodes(nodeAddress));
|
||||
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getPeersRequest);
|
||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||
@Override
|
||||
public void onSuccess(Connection connection) {
|
||||
if (!connection.getPeersNodeAddressOptional().isPresent()) {
|
||||
connection.setPeersNodeAddress(nodeAddress);
|
||||
//TODO remove setPeersNodeAddress if never needed
|
||||
log.warn("sendGetPeersRequest: !connection.getPeersNodeAddressOptional().isPresent()");
|
||||
}
|
||||
PeerExchangeHandler.this.connection = connection;
|
||||
connection.addMessageListener(PeerExchangeHandler.this);
|
||||
log.trace("Send " + getPeersRequest + " to " + nodeAddress + " succeeded.");
|
||||
}
|
||||
PeerExchangeHandler.this.connection = connection;
|
||||
connection.addMessageListener(PeerExchangeHandler.this);
|
||||
log.trace("Send " + getPeersRequest + " to " + nodeAddress + " succeeded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
String errorMessage = "Sending getPeersRequest to " + nodeAddress +
|
||||
" failed. That is expected if the peer is offline.\n\tgetPeersRequest=" + getPeersRequest +
|
||||
".\n\tException=" + throwable.getMessage();
|
||||
log.info(errorMessage);
|
||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable throwable) {
|
||||
String errorMessage = "Sending getPeersRequest to " + nodeAddress +
|
||||
" failed. That is expected if the peer is offline.\n\tgetPeersRequest=" + getPeersRequest +
|
||||
".\n\tException=" + throwable.getMessage();
|
||||
log.info(errorMessage);
|
||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress);
|
||||
}
|
||||
});
|
||||
|
||||
checkArgument(timeoutTimer == null, "requestReportedPeers must not be called twice.");
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
String errorMessage = "A timeout occurred at sending getPeersRequest:" + getPeersRequest + " for nodeAddress:" + nodeAddress;
|
||||
log.info(errorMessage + " / PeerExchangeHandler=" +
|
||||
PeerExchangeHandler.this);
|
||||
log.info("timeoutTimer called on " + this);
|
||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, nodeAddress);
|
||||
},
|
||||
TIME_OUT_SEC, TimeUnit.SECONDS);
|
||||
checkArgument(timeoutTimer == null, "requestReportedPeers must not be called twice.");
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
String errorMessage = "A timeout occurred at sending getPeersRequest:" + getPeersRequest + " for nodeAddress:" + nodeAddress;
|
||||
log.info(errorMessage + " / PeerExchangeHandler=" +
|
||||
PeerExchangeHandler.this);
|
||||
log.info("timeoutTimer called on " + this);
|
||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, nodeAddress);
|
||||
},
|
||||
TIME_OUT_SEC, TimeUnit.SECONDS);
|
||||
} else {
|
||||
log.trace("My node address is still null at sendGetPeersRequest. We ignore that call.");
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -82,7 +82,9 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
|
||||
.filter(entry -> entry.getValue().isExpired())
|
||||
.forEach(entry -> {
|
||||
ByteArray hashOfPayload = entry.getKey();
|
||||
toRemoveSet.add(map.get(hashOfPayload));
|
||||
ProtectedData protectedData = map.get(hashOfPayload);
|
||||
toRemoveSet.add(protectedData);
|
||||
log.trace("remove protectedData:\n\t" + protectedData);
|
||||
map.remove(hashOfPayload);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user