bitcoinj 0.15: Futures.addCallback() in guava 28 requires an executor.

This commit is contained in:
Oscar Guindzberg 2019-04-16 16:13:49 -03:00
parent 9f767377e8
commit 423ffa84e1
No known key found for this signature in database
GPG Key ID: 209796BF2E1D4F75
29 changed files with 63 additions and 36 deletions

View File

@ -49,6 +49,7 @@ import javax.inject.Inject;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import org.spongycastle.crypto.params.KeyParameter;
@ -864,7 +865,7 @@ public class BtcWalletService extends WalletService {
log.error("Broadcasting double spending transaction failed. " + t.getMessage());
errorMessageHandler.handleErrorMessage(t.getMessage());
}
});
}, MoreExecutors.directExecutor());
}
} catch (InsufficientMoneyException e) {
@ -1019,7 +1020,7 @@ public class BtcWalletService extends WalletService {
AddressEntryException, InsufficientMoneyException {
SendRequest sendRequest = getSendRequest(fromAddress, toAddress, receiverAmount, fee, aesKey, context);
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
Futures.addCallback(sendResult.broadcastComplete, callback, MoreExecutors.directExecutor());
printTx("sendFunds", sendResult.tx);
return sendResult.tx.getHashAsString();
@ -1036,7 +1037,7 @@ public class BtcWalletService extends WalletService {
SendRequest request = getSendRequestForMultipleAddresses(fromAddresses, toAddress, receiverAmount, fee, changeAddress, aesKey);
Wallet.SendResult sendResult = wallet.sendCoins(request);
Futures.addCallback(sendResult.broadcastComplete, callback);
Futures.addCallback(sendResult.broadcastComplete, callback, MoreExecutors.directExecutor());
printTx("sendFunds", sendResult.tx);
return sendResult.tx.getHashAsString();

View File

@ -29,6 +29,7 @@ import org.bitcoinj.wallet.Wallet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.HashMap;
import java.util.Map;
@ -129,7 +130,7 @@ public class TxBroadcaster {
UserThread.execute(() -> callback.onFailure(new TxBroadcastException("We got an onFailure from " +
"the peerGroup.broadcastTransaction callback.", throwable)));
}
});
}, MoreExecutors.directExecutor());
}
private static void stopAndRemoveTimer(String txId) {

View File

@ -68,6 +68,7 @@ import javax.inject.Inject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
@ -507,7 +508,7 @@ public abstract class WalletService {
log.error("emptyWallet onFailure " + t.toString());
errorMessageHandler.handleErrorMessage(t.getMessage());
}
});
}, MoreExecutors.directExecutor());
}

View File

@ -35,6 +35,7 @@ import javax.inject.Inject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
@ -135,7 +136,7 @@ public final class RepublishGovernanceDataHandler {
"Might be caused by an previous timeout.");
}
}
});
}, MoreExecutors.directExecutor());
}
private void connectToNextNode() {

View File

@ -33,6 +33,7 @@ import bisq.common.proto.network.NetworkEnvelope;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Optional;
@ -151,7 +152,7 @@ abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res
"Might be caused by an previous timeout.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.warn("We have stopped already. We ignore that requestProposalsHash call.");
}

View File

@ -41,6 +41,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.nio.file.Paths;
@ -167,7 +168,7 @@ public class ExportJsonFilesService implements DaoSetupService {
log.error(throwable.toString());
throwable.printStackTrace();
}
});
}, MoreExecutors.directExecutor());
}
}

View File

@ -52,6 +52,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
import java.util.Properties;
@ -175,7 +176,7 @@ public class RpcService {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> errorHandler.accept(throwable));
}
});
}, MoreExecutors.directExecutor());
}
void addNewBtcBlockHandler(Consumer<RawBlock> btcBlockHandler,
@ -217,7 +218,7 @@ public class RpcService {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> errorHandler.accept(throwable));
}
});
}, MoreExecutors.directExecutor());
}
void requestBtcBlock(int blockHeight,
@ -250,7 +251,7 @@ public class RpcService {
log.error("Error at requestBtcBlock: blockHeight={}", blockHeight);
UserThread.execute(() -> errorHandler.accept(throwable));
}
});
}, MoreExecutors.directExecutor());
}

View File

@ -32,6 +32,7 @@ import bisq.common.UserThread;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.LinkedList;
@ -130,7 +131,7 @@ class GetBlocksRequestHandler {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
}
public void stop() {

View File

@ -33,6 +33,7 @@ import bisq.common.proto.network.NetworkEnvelope;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Random;
@ -153,7 +154,7 @@ public class RequestBlocksHandler implements MessageListener {
"Might be caused by a previous timeout.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.warn("We have stopped already. We ignore that requestData call.");
}

View File

@ -37,6 +37,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import org.apache.commons.codec.binary.Hex;
@ -313,6 +314,6 @@ public class MobileNotificationService {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> errorHandler.accept(throwable));
}
});
}, MoreExecutors.directExecutor());
}
}

View File

@ -24,6 +24,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Map;
@ -57,7 +58,7 @@ public class FeeRequest {
public void onFailure(@NotNull Throwable throwable) {
resultFuture.setException(throwable);
}
});
}, MoreExecutors.directExecutor());
return resultFuture;
}

View File

@ -32,6 +32,7 @@ import com.google.inject.Inject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import javafx.beans.property.IntegerProperty;
@ -169,7 +170,7 @@ public class FeeService {
if (faultHandler != null)
UserThread.execute(() -> faultHandler.handleFault("Could not load fees", throwable));
}
});
}, MoreExecutors.directExecutor());
} else {
log.debug("We got a requestFees called again before min pause of {} minutes has passed.", MIN_PAUSE_BETWEEN_REQUESTS_IN_MIN);
UserThread.execute(() -> {

View File

@ -38,6 +38,7 @@ import com.google.inject.Inject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import javafx.beans.property.IntegerProperty;
@ -403,6 +404,6 @@ public class PriceFeedService {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> faultHandler.handleFault("Could not load marketPrices", throwable));
}
});
}, MoreExecutors.directExecutor());
}
}

View File

@ -24,6 +24,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Map;
@ -56,7 +57,7 @@ public class PriceRequest {
public void onFailure(@NotNull Throwable throwable) {
resultFuture.setException(new PriceRequestException(throwable, baseUrl));
}
});
}, MoreExecutors.directExecutor());
return resultFuture;
}

View File

@ -66,6 +66,7 @@ import org.bitcoinj.core.TransactionConfidence;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
@ -1157,7 +1158,7 @@ public abstract class Trade implements Tradable, Model {
log.error(t.getMessage());
throw new RuntimeException(t);
}
});
}, MoreExecutors.directExecutor());
}
} else {
log.error("depositTx == null. That must not happen.");

View File

@ -35,6 +35,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -262,7 +263,7 @@ class XmrTxProofRequest implements AssetTxProofRequest<XmrTxProofRequest.Result>
UserThread.execute(() ->
resultHandler.accept(XmrTxProofRequest.Result.ERROR.with(Detail.CONNECTION_FAILURE.error(errorMessage))));
}
});
}, MoreExecutors.directExecutor());
}
@Override

View File

@ -265,7 +265,7 @@ class TakeOfferDataModel extends OfferDataModel {
.onClose(() -> setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI))
.show());
}
});
}, MoreExecutors.directExecutor());
} else {
setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx());
isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);

View File

@ -37,6 +37,7 @@ import bisq.common.proto.network.NetworkEnvelope;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.time.Clock;
@ -135,7 +136,7 @@ public abstract class P2PSeedNodeSnapshotBase extends Metric implements MessageL
log.error(
"Sending {} failed. That is expected if the peer is offline.\n\tException={}", message.getClass().getSimpleName(), throwable.getMessage());
}
});
}, MoreExecutors.directExecutor());
} catch (Exception e) {
gate.proceed(); // release the gate on error

View File

@ -58,6 +58,7 @@ import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import org.fxmisc.easybind.EasyBind;
@ -501,7 +502,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
throwable.printStackTrace();
sendDirectMessageListener.onFault(throwable.toString());
}
});
}, MoreExecutors.directExecutor());
} catch (CryptoException e) {
e.printStackTrace();
log.error(message.toString());
@ -604,7 +605,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
receiverStoragePublicKey,
sendMailboxMessageListener);
}
});
}, MoreExecutors.directExecutor());
} catch (CryptoException e) {
log.error("sendEncryptedMessage failed");
e.printStackTrace();

View File

@ -31,6 +31,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import javafx.beans.property.ObjectProperty;
@ -225,7 +226,7 @@ public abstract class NetworkNode implements MessageListener {
log.debug("onFailure at sendMessage: peersNodeAddress={}\n\tmessage={}\n\tthrowable={}", peersNodeAddress, networkEnvelope.getClass().getSimpleName(), throwable.toString());
UserThread.execute(() -> resultFuture.setException(throwable));
}
});
}, MoreExecutors.directExecutor());
return resultFuture;
}
@ -290,7 +291,7 @@ public abstract class NetworkNode implements MessageListener {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> resultFuture.setException(throwable));
}
});
}, MoreExecutors.directExecutor());
return resultFuture;
}

View File

@ -320,6 +320,6 @@ public class TorNetworkNode extends NetworkNode {
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> log.error("Hidden service creation failed: " + throwable));
}
});
}, MoreExecutors.directExecutor());
}
}

View File

@ -28,6 +28,7 @@ import bisq.common.UserThread;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
@ -265,7 +266,7 @@ public class BroadcastHandler implements PeerManager.Listener {
maybeNotifyListeners(broadcastRequestsForConnection);
checkForCompletion();
}
});
}, MoreExecutors.directExecutor());
}
private BroadcastMessage getMessage(List<Broadcaster.BroadcastRequest> broadcastRequests) {

View File

@ -29,6 +29,7 @@ import bisq.common.UserThread;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.TimeUnit;
@ -147,7 +148,7 @@ public class GetDataRequestHandler {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
log.info("handle GetDataRequest took {} ms", System.currentTimeMillis() - ts);
}

View File

@ -37,6 +37,7 @@ import bisq.common.proto.network.NetworkPayload;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.HashMap;
@ -168,7 +169,7 @@ class RequestDataHandler implements MessageListener {
"Might be caused by an previous timeout.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.warn("We have stopped already. We ignore that requestData call.");
}

View File

@ -30,6 +30,7 @@ import bisq.common.proto.network.NetworkEnvelope;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Random;
@ -129,7 +130,7 @@ class KeepAliveHandler implements MessageListener {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.trace("We have stopped already. We ignore that sendPing call.");
}

View File

@ -35,6 +35,7 @@ import javax.inject.Inject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.HashMap;
@ -126,7 +127,7 @@ public class KeepAliveManager implements MessageListener, ConnectionListener, Pe
log.warn("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.warn("We have stopped already. We ignore that onMessage call.");
}

View File

@ -29,6 +29,7 @@ import bisq.common.UserThread;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.TimeUnit;
@ -128,7 +129,7 @@ class GetPeersRequestHandler {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
peerManager.addToReportedPeers(getPeersRequest.getReportedPeers(), connection);
}

View File

@ -32,6 +32,7 @@ import bisq.common.proto.network.NetworkEnvelope;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Random;
@ -144,7 +145,7 @@ class PeerExchangeHandler implements MessageListener {
log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onFailure call.");
}
}
});
}, MoreExecutors.directExecutor());
} else {
log.debug("My node address is still null at sendGetPeersRequest. We ignore that call.");
}

View File

@ -22,6 +22,7 @@ import bisq.network.p2p.mocks.MockPayload;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.io.File;
@ -124,7 +125,7 @@ public class TorNetworkNodeTest {
public void onFailure(@NotNull Throwable throwable) {
log.debug("onFailure ");
}
});
}, MoreExecutors.directExecutor());
latch.await();
@ -207,7 +208,7 @@ public class TorNetworkNodeTest {
public void onFailure(@NotNull Throwable throwable) {
log.debug("onFailure ");
}
});
}, MoreExecutors.directExecutor());
latch.await();