Remove updateStateOnFault method

This commit is contained in:
Manfred Karrer 2015-03-20 17:36:07 +01:00
parent b5e47716d6
commit b531c3a0c2
21 changed files with 35 additions and 95 deletions

View file

@ -51,9 +51,6 @@ public abstract class Task<T extends SharedTaskModel> {
abstract protected void doRun() throws WalletException, TransactionVerificationException, SigningException; abstract protected void doRun() throws WalletException, TransactionVerificationException, SigningException;
protected void updateStateOnFault() {
}
private void interceptBeforeRun() { private void interceptBeforeRun() {
if (getClass() == taskToInterceptBeforeRun) if (getClass() == taskToInterceptBeforeRun)
throw new InterceptTaskException("Task intercepted before run got executed. Task = " + getClass().getSimpleName()); throw new InterceptTaskException("Task intercepted before run got executed. Task = " + getClass().getSimpleName());
@ -96,7 +93,6 @@ public abstract class Task<T extends SharedTaskModel> {
} }
protected void failed() { protected void failed() {
updateStateOnFault();
taskHandler.handleErrorMessage(errorMessage); taskHandler.handleErrorMessage(errorMessage);
} }

View file

@ -27,6 +27,7 @@ import io.bitsquare.offer.Direction;
import io.bitsquare.offer.Offer; import io.bitsquare.offer.Offer;
import io.bitsquare.offer.OfferBookService; import io.bitsquare.offer.OfferBookService;
import io.bitsquare.p2p.AddressService; import io.bitsquare.p2p.AddressService;
import io.bitsquare.p2p.MailboxService;
import io.bitsquare.p2p.Message; import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.MessageService; import io.bitsquare.p2p.MessageService;
import io.bitsquare.p2p.Peer; import io.bitsquare.p2p.Peer;
@ -72,6 +73,7 @@ public class TradeManager {
private final AccountSettings accountSettings; private final AccountSettings accountSettings;
private final Persistence persistence; private final Persistence persistence;
private final MessageService messageService; private final MessageService messageService;
private MailboxService mailboxService;
private final AddressService addressService; private final AddressService addressService;
private final BlockChainService blockChainService; private final BlockChainService blockChainService;
private final WalletService walletService; private final WalletService walletService;
@ -95,13 +97,14 @@ public class TradeManager {
@Inject @Inject
public TradeManager(User user, AccountSettings accountSettings, Persistence persistence, public TradeManager(User user, AccountSettings accountSettings, Persistence persistence,
MessageService messageService, AddressService addressService, BlockChainService blockChainService, MessageService messageService, MailboxService mailboxService, AddressService addressService, BlockChainService blockChainService,
WalletService walletService, SignatureService signatureService, WalletService walletService, SignatureService signatureService,
OfferBookService offerBookService) { OfferBookService offerBookService) {
this.user = user; this.user = user;
this.accountSettings = accountSettings; this.accountSettings = accountSettings;
this.persistence = persistence; this.persistence = persistence;
this.messageService = messageService; this.messageService = messageService;
this.mailboxService = mailboxService;
this.addressService = addressService; this.addressService = addressService;
this.blockChainService = blockChainService; this.blockChainService = blockChainService;
this.walletService = walletService; this.walletService = walletService;
@ -428,6 +431,7 @@ public class TradeManager {
BuyerAsOffererModel model = new BuyerAsOffererModel( BuyerAsOffererModel model = new BuyerAsOffererModel(
trade, trade,
messageService, messageService,
mailboxService,
walletService, walletService,
blockChainService, blockChainService,
signatureService, signatureService,

View file

@ -42,9 +42,4 @@ public class AddOfferToRemoteOfferBook extends Task<PlaceOfferModel> {
failed(throwable); failed(throwable);
}); });
} }
@Override
protected void updateStateOnFault() {
// do nothing
}
} }

View file

@ -79,12 +79,14 @@ public class BroadcastCreateOfferFeeTx extends Task<PlaceOfferModel> {
log.error("addOffer failed"); log.error("addOffer failed");
addOfferFailed = true; addOfferFailed = true;
failed(throwable); failed(throwable);
updateStateOnFault();
}); });
}, },
(message, throwable) -> { (message, throwable) -> {
log.error("removeOffer failed"); log.error("removeOffer failed");
removeOfferFailed = true; removeOfferFailed = true;
failed(throwable); failed(throwable);
updateStateOnFault();
}); });
} }
} }
@ -92,15 +94,17 @@ public class BroadcastCreateOfferFeeTx extends Task<PlaceOfferModel> {
@Override @Override
public void onFailure(@NotNull Throwable t) { public void onFailure(@NotNull Throwable t) {
failed(t); failed(t);
updateStateOnFault();
} }
}); });
} }
else { else {
failed("Not enough balance for placing the offer."); failed("Not enough balance for placing the offer.");
updateStateOnFault();
} }
} }
protected void updateStateOnFault() { private void updateStateOnFault() {
if (!removeOfferFailed && !addOfferFailed) { if (!removeOfferFailed && !addOfferFailed) {
// If broadcast fails we need to remove offer from offerbook // If broadcast fails we need to remove offer from offerbook
model.offerBookService.removeOffer(model.offer, model.offerBookService.removeOffer(model.offer,

View file

@ -48,9 +48,4 @@ public class CreateOfferFeeTx extends Task<PlaceOfferModel> {
failed(t); failed(t);
} }
} }
@Override
protected void updateStateOnFault() {
// do nothing
}
} }

View file

@ -41,9 +41,4 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
failed(e); failed(e);
} }
} }
@Override
protected void updateStateOnFault() {
// do nothing
}
} }

View file

@ -20,6 +20,7 @@ package io.bitsquare.trade.protocol.trade.offerer.models;
import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.WalletService; import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService; import io.bitsquare.crypto.SignatureService;
import io.bitsquare.p2p.MailboxService;
import io.bitsquare.p2p.MessageService; import io.bitsquare.p2p.MessageService;
import io.bitsquare.persistence.Persistence; import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
@ -36,6 +37,7 @@ public class BuyerAsOffererModel extends SharedTradeModel implements Serializabl
private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class); private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class);
transient public final Trade trade; transient public final Trade trade;
public final MailboxService mailboxService;
public final TakerModel taker; public final TakerModel taker;
public final OffererModel offerer; public final OffererModel offerer;
@ -44,6 +46,7 @@ public class BuyerAsOffererModel extends SharedTradeModel implements Serializabl
public BuyerAsOffererModel(Trade trade, public BuyerAsOffererModel(Trade trade,
MessageService messageService, MessageService messageService,
MailboxService mailboxService,
WalletService walletService, WalletService walletService,
BlockChainService blockChainService, BlockChainService blockChainService,
SignatureService signatureService, SignatureService signatureService,
@ -57,6 +60,7 @@ public class BuyerAsOffererModel extends SharedTradeModel implements Serializabl
persistence); persistence);
this.trade = trade; this.trade = trade;
this.mailboxService = mailboxService;
Serializable serializable = persistence.read(this, "BuyerAsOffererModel_" + id); Serializable serializable = persistence.read(this, "BuyerAsOffererModel_" + id);
if (serializable instanceof BuyerAsOffererModel) { if (serializable instanceof BuyerAsOffererModel) {

View file

@ -61,9 +61,5 @@ public class CreateAndSignPayoutTx extends Task<BuyerAsOffererModel> {
failed(e); failed(e);
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -50,8 +50,4 @@ public class CreateOffererDepositTxInputs extends Task<BuyerAsOffererModel> {
failed(e); failed(e);
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -50,8 +50,4 @@ public class ProcessPayoutTxPublishedMessage extends Task<BuyerAsOffererModel> {
failed(t); failed(t);
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -52,9 +52,4 @@ public class ProcessRequestDepositTxInputsMessage extends Task<BuyerAsOffererMod
failed(t); failed(t);
} }
} }
@Override
protected void updateStateOnFault() {
// do nothing
}
} }

View file

@ -56,8 +56,4 @@ public class ProcessRequestOffererPublishDepositTxMessage extends Task<BuyerAsOf
failed(t); failed(t);
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -56,8 +56,4 @@ public class RequestDepositPayment extends Task<BuyerAsOffererModel> {
} }
}); });
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -35,6 +35,7 @@ public class SendBankTransferStartedMessage extends Task<BuyerAsOffererModel> {
@Override @Override
protected void doRun() { protected void doRun() {
try {
BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage( BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage(
model.id, model.id,
model.offerer.payoutTxSignature, model.offerer.payoutTxSignature,
@ -53,9 +54,8 @@ public class SendBankTransferStartedMessage extends Task<BuyerAsOffererModel> {
failed("Sending BankTransferInitedMessage failed."); failed("Sending BankTransferInitedMessage failed.");
} }
}); });
} } catch (Throwable t) {
failed("Sending BankTransferInitedMessage failed.");
@Override }
protected void updateStateOnFault() {
} }
} }

View file

@ -50,8 +50,4 @@ public class SendDepositTxIdToTaker extends Task<BuyerAsOffererModel> {
} }
}); });
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -64,8 +64,4 @@ public class SetupListenerForBlockChainConfirmation extends Task<BuyerAsOffererM
if (!transactionConfidence.removeEventListener(transactionConfidenceListener)) if (!transactionConfidence.removeEventListener(transactionConfidenceListener))
throw new RuntimeException("Remove transactionConfidenceListener failed at SetupListenerForBlockChainConfirmation."); throw new RuntimeException("Remove transactionConfidenceListener failed at SetupListenerForBlockChainConfirmation.");
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -73,8 +73,4 @@ public class SignAndPublishDepositTx extends Task<BuyerAsOffererModel> {
failed(e); failed(e);
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -58,8 +58,4 @@ public class VerifyAndSignContract extends Task<BuyerAsOffererModel> {
complete(); complete();
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -41,8 +41,4 @@ public class VerifyTakeOfferFeePayment extends Task<BuyerAsOffererModel> {
complete(); complete();
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -47,8 +47,4 @@ public class VerifyTakerAccount extends Task<BuyerAsOffererModel> {
failed("Account registration validation for peer failed."); failed("Account registration validation for peer failed.");
} }
} }
@Override
protected void updateStateOnFault() {
}
} }

View file

@ -40,8 +40,4 @@ public class VerifyOfferFeePayment extends Task<SellerAsTakerModel> {
}*/ }*/
complete(); complete();
} }
@Override
protected void updateStateOnFault() {
}
} }