Different Between TransactionParticipant and AbortParticipant

Today, i want to share about the different between TransactionParticipant and AbortParticipant interface on jPOS iso 8583 framework.
you need to implement one of these interface when you are using Transaction Manager on your jPOS project. you can find my post about how to implement Transaction Manager here.
back to the main topic in this post. What is different between TransactionParticipant and AbortParticipant interface, and when you use AbortParticipant instead TransactionParticipant interface. I have looking for the information about this on jPOS programmer guide:

developer can implement the optional AbortParticipant interface, in order to let the TransactionManager know that you still want to join the transaction, even if it’s known to have failed.

and the AbortParticipant interface look like:
[java]
public interface AbortParticipant extends TransactionParticipant {
public int prepareForAbort (long id, Serializable context);
}
[/java]

i still getting confuse about that explanation, what i have learned is that the different between these interface is that AbortParticipant have extra method called prepareForAbort(id, context). So i looking for the prepareForAbort() usage, but when i debug my code and set break point in my prepareForAbort() method, i realize that prepareForAbort() method never be invoked.
Then, i ask to the jpos user group here and get great explanation from Mr. Alejandro Revilla. Here it is the explanation:

the TM will call prepare on the participants, if all participants return PREPARED, then the TM will call commit on all those that have joined the transaction (by not returning the NO_JOIN modifier).

The first participant that returns ABORTED will indicate the TM that there’s no need to call prepare on the following participants, because the transaction is bound to be aborted unless the participant implements the AbortParticipant.

The prepareForAbort is basically a way for the TM to say “Hey, do whatever you have to do, but this transaction I’m asking you to get ready for is actually going to be aborted anyway”.

Implementing AbortParticipant is a way to let the TM know that you want to get called even if the transaction is going to abort.

so, based on that clear explanation, you need to implement AbortParticipant interface if you need to process prepare method of all participant even if there are prepare method that return ABORTED. And by contrast you have to implement TransactionParticipant interface, if you need to initiate the aborting procedure (which will call abort(id,context) only on the previously-called participants) if one of participants prepare() method return ABORTED.

So, that’s enough for different between TransactionParticipant and AbortParticipant interface post. hope this post can help you, thanks for visiting my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *