Class JSParticipant

java.lang.Object
org.jpos.util.Log
org.jpos.transaction.participant.JSParticipant
All Implemented Interfaces:
XmlConfigurable, AbortParticipant, TransactionConstants, TransactionParticipant, LogSource

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:
    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");
    }
  • Constructor Details

  • Method Details