mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 08:55:22 -04:00
Add more logging, don't throw exception at timers
This commit is contained in:
parent
d506a1acfc
commit
8b1c0e5e6f
9 changed files with 97 additions and 87 deletions
|
@ -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,7 +17,7 @@ public class DefaultJavaTimer implements Timer {
|
|||
|
||||
@Override
|
||||
public Timer runLater(Duration delay, Runnable runnable) {
|
||||
checkArgument(timer == null, "runLater or runPeriodically already called on that timer");
|
||||
if (timer != null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
|
@ -34,12 +31,15 @@ public class DefaultJavaTimer implements Timer {
|
|||
}
|
||||
}
|
||||
}, 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");
|
||||
if (timer != null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
|
@ -53,13 +53,17 @@ public class DefaultJavaTimer implements Timer {
|
|||
}
|
||||
}
|
||||
}, 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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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,8 +81,7 @@ 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");
|
||||
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>() {
|
||||
|
@ -118,6 +116,9 @@ class PeerExchangeHandler implements MessageListener {
|
|||
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…
Add table
Add a link
Reference in a new issue