Class BSHTransactionParticipant
java.lang.Object
org.jpos.util.SimpleLogSource
org.jpos.transaction.participant.BSHTransactionParticipant
- All Implemented Interfaces:
XmlConfigurable, AbortParticipant, TransactionConstants, TransactionParticipant, LogSource
- Direct Known Subclasses:
BSHGroupSelector
public class BSHTransactionParticipant
extends SimpleLogSource
implements TransactionParticipant, AbortParticipant, XmlConfigurable
A TransactionParticipant whose prepare, commit and abort methods can be
specified through beanshell scripts.
To indicate what code to execute for any of the methods just add an element named 'prepare', 'commit' or 'abort' contained in that of the participant.
See BSHMethod for details on the syntax of these elements. The value to return in the prepare method should be stored in the script variable named "result". None of these tags are mandatory.
You can subclass BSHTransactionParticipant and override the default... methods. That way you can provide default behaviour for a participant and override it at deploy time through scripts.
To indicate what code to execute for any of the methods just add an element named 'prepare', 'commit' or 'abort' contained in that of the participant.
See BSHMethod for details on the syntax of these elements. The value to return in the prepare method should be stored in the script variable named "result". None of these tags are mandatory.
You can subclass BSHTransactionParticipant and override the default... methods. That way you can provide default behaviour for a participant and override it at deploy time through scripts.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BSHMethodBeanShell method for the abort phase.protected BSHMethodBeanShell method for the commit phase.protected BSHMethodBeanShell method for the prepare-for-abort phase.protected BSHMethodBeanShell method for the prepare phase.Fields inherited from class SimpleLogSource
logger, realmFields inherited from interface TransactionConstants
ABORTED, FAIL, NO_JOIN, PAUSE, PREPARED, READONLY, RETRYModifier and TypeFieldDescriptionstatic final intTransaction has been aborted.static final intShortcut for a read-only, non-joining abort (READONLY | NO_JOIN).static final intThis participant does not join the transactionstatic final intTransaction is paused.static final intTransaction has been prepared successfully.static final intContext has not been modified (no need to persist a snapshot)static final intTransaction should be retried. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of BSHTransactionParticipant -
Method Summary
Modifier and TypeMethodDescriptionvoidabort(long id, Serializable context) Called by TransactionManager upon transaction commit.voidcommit(long id, Serializable context) Called by TransactionManager upon transaction commit.protected voiddefaultAbort(long id, Serializable context, LogEvent ev) Default abort handling when no BeanShell abort method is configured (no-op).protected voiddefaultCommit(long id, Serializable context, LogEvent ev) Default commit implementation (no-op).protected intdefaultPrepare(long id, Serializable context, LogEvent ev) Default prepare implementation; returns PREPARED|READONLY.protected ObjectexecuteMethod(BSHMethod m, long id, Serializable context, LogEvent evt, String resultName) Executes the given BSHMethod with the standard transaction parameters.intprepare(long id, Serializable context) Called by TransactionManager in preparation for a transactionintprepareForAbort(long id, Serializable context) Called by TransactionManager in preparation for a transaction that is known to abort.voidsetConfiguration(org.jdom2.Element e) Configures this object from an XML element.Methods inherited from class SimpleLogSource
error, error, getLogger, getRealm, info, info, setLogger, setRealm, warning, warningModifier and TypeMethodDescriptionvoidLogs an error message.voidLogs an error message with an attached object.Returns the logger.getRealm()Returns the logging realm.voidLogs an informational message.voidLogs an informational message with an attached object.voidSets the logger and realm for this log source.voidSets the logging realm.voidLogs a warning message.voidLogs a warning message with an attached object.
-
Field Details
-
prepareMethod
BeanShell method for the prepare phase. -
prepareForAbortMethod
BeanShell method for the prepare-for-abort phase. -
commitMethod
BeanShell method for the commit phase. -
abortMethod
BeanShell method for the abort phase.
-
-
Constructor Details
-
BSHTransactionParticipant
public BSHTransactionParticipant()Creates a new instance of BSHTransactionParticipant
-
-
Method Details
-
abort
Description copied from interface:TransactionParticipantCalled by TransactionManager upon transaction commit. Warning: implementation should be able to handle multiple calls with the same transaction id (rare crash recovery)- Specified by:
abortin interfaceTransactionParticipant- Parameters:
id- the Transaction identifiercontext- transaction context
-
defaultAbort
Default abort handling when no BeanShell abort method is configured (no-op).- Parameters:
id- transaction idcontext- transaction contextev- log event
-
commit
Description copied from interface:TransactionParticipantCalled by TransactionManager upon transaction commit. Warning: implementation should be able to handle multiple calls with the same transaction id (rare crash recovery)- Specified by:
commitin interfaceTransactionParticipant- Parameters:
id- the Transaction identifiercontext- transaction context
-
defaultCommit
Default commit implementation (no-op).- Parameters:
id- transaction idcontext- transaction contextev- log event
-
prepare
Description copied from interface:TransactionParticipantCalled by TransactionManager in preparation for a transaction- Specified by:
preparein interfaceTransactionParticipant- Parameters:
id- the Transaction identifiercontext- transaction context- Returns:
- PREPARED or ABORTED (| NO_JOIN | READONLY)
-
prepareForAbort
Called by TransactionManager in preparation for a transaction that is known to abort.- Specified by:
prepareForAbortin interfaceAbortParticipant- Parameters:
id- the Transaction identifiercontext- transaction context- Returns:
- 0 [| NO_JOIN | READONLY)
-
defaultPrepare
Default prepare implementation; returns PREPARED|READONLY.- Parameters:
id- transaction idcontext- transaction contextev- log event- Returns:
- transaction result code
-
setConfiguration
Description copied from interface:XmlConfigurableConfigures this object from an XML element.- Specified by:
setConfigurationin interfaceXmlConfigurable- Parameters:
e- Configuration element- Throws:
ConfigurationException- on error
-
executeMethod
protected Object executeMethod(BSHMethod m, long id, Serializable context, LogEvent evt, String resultName) throws bsh.EvalError, IOException Executes the given BSHMethod with the standard transaction parameters.- Parameters:
m- the BSHMethod to executeid- transaction idcontext- transaction contextevt- log eventresultName- the result variable name- Returns:
- the value of resultName after execution
- Throws:
bsh.EvalError- on BeanShell evaluation errorIOException- if the script cannot be read
-