mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 17:05:29 -04:00
Update guava, cleanup threading
This commit is contained in:
parent
1a66d3cef5
commit
def492a22a
21 changed files with 423 additions and 361 deletions
|
@ -121,7 +121,10 @@ public class WalletService {
|
|||
|
||||
Timer timeoutTimer = FxTimer.runLater(
|
||||
Duration.ofMillis(STARTUP_TIMEOUT),
|
||||
() -> exceptionHandler.handleException(new TimeoutException("Wallet did not initialize in " + STARTUP_TIMEOUT / 1000 + " seconds."))
|
||||
() -> {
|
||||
Thread.currentThread().setName("WalletService:StartupTimeout-" + new Random().nextInt(1000));
|
||||
exceptionHandler.handleException(new TimeoutException("Wallet did not initialize in " + STARTUP_TIMEOUT / 1000 + " seconds."));
|
||||
}
|
||||
);
|
||||
|
||||
// If seed is non-null it means we are restoring from backup.
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package io.bitsquare.crypto;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import org.bitcoinj.crypto.KeyCrypterScrypt;
|
||||
import org.bitcoinj.wallet.Protos;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
//TODO: Borrowed form BitcoinJ/Lighthouse. Remove Protos dependency, check complete code logic.
|
||||
public class ScryptUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(ScryptUtil.class);
|
||||
|
@ -30,13 +28,7 @@ public class ScryptUtil {
|
|||
}
|
||||
|
||||
public static void deriveKeyWithScrypt(KeyCrypterScrypt keyCrypterScrypt, String password, DeriveKeyResultHandler resultHandler) {
|
||||
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
||||
.setNameFormat("Routing-%d")
|
||||
.setDaemon(true)
|
||||
.build();
|
||||
|
||||
ExecutorService executorService = new ThreadPoolExecutor(5, 50, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(50), threadFactory);
|
||||
executorService.submit(() -> {
|
||||
Utilities.getThreadPoolExecutor("ScryptUtil:deriveKeyWithScrypt-%d", 1, 2, 5L).submit(() -> {
|
||||
try {
|
||||
log.info("Doing key derivation");
|
||||
long start = System.currentTimeMillis();
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
public class OpenOffer implements Tradable, Serializable {
|
||||
// That object is saved to disc. We need to take care of changes to not break deserialization.
|
||||
|
@ -102,6 +103,7 @@ public class OpenOffer implements Tradable, Serializable {
|
|||
timeoutTimer = FxTimer.runLater(
|
||||
Duration.ofMillis(TIMEOUT),
|
||||
() -> {
|
||||
Thread.currentThread().setName("OpenOffer:Timeout-" + new Random().nextInt(1000));
|
||||
log.debug("Timeout reached");
|
||||
if (state == State.RESERVED)
|
||||
setState(State.AVAILABLE);
|
||||
|
|
|
@ -50,8 +50,6 @@ import java.util.Optional;
|
|||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.google.inject.internal.util.$Preconditions.checkNotNull;
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
@ -70,7 +68,6 @@ public class OpenOfferManager {
|
|||
private final TradableList<OpenOffer> openOffers;
|
||||
private final Storage<TradableList<OpenOffer>> openOffersStorage;
|
||||
private boolean shutDownRequested;
|
||||
private ScheduledThreadPoolExecutor executor;
|
||||
private P2PServiceListener p2PServiceListener;
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
|
@ -181,7 +178,7 @@ public class OpenOfferManager {
|
|||
}
|
||||
|
||||
private void rePublishOffers() {
|
||||
log.trace("rePublishOffers");
|
||||
if (!openOffers.isEmpty()) log.trace("rePublishOffers");
|
||||
for (OpenOffer openOffer : openOffers) {
|
||||
offerBookService.addOffer(openOffer.getOffer(),
|
||||
() -> log.debug("Successful added offer to P2P network"),
|
||||
|
@ -196,14 +193,8 @@ public class OpenOfferManager {
|
|||
}
|
||||
|
||||
public void shutDown(Runnable completeHandler) {
|
||||
if (executor != null) {
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
|
||||
if (!shutDownRequested) {
|
||||
log.debug("shutDown");
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Random;
|
||||
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
||||
|
@ -144,6 +145,7 @@ public class OfferAvailabilityProtocol {
|
|||
stopTimeout();
|
||||
|
||||
timeoutTimer = FxTimer.runLater(Duration.ofMillis(TIMEOUT), () -> {
|
||||
Thread.currentThread().setName("OfferAvailabilityProtocol:Timeout-" + new Random().nextInt(1000));
|
||||
log.warn("Timeout reached");
|
||||
errorMessageHandler.handleErrorMessage("Timeout reached: Peer has not responded.");
|
||||
});
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.security.PublicKey;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
||||
|
@ -126,6 +127,7 @@ public abstract class TradeProtocol {
|
|||
stopTimeout();
|
||||
|
||||
timeoutTimer = FxTimer.runLater(Duration.ofMillis(TIMEOUT), () -> {
|
||||
Thread.currentThread().setName("TradeProtocol:Timeout-" + new Random().nextInt(1000));
|
||||
log.error("Timeout reached");
|
||||
trade.setErrorMessage("A timeout occurred.");
|
||||
cleanupTradable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue