Class JSParticipant
java.lang.Object
org.jpos.util.Log
org.jpos.transaction.participant.JSParticipant
- All Implemented Interfaces:
XmlConfigurable, AbortParticipant, TransactionConstants, TransactionParticipant, LogSource
public class JSParticipant
extends Log
implements TransactionParticipant, AbortParticipant, XmlConfigurable
A TransactionParticipant whose prepare, commit and abort methods can be
specified through JS 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.
The value to return in the prepare method should be stored in the script variable named "result". None of these tags are mandatory.
Usage:
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.
The value to return in the prepare method should be stored in the script variable named "result". None of these tags are mandatory.
Usage:
Add a transaction participant like this:
<participant class="org.jpos.transaction.participant.JSParticipant" logger="Q2" realm="js"
src='deploy/test.js' />
test.js may look like this (all functions are optional)
var K = Java.type("org.jpos.transaction.TransactionConstants");
var prepare = function(id, ctx) {
var map = ctx.getMap();
ctx.log ("Prepare has been called");
ctx.log (map.TIMESTAMP);
map.NEWPROPERTY='ABC';
return K.PREPARED;
}
var prepareForAbort = function(id, ctx) {
ctx.put ("Test", "Test from JS transaction $id");
ctx.log ("prepareForAbort has been called");
return K.PREPARED;
}
var commit = function(id, ctx) {
ctx.log ("Commit has been called");
}
var abort = function(id, ctx) {
ctx.log ("Abort has been called");
}
-
Field Summary
-
Constructor Summary
Constructors -
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.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) Methods inherited from class Log
createDebug, createDebug, createError, createError, createFatal, createFatal, createInfo, createInfo, createLogEvent, createLogEvent, createTrace, createTrace, createWarn, createWarn, debug, debug, error, error, fatal, fatal, getLog, getLogger, getRealm, info, info, setLogger, setLogger, setRealm, trace, trace, warn, warn
-
Constructor Details
-
JSParticipant
public JSParticipant()
-
-
Method Details
-
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
Description copied from interface:AbortParticipantCalled 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)
-
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
-
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
-
setConfiguration
- Specified by:
setConfigurationin interfaceXmlConfigurable- Parameters:
e- Configuration element- Throws:
ConfigurationException- on error
-