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
Fields inherited from class Log
DEBUG, defaultTags, ERROR, FATAL, INFO, logger, realm, TRACE, WARNModifier and TypeFieldDescriptionstatic final StringLevel constant for debug events.Default tags applied to everyLogEventcreated by thisLog.static final StringLevel constant for error events.static final StringLevel constant for fatal events.static final StringLevel constant for informational events.protected LoggerLogger receiving the events produced by thisLog.protected StringRealm associated with events emitted through thisLog.static final StringLevel constant for trace events.static final StringLevel constant for warning events.Fields 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
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) Configures this object from an XML element.Methods inherited from class Log
applyDefaultTags, createDebug, createDebug, createError, createError, createFatal, createFatal, createInfo, createInfo, createLogEvent, createLogEvent, createTrace, createTrace, createWarn, createWarn, debug, debug, error, error, fatal, fatal, getDefaultTags, getLog, getLogger, getRealm, info, info, removeDefaultTag, setDefaultTag, setDefaultTags, setLogger, setLogger, setRealm, trace, trace, warn, warnModifier and TypeMethodDescriptionprotected LogEventapplyDefaultTags(LogEvent evt) Decoratesevtwith thisLog's default tags, if any.Creates an empty debug-level event.createDebug(Object detail) Creates a debug-level event with the given payload.Creates an empty error-level event.createError(Object detail) Creates an error-level event with the given payload.Creates an empty fatal-level event.createFatal(Object detail) Creates a fatal-level event with the given payload.Creates an empty info-level event.createInfo(Object detail) Creates an info-level event with the given payload.createLogEvent(String level) Creates a newLogEventat the given level decorated with thisLog's default tags.createLogEvent(String level, Object detail) Creates a newLogEventat the given level with an initial payload.Creates an empty trace-level event.createTrace(Object detail) Creates a trace-level event with the given payload.Creates an empty warning-level event.createWarn(Object detail) Creates a warning-level event with the given payload.voidLogs a debug event with the given detail.voidLogs a debug event with the given detail and an additional payload.voidLogs an error event with the given detail.voidLogs an error event with the given detail and an additional payload.voidLogs a fatal event with the given detail.voidLogs a fatal event with the given detail and an additional payload.Returns an unmodifiable snapshot of the current default tags.static LogConvenience factory returning aLogbound to the given logger name and realm.Returns the underlying logger.getRealm()Returns the realm associated with events emitted through thisLog.voidLogs an info event with the given detail.voidLogs an info event with the given detail and an additional payload.voidremoveDefaultTag(String key) Removes a previously-registered default tag.voidsetDefaultTag(String key, String value) Sets a default tag on every event produced by thisLog; anullvalue removes the entry.voidsetDefaultTags(Map<String, String> tags) Replaces the entire set of default tags.voidReplaces the underlying logger, leaving the realm unchanged.voidReplaces the underlying logger and realm.voidReplaces the realm associated with emitted events.voidLogs a trace event with the given detail.voidLogs a trace event with the given detail and an additional payload.voidLogs a warning event with the given detail.voidLogs a warning event with the given detail and an additional payload.
-
Constructor Details
-
JSParticipant
public JSParticipant()Default constructor; no instance state to initialise.
-
-
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
Description copied from interface:XmlConfigurableConfigures this object from an XML element.- Specified by:
setConfigurationin interfaceXmlConfigurable- Parameters:
e- Configuration element- Throws:
ConfigurationException- on error
-