use of bisq.common.Timer in project bisq-desktop by bisq-network.
the class MainViewModel method startBasicServices.
private void startBasicServices() {
log.info("startBasicServices");
ChangeListener<Boolean> walletInitializedListener = (observable, oldValue, newValue) -> {
// TODO that seems to be called too often if Tor takes longer to start up...
if (newValue && !p2pNetWorkReady.get())
showTorNetworkSettingsWindow();
};
Timer startupTimeout = UserThread.runAfter(() -> {
log.warn("startupTimeout called");
if (walletsManager.areWalletsEncrypted())
walletInitialized.addListener(walletInitializedListener);
else
showTorNetworkSettingsWindow();
}, STARTUP_TIMEOUT_MINUTES, TimeUnit.MINUTES);
p2pNetWorkReady = initP2PNetwork();
// When using Tor, wallet init must be deferred until Tor is ready.
if (!preferences.getUseTorForBitcoinJ() || bisqEnvironment.isBitcoinLocalhostNodeRunning())
initWalletService();
// need to store it to not get garbage collected
allServicesDone = EasyBind.combine(walletInitialized, p2pNetWorkReady, (a, b) -> {
log.debug("\nwalletInitialized={}\n" + "p2pNetWorkReady={}", a, b);
return a && b;
});
allServicesDone.subscribe((observable, oldValue, newValue) -> {
if (newValue) {
startupTimeout.stop();
walletInitialized.removeListener(walletInitializedListener);
onBasicServicesInitialized();
if (torNetworkSettingsWindow != null)
torNetworkSettingsWindow.hide();
}
});
}
use of bisq.common.Timer in project bisq-desktop by bisq-network.
the class TraderDisputeView method onSendMessage.
private void onSendMessage(String inputText, Dispute dispute) {
if (disputeCommunicationMessage != null) {
disputeCommunicationMessage.arrivedProperty().removeListener(arrivedPropertyListener);
disputeCommunicationMessage.storedInMailboxProperty().removeListener(storedInMailboxPropertyListener);
}
disputeCommunicationMessage = disputeManager.sendDisputeDirectMessage(dispute, inputText, new ArrayList<>(tempAttachments));
tempAttachments.clear();
scrollToBottom();
inputTextArea.setDisable(true);
inputTextArea.clear();
Timer timer = UserThread.runAfter(() -> {
sendMsgInfoLabel.setVisible(true);
sendMsgInfoLabel.setManaged(true);
sendMsgInfoLabel.setText(Res.get("support.sendingMessage"));
sendMsgBusyAnimation.play();
}, 500, TimeUnit.MILLISECONDS);
arrivedPropertyListener = (observable, oldValue, newValue) -> {
if (newValue) {
hideSendMsgInfo(timer);
}
};
if (disputeCommunicationMessage != null && disputeCommunicationMessage.arrivedProperty() != null)
disputeCommunicationMessage.arrivedProperty().addListener(arrivedPropertyListener);
storedInMailboxPropertyListener = (observable, oldValue, newValue) -> {
if (newValue) {
sendMsgInfoLabel.setVisible(true);
sendMsgInfoLabel.setManaged(true);
sendMsgInfoLabel.setText(Res.get("support.receiverNotOnline"));
hideSendMsgInfo(timer);
}
};
if (disputeCommunicationMessage != null)
disputeCommunicationMessage.storedInMailboxProperty().addListener(storedInMailboxPropertyListener);
}
use of bisq.common.Timer in project bisq-core by bisq-network.
the class WalletsSetup method initialize.
// /////////////////////////////////////////////////////////////////////////////////////////
// Lifecycle
// /////////////////////////////////////////////////////////////////////////////////////////
public void initialize(@Nullable DeterministicSeed seed, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
Log.traceCall();
// Tell bitcoinj to execute event handlers on the JavaFX UI thread. This keeps things simple and means
// we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
// we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
// a future version.
Threading.USER_THREAD = UserThread.getExecutor();
Timer timeoutTimer = UserThread.runAfter(() -> exceptionHandler.handleException(new TimeoutException("Wallet did not initialize in " + STARTUP_TIMEOUT + " seconds.")), STARTUP_TIMEOUT);
backupWallets();
final Socks5Proxy socks5Proxy = preferences.getUseTorForBitcoinJ() ? socks5ProxyProvider.getSocks5Proxy() : null;
log.info("Socks5Proxy for bitcoinj: socks5Proxy=" + socks5Proxy);
walletConfig = new WalletConfig(params, socks5Proxy, walletDir, bisqEnvironment, userAgent, numConnectionForBtc, btcWalletFileName, BSQ_WALLET_FILE_NAME, SPV_CHAIN_FILE_NAME) {
@Override
protected void onSetupCompleted() {
// We are here in the btcj thread Thread[ STARTING,5,main]
super.onSetupCompleted();
final PeerGroup peerGroup = walletConfig.peerGroup();
// We don't want to get our node white list polluted with nodes from AddressMessage calls.
if (preferences.getBitcoinNodes() != null && !preferences.getBitcoinNodes().isEmpty())
peerGroup.setAddPeersFromAddressMessage(false);
peerGroup.addConnectedEventListener((peer, peerCount) -> {
// We get called here on our user thread
numPeers.set(peerCount);
connectedPeers.set(peerGroup.getConnectedPeers());
});
peerGroup.addDisconnectedEventListener((peer, peerCount) -> {
// We get called here on our user thread
numPeers.set(peerCount);
connectedPeers.set(peerGroup.getConnectedPeers());
});
// Map to user thread
UserThread.execute(() -> {
addressEntryList.onWalletReady(walletConfig.getBtcWallet());
timeoutTimer.stop();
setupCompletedHandlers.stream().forEach(Runnable::run);
});
// onSetupCompleted in walletAppKit is not the called on the last invocations, so we add a bit of delay
UserThread.runAfter(resultHandler::handleResult, 100, TimeUnit.MILLISECONDS);
}
};
if (params == RegTestParams.get()) {
walletConfig.setMinBroadcastConnections(1);
if (regTestHost == RegTestHost.LOCALHOST) {
walletConfig.setPeerNodesForLocalHost();
} else if (regTestHost == RegTestHost.REG_TEST_SERVER) {
walletConfig.setMinBroadcastConnections(1);
configPeerNodesForRegTestServer();
} else {
configPeerNodes(socks5Proxy);
}
} else if (bisqEnvironment.isBitcoinLocalhostNodeRunning()) {
walletConfig.setMinBroadcastConnections(1);
walletConfig.setPeerNodesForLocalHost();
} else {
configPeerNodes(socks5Proxy);
}
walletConfig.setDownloadListener(downloadListener).setBlockingStartup(false);
// If seed is non-null it means we are restoring from backup.
walletConfig.setSeed(seed);
walletConfig.addListener(new Service.Listener() {
@Override
public void failed(@NotNull Service.State from, @NotNull Throwable failure) {
walletConfig = null;
log.error("Service failure from state: {}; failure={}", from, failure);
timeoutTimer.stop();
UserThread.execute(() -> exceptionHandler.handleException(failure));
}
}, Threading.USER_THREAD);
walletConfig.startAsync();
}
Aggregations