Skip to content

Commit

Permalink
wallets: Remove dependency to Bisq 2 Threading Class
Browse files Browse the repository at this point in the history
We can't depend on Bisq 2's Threading class to be able to reuse the wallets library in Bisq 1.
  • Loading branch information
alvasw committed Sep 11, 2024
1 parent 65a3ea6 commit d221ad0
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package bisq.wallets.bitcoind.zmq;

import bisq.common.threading.ExecutorFactory;
import bisq.wallets.bitcoind.rpc.responses.BitcoindGetZmqNotificationsResponse;
import bisq.wallets.bitcoind.zmq.exceptions.CannotFindZmqAddressException;
import bisq.wallets.bitcoind.zmq.exceptions.CannotFindZmqTopicException;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.zeromq.SocketType;
Expand All @@ -33,6 +33,8 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.stream.Collectors;

@Slf4j
Expand All @@ -45,8 +47,8 @@ public class ZmqConnection implements AutoCloseable {
@Getter
private final ZmqListeners listeners;

private final ExecutorService executorService = ExecutorFactory
.newFixedThreadPool("wallet-zeromq-notification-thread-pool", 2);
private final ExecutorService executorService =
newFixedThreadPool("wallet-zeromq-notification-thread-pool", 2);

private ZContext context;

Expand Down Expand Up @@ -151,4 +153,12 @@ private boolean isSocketClosed(int errorCode) {
private boolean isZeroMqContextTerminated(int errorCode) {
return errorCode == ERROR_CODE_CONTEXT_TERMINATED;
}

public ExecutorService newFixedThreadPool(String name, int numThreads) {
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name + "-%d")
.setDaemon(true)
.build();
return Executors.newFixedThreadPool(numThreads, threadFactory);
}
}

0 comments on commit d221ad0

Please sign in to comment.