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;
protected void updateStateOnFault() {
}
private void interceptBeforeRun() {
if (getClass() == taskToInterceptBeforeRun)
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() {
updateStateOnFault();
taskHandler.handleErrorMessage(errorMessage);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -41,9 +41,4 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
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.WalletService;
import io.bitsquare.crypto.SignatureService;
import io.bitsquare.p2p.MailboxService;
import io.bitsquare.p2p.MessageService;
import io.bitsquare.persistence.Persistence;
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);
transient public final Trade trade;
public final MailboxService mailboxService;
public final TakerModel taker;
public final OffererModel offerer;
@ -44,6 +46,7 @@ public class BuyerAsOffererModel extends SharedTradeModel implements Serializabl
public BuyerAsOffererModel(Trade trade,
MessageService messageService,
MailboxService mailboxService,
WalletService walletService,
BlockChainService blockChainService,
SignatureService signatureService,
@ -57,6 +60,7 @@ public class BuyerAsOffererModel extends SharedTradeModel implements Serializabl
persistence);
this.trade = trade;
this.mailboxService = mailboxService;
Serializable serializable = persistence.read(this, "BuyerAsOffererModel_" + id);
if (serializable instanceof BuyerAsOffererModel) {

View File

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

View File

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

View File

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

View File

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

View File

@ -56,8 +56,4 @@ public class ProcessRequestOffererPublishDepositTxMessage extends Task<BuyerAsOf
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,27 +35,27 @@ public class SendBankTransferStartedMessage extends Task<BuyerAsOffererModel> {
@Override
protected void doRun() {
BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage(
model.id,
model.offerer.payoutTxSignature,
model.offerer.payoutAmount,
model.taker.payoutAmount,
model.offerer.addressEntry.getAddressString());
model.messageService.sendMessage(model.taker.peer, tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("Sending BankTransferInitedMessage succeeded.");
complete();
}
try {
BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage(
model.id,
model.offerer.payoutTxSignature,
model.offerer.payoutAmount,
model.taker.payoutAmount,
model.offerer.addressEntry.getAddressString());
model.messageService.sendMessage(model.taker.peer, tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {
log.trace("Sending BankTransferInitedMessage succeeded.");
complete();
}
@Override
public void handleFault() {
failed("Sending BankTransferInitedMessage failed.");
}
});
}
@Override
protected void updateStateOnFault() {
@Override
public void handleFault() {
failed("Sending BankTransferInitedMessage failed.");
}
});
} catch (Throwable t) {
failed("Sending BankTransferInitedMessage failed.");
}
}
}

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))
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);
}
}
@Override
protected void updateStateOnFault() {
}
}

View File

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

View File

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

View File

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

View File

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