resend payment sent & received messages from trade thread on startup

This commit is contained in:
woodser 2024-02-01 07:43:31 -05:00
parent bbec107dcc
commit 6f51d333ec
2 changed files with 46 additions and 40 deletions

View File

@ -55,27 +55,30 @@ public class BuyerProtocol extends DisputeProtocol {
super.onInitialized();
// re-send payment sent message if not acked
synchronized (trade) {
if (trade.isShutDownStarted()) return;
if (trade.getState().ordinal() >= Trade.State.BUYER_SENT_PAYMENT_SENT_MSG.ordinal() && trade.getState().ordinal() < Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG.ordinal()) {
latchTrade();
given(anyPhase(Trade.Phase.PAYMENT_SENT)
.with(BuyerEvent.STARTUP))
.setup(tasks(
BuyerSendPaymentSentMessageToSeller.class,
BuyerSendPaymentSentMessageToArbitrator.class)
.using(new TradeTaskRunner(trade,
() -> {
unlatchTrade();
},
(errorMessage) -> {
log.warn("Error sending PaymentSentMessage on startup: " + errorMessage);
unlatchTrade();
})))
.executeTasks();
awaitTradeLatch();
ThreadUtils.execute(() -> {
if (trade.isShutDownStarted() || trade.isPayoutPublished()) return;
synchronized (trade) {
if (trade.isShutDownStarted() || trade.isPayoutPublished()) return;
if (trade.getState().ordinal() >= Trade.State.BUYER_SENT_PAYMENT_SENT_MSG.ordinal() && trade.getState().ordinal() < Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG.ordinal()) {
latchTrade();
given(anyPhase(Trade.Phase.PAYMENT_SENT)
.with(BuyerEvent.STARTUP))
.setup(tasks(
BuyerSendPaymentSentMessageToSeller.class,
BuyerSendPaymentSentMessageToArbitrator.class)
.using(new TradeTaskRunner(trade,
() -> {
unlatchTrade();
},
(errorMessage) -> {
log.warn("Error sending PaymentSentMessage on startup: " + errorMessage);
unlatchTrade();
})))
.executeTasks();
awaitTradeLatch();
}
}
}
}, trade.getId());
}
@Override

View File

@ -51,27 +51,30 @@ public class SellerProtocol extends DisputeProtocol {
super.onInitialized();
// re-send payment received message if payout not published
synchronized (trade) {
if (trade.isShutDownStarted()) return;
if (trade.getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && !trade.isPayoutPublished()) {
latchTrade();
given(anyPhase(Trade.Phase.PAYMENT_RECEIVED)
.with(SellerEvent.STARTUP))
.setup(tasks(
SellerSendPaymentReceivedMessageToBuyer.class,
SellerSendPaymentReceivedMessageToArbitrator.class)
.using(new TradeTaskRunner(trade,
() -> {
unlatchTrade();
},
(errorMessage) -> {
log.warn("Error sending PaymentReceivedMessage on startup: " + errorMessage);
unlatchTrade();
})))
.executeTasks();
awaitTradeLatch();
ThreadUtils.execute(() -> {
if (trade.isShutDownStarted() || trade.isPayoutPublished()) return;
synchronized (trade) {
if (trade.isShutDownStarted() || trade.isPayoutPublished()) return;
if (trade.getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && !trade.isPayoutPublished()) {
latchTrade();
given(anyPhase(Trade.Phase.PAYMENT_RECEIVED)
.with(SellerEvent.STARTUP))
.setup(tasks(
SellerSendPaymentReceivedMessageToBuyer.class,
SellerSendPaymentReceivedMessageToArbitrator.class)
.using(new TradeTaskRunner(trade,
() -> {
unlatchTrade();
},
(errorMessage) -> {
log.warn("Error sending PaymentReceivedMessage on startup: " + errorMessage);
unlatchTrade();
})))
.executeTasks();
awaitTradeLatch();
}
}
}
}, trade.getId());
}
@Override