Rename *Handler methods

This commit is contained in:
Chris Beams 2014-11-05 13:12:30 +01:00
parent f72bdf5f71
commit 44dc76e07e
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
28 changed files with 56 additions and 51 deletions

View file

@ -78,7 +78,7 @@ class TomP2POfferRepository implements OfferRepository {
// deactivate it for the moment until the port forwarding bug is fixed // deactivate it for the moment until the port forwarding bug is fixed
// if (future.isSuccess()) { // if (future.isSuccess()) {
Platform.runLater(() -> { Platform.runLater(() -> {
resultHandler.onResult(); resultHandler.handleResult();
offerRepositoryListeners.stream().forEach(listener -> { offerRepositoryListeners.stream().forEach(listener -> {
try { try {
Object offerDataObject = offerData.object(); Object offerDataObject = offerData.object();
@ -101,13 +101,13 @@ class TomP2POfferRepository implements OfferRepository {
@Override @Override
public void exceptionCaught(Throwable ex) throws Exception { public void exceptionCaught(Throwable ex) throws Exception {
Platform.runLater(() -> { Platform.runLater(() -> {
faultHandler.onFault("Failed to add offer to DHT", ex); faultHandler.handleFault("Failed to add offer to DHT", ex);
}); });
} }
}); });
} catch (IOException ex) { } catch (IOException ex) {
Platform.runLater(() -> { Platform.runLater(() -> {
faultHandler.onFault("Failed to add offer to DHT", ex); faultHandler.handleFault("Failed to add offer to DHT", ex);
}); });
} }
} }

View file

@ -168,7 +168,8 @@ public class TradeManager {
settings.getAcceptedLanguageLocales()); settings.getAcceptedLanguageLocales());
if (createOfferCoordinatorMap.containsKey(offer.getId())) { if (createOfferCoordinatorMap.containsKey(offer.getId())) {
errorMessageHandler.onFault("A createOfferCoordinator for the offer with the id " + offer.getId() + " " + errorMessageHandler.handleErrorMessage("A createOfferCoordinator for the offer with the id " + offer
.getId() + " " +
"already exists."); "already exists.");
} }
else { else {
@ -185,13 +186,13 @@ public class TradeManager {
resultHandler.onResult(transactionId); resultHandler.onResult(transactionId);
} catch (Exception e) { } catch (Exception e) {
//TODO retry policy //TODO retry policy
errorMessageHandler.onFault("Could not save offer. Reason: " + errorMessageHandler.handleErrorMessage("Could not save offer. Reason: " +
(e.getCause() != null ? e.getCause().getMessage() : e.toString())); (e.getCause() != null ? e.getCause().getMessage() : e.toString()));
createOfferCoordinatorMap.remove(offer.getId()); createOfferCoordinatorMap.remove(offer.getId());
} }
}, },
(message, throwable) -> { (message, throwable) -> {
errorMessageHandler.onFault(message); errorMessageHandler.handleErrorMessage(message);
createOfferCoordinatorMap.remove(offer.getId()); createOfferCoordinatorMap.remove(offer.getId());
}, offerRepository); }, offerRepository);
createOfferCoordinatorMap.put(offer.getId(), createOfferCoordinator); createOfferCoordinatorMap.put(offer.getId(), createOfferCoordinator);

View file

@ -142,7 +142,7 @@ public class CreateOfferCoordinator {
private void onFailed(String message, Throwable throwable) { private void onFailed(String message, Throwable throwable) {
//TODO recover policy, timer //TODO recover policy, timer
faultHandler.onFault(message, throwable); faultHandler.handleFault(message, throwable);
} }

View file

@ -42,24 +42,24 @@ public class BroadCastOfferFeeTx {
log.info("sendResult onSuccess:" + transaction); log.info("sendResult onSuccess:" + transaction);
if (transaction != null) { if (transaction != null) {
try { try {
resultHandler.onResult(); resultHandler.handleResult();
} catch (Exception e) { } catch (Exception e) {
faultHandler.onFault("Offer fee payment failed.", e); faultHandler.handleFault("Offer fee payment failed.", e);
} }
} }
else { else {
faultHandler.onFault("Offer fee payment failed.", faultHandler.handleFault("Offer fee payment failed.",
new Exception("Offer fee payment failed. Transaction = null.")); new Exception("Offer fee payment failed. Transaction = null."));
} }
} }
@Override @Override
public void onFailure(@NotNull Throwable t) { public void onFailure(@NotNull Throwable t) {
faultHandler.onFault("Offer fee payment failed with an exception.", t); faultHandler.handleFault("Offer fee payment failed with an exception.", t);
} }
}); });
} catch (Throwable t) { } catch (Throwable t) {
faultHandler.onFault("Offer fee payment failed because an exception occurred.", t); faultHandler.handleFault("Offer fee payment failed because an exception occurred.", t);
} }
} }
} }

View file

@ -34,10 +34,11 @@ public class CreateOfferFeeTx {
try { try {
resultHandler.onResult(walletFacade.createOfferFeeTx(offerId)); resultHandler.onResult(walletFacade.createOfferFeeTx(offerId));
} catch (InsufficientMoneyException e) { } catch (InsufficientMoneyException e) {
faultHandler.onFault("Offer fee payment failed because there is insufficient money in the trade wallet. " + faultHandler.handleFault("Offer fee payment failed because there is insufficient money in the trade " +
"wallet. " +
"", e); "", e);
} catch (Throwable t) { } catch (Throwable t) {
faultHandler.onFault("Offer fee payment failed because of an exception occurred. ", t); faultHandler.handleFault("Offer fee payment failed because of an exception occurred. ", t);
} }
} }
} }

View file

@ -66,9 +66,9 @@ public class VerifyOffer {
// getAddressInfoByTradeID(offerId) // getAddressInfoByTradeID(offerId)
// TODO when offer is flattened continue here... // TODO when offer is flattened continue here...
resultHandler.onResult(); resultHandler.handleResult();
} catch (Throwable t) { } catch (Throwable t) {
faultHandler.onFault("Offer validation failed.", t); faultHandler.handleFault("Offer validation failed.", t);
} }
} }
} }

View file

@ -50,7 +50,7 @@ public class CreateDepositTx {
resultHandler.onResult(offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex); resultHandler.onResult(offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
} catch (InsufficientMoneyException e) { } catch (InsufficientMoneyException e) {
log.error("Create deposit tx faultHandler.onFault due InsufficientMoneyException " + e); log.error("Create deposit tx faultHandler.onFault due InsufficientMoneyException " + e);
exceptionHandler.onError( exceptionHandler.handleException(
new Exception("Create deposit tx faultHandler.onFault due InsufficientMoneyException " + e)); new Exception("Create deposit tx faultHandler.onFault due InsufficientMoneyException " + e));
} }
} }

View file

@ -49,7 +49,7 @@ public class HandleTakeOfferRequest {
@Override @Override
public void onFailed() { public void onFailed() {
log.error("AcceptTakeOfferRequestMessage did not arrive at peer"); log.error("AcceptTakeOfferRequestMessage did not arrive at peer");
exceptionHandler.onError(new Exception("AcceptTakeOfferRequestMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("AcceptTakeOfferRequestMessage did not arrive at peer"));
} }
}); });
} }

View file

@ -48,13 +48,14 @@ public class RequestTakerDepositPayment {
@Override @Override
public void onResult() { public void onResult() {
log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer"); log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("RequestTakerDepositPaymentMessage did not arrive at peer"); log.error("RequestTakerDepositPaymentMessage did not arrive at peer");
exceptionHandler.onError(new Exception("RequestTakerDepositPaymentMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("RequestTakerDepositPaymentMessage did not arrive at " +
"peer"));
} }
}); });
} }

View file

@ -43,13 +43,13 @@ public class SendDepositTxIdToTaker {
@Override @Override
public void onResult() { public void onResult() {
log.trace("DepositTxPublishedMessage successfully arrived at peer"); log.trace("DepositTxPublishedMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("DepositTxPublishedMessage did not arrive at peer"); log.error("DepositTxPublishedMessage did not arrive at peer");
exceptionHandler.onError(new Exception("DepositTxPublishedMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("DepositTxPublishedMessage did not arrive at peer"));
} }
}); });
} }

View file

@ -72,19 +72,19 @@ public class SendSignedPayoutTx {
@Override @Override
public void onResult() { public void onResult() {
log.trace("BankTransferInitedMessage successfully arrived at peer"); log.trace("BankTransferInitedMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("BankTransferInitedMessage did not arrive at peer"); log.error("BankTransferInitedMessage did not arrive at peer");
exceptionHandler.onError(new Exception("BankTransferInitedMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("BankTransferInitedMessage did not arrive at peer"));
} }
}); });
} catch (Exception e) { } catch (Exception e) {
log.error("Exception at OffererCreatesAndSignsPayoutTx " + e); log.error("Exception at OffererCreatesAndSignsPayoutTx " + e);
exceptionHandler.onError(e); exceptionHandler.handleException(e);
} }
} }
} }

View file

@ -44,7 +44,7 @@ public class SetupListenerForBlockChainConfirmation {
listener.onDepositTxConfirmedInBlockchain(); listener.onDepositTxConfirmedInBlockchain();
depositTransaction.getConfidence().removeEventListener(this); depositTransaction.getConfidence().removeEventListener(this);
log.trace("Tx is in blockchain"); log.trace("Tx is in blockchain");
resultHandler.onResult(); resultHandler.handleResult();
} }
} }
}); });

View file

@ -59,12 +59,12 @@ public class SignAndPublishDepositTx {
@Override @Override
public void onFailure(@NotNull Throwable t) { public void onFailure(@NotNull Throwable t) {
log.error("offererSignAndPublishTx faultHandler.onFault:" + t); log.error("offererSignAndPublishTx faultHandler.onFault:" + t);
exceptionHandler.onError(t); exceptionHandler.handleException(t);
} }
}); });
} catch (Exception e) { } catch (Exception e) {
log.error("offererSignAndPublishTx faultHandler.onFault:" + e); log.error("offererSignAndPublishTx faultHandler.onFault:" + e);
exceptionHandler.onError(e); exceptionHandler.handleException(e);
} }
} }

View file

@ -33,7 +33,7 @@ public class VerifyTakeOfferFeePayment {
//TODO mocked yet, need a confidence listeners //TODO mocked yet, need a confidence listeners
int numOfPeersSeenTx = walletFacade.getNumOfPeersSeenTx(takeOfferFeeTxId); int numOfPeersSeenTx = walletFacade.getNumOfPeersSeenTx(takeOfferFeeTxId);
if (numOfPeersSeenTx > 2) { if (numOfPeersSeenTx > 2) {
resultHandler.onResult(); resultHandler.handleResult();
} }
} }

View file

@ -34,15 +34,16 @@ public class VerifyPeerAccount {
if (blockChainFacade.verifyAccountRegistration()) { if (blockChainFacade.verifyAccountRegistration()) {
if (blockChainFacade.isAccountBlackListed(peersAccountId, peersBankAccount)) { if (blockChainFacade.isAccountBlackListed(peersAccountId, peersBankAccount)) {
log.error("Taker is blacklisted"); log.error("Taker is blacklisted");
exceptionHandler.onError(new Exception("Taker is blacklisted")); exceptionHandler.handleException(new Exception("Taker is blacklisted"));
} }
else { else {
resultHandler.onResult(); resultHandler.handleResult();
} }
} }
else { else {
log.error("Account registration validation for peer faultHandler.onFault."); log.error("Account registration validation for peer faultHandler.onFault.");
exceptionHandler.onError(new Exception("Account registration validation for peer faultHandler.onFault.")); exceptionHandler.handleException(new Exception("Account registration validation for peer faultHandler" +
".onFault."));
} }
} }

View file

@ -58,7 +58,7 @@ public class CreateAndSignContract {
resultHandler.onResult(contract, contractAsJson, signature); resultHandler.onResult(contract, contractAsJson, signature);
} catch (Throwable t) { } catch (Throwable t) {
log.error("Exception at sign contract " + t); log.error("Exception at sign contract " + t);
exceptionHandler.onError(t); exceptionHandler.handleException(t);
} }
} }

View file

@ -43,7 +43,7 @@ public class GetPeerAddress {
@Override @Override
public void onFailed() { public void onFailed() {
log.error("Lookup for peer address faultHandler.onFault."); log.error("Lookup for peer address faultHandler.onFault.");
exceptionHandler.onError(new Exception("Lookup for peer address faultHandler.onFault.")); exceptionHandler.handleException(new Exception("Lookup for peer address faultHandler.onFault."));
} }
}); });
} }

View file

@ -57,7 +57,7 @@ public class PayDeposit {
resultHandler.onResult(signedTakerDepositTx); resultHandler.onResult(signedTakerDepositTx);
} catch (InsufficientMoneyException e) { } catch (InsufficientMoneyException e) {
log.error("Pay deposit faultHandler.onFault due InsufficientMoneyException " + e); log.error("Pay deposit faultHandler.onFault due InsufficientMoneyException " + e);
exceptionHandler.onError( exceptionHandler.handleException(
new Exception("Pay deposit faultHandler.onFault due InsufficientMoneyException " + e)); new Exception("Pay deposit faultHandler.onFault due InsufficientMoneyException " + e));
} }
} }

View file

@ -47,13 +47,13 @@ public class PayTakeOfferFee {
@Override @Override
public void onFailure(@NotNull Throwable t) { public void onFailure(@NotNull Throwable t) {
log.error("Take offer fee paid faultHandler.onFault with exception: " + t); log.error("Take offer fee paid faultHandler.onFault with exception: " + t);
exceptionHandler.onError( exceptionHandler.handleException(
new Exception("Take offer fee paid faultHandler.onFault with exception: " + t)); new Exception("Take offer fee paid faultHandler.onFault with exception: " + t));
} }
}); });
} catch (InsufficientMoneyException e) { } catch (InsufficientMoneyException e) {
log.error("Take offer fee paid faultHandler.onFault due InsufficientMoneyException " + e); log.error("Take offer fee paid faultHandler.onFault due InsufficientMoneyException " + e);
exceptionHandler.onError( exceptionHandler.handleException(
new Exception("Take offer fee paid faultHandler.onFault due to InsufficientMoneyException " + e)); new Exception("Take offer fee paid faultHandler.onFault due to InsufficientMoneyException " + e));
} }
} }

View file

@ -38,13 +38,14 @@ public class RequestTakeOffer {
@Override @Override
public void onResult() { public void onResult() {
log.trace("RequestTakeOfferMessage successfully arrived at peer"); log.trace("RequestTakeOfferMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("RequestTakeOfferMessage did not arrive at peer"); log.error("RequestTakeOfferMessage did not arrive at peer");
exceptionHandler.onError(new Exception("RequestTakeOfferMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("RequestTakeOfferMessage did not arrive at " +
"peer"));
} }
}); });
} }

View file

@ -38,13 +38,13 @@ public class SendPayoutTxToOfferer {
@Override @Override
public void onResult() { public void onResult() {
log.trace("PayoutTxPublishedMessage successfully arrived at peer"); log.trace("PayoutTxPublishedMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("PayoutTxPublishedMessage did not arrive at peer"); log.error("PayoutTxPublishedMessage did not arrive at peer");
exceptionHandler.onError(new Exception("PayoutTxPublishedMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("PayoutTxPublishedMessage did not arrive at peer"));
} }
}); });

View file

@ -72,13 +72,13 @@ public class SendSignedTakerDepositTxAsHex {
@Override @Override
public void onResult() { public void onResult() {
log.trace("RequestOffererDepositPublicationMessage successfully arrived at peer"); log.trace("RequestOffererDepositPublicationMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("RequestOffererDepositPublicationMessage did not arrive at peer"); log.error("RequestOffererDepositPublicationMessage did not arrive at peer");
exceptionHandler.onError( exceptionHandler.handleException(
new Exception("RequestOffererDepositPublicationMessage did not arrive at peer")); new Exception("RequestOffererDepositPublicationMessage did not arrive at peer"));
} }
}); });

View file

@ -48,13 +48,13 @@ public class SendTakeOfferFeePayedTxId {
@Override @Override
public void onResult() { public void onResult() {
log.trace("TakeOfferFeePayedMessage successfully arrived at peer"); log.trace("TakeOfferFeePayedMessage successfully arrived at peer");
resultHandler.onResult(); resultHandler.handleResult();
} }
@Override @Override
public void onFailed() { public void onFailed() {
log.error("TakeOfferFeePayedMessage did not arrive at peer"); log.error("TakeOfferFeePayedMessage did not arrive at peer");
exceptionHandler.onError(new Exception("TakeOfferFeePayedMessage did not arrive at peer")); exceptionHandler.handleException(new Exception("TakeOfferFeePayedMessage did not arrive at peer"));
} }
}); });
} }

View file

@ -65,12 +65,12 @@ public class SignAndPublishPayoutTx {
@Override @Override
public void onFailure(@NotNull Throwable t) { public void onFailure(@NotNull Throwable t) {
log.error("Exception at takerSignsAndSendsTx " + t); log.error("Exception at takerSignsAndSendsTx " + t);
exceptionHandler.onError(t); exceptionHandler.handleException(t);
} }
}); });
} catch (Exception e) { } catch (Exception e) {
log.error("Exception at takerSignsAndSendsTx " + e); log.error("Exception at takerSignsAndSendsTx " + e);
exceptionHandler.onError(e); exceptionHandler.handleException(e);
} }
} }

View file

@ -21,5 +21,5 @@ package io.bitsquare.util.task;
* For reporting error message only (UI) * For reporting error message only (UI)
*/ */
public interface ErrorMessageHandler { public interface ErrorMessageHandler {
void onFault(String errorMessage); void handleErrorMessage(String errorMessage);
} }

View file

@ -21,5 +21,5 @@ package io.bitsquare.util.task;
* For reporting throwables only * For reporting throwables only
*/ */
public interface ExceptionHandler { public interface ExceptionHandler {
void onError(Throwable throwable); void handleException(Throwable throwable);
} }

View file

@ -21,5 +21,5 @@ package io.bitsquare.util.task;
* For reporting a description message and throwable * For reporting a description message and throwable
*/ */
public interface FaultHandler { public interface FaultHandler {
void onFault(String message, Throwable throwable); void handleFault(String message, Throwable throwable);
} }

View file

@ -18,5 +18,5 @@
package io.bitsquare.util.task; package io.bitsquare.util.task;
public interface ResultHandler { public interface ResultHandler {
void onResult(); void handleResult();
} }