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

    • JSParticipant

      public JSParticipant()
      Default constructor; no instance state to initialise.
  • Method Details

    • prepare

      public int prepare(long id, Serializable context)
      Description copied from interface: TransactionParticipant
      Called by TransactionManager in preparation for a transaction
      Specified by:
      prepare in interface TransactionParticipant
      Parameters:
      id - the Transaction identifier
      context - transaction context
      Returns:
      PREPARED or ABORTED (| NO_JOIN | READONLY)
    • prepareForAbort

      public int prepareForAbort(long id, Serializable context)
      Description copied from interface: AbortParticipant
      Called by TransactionManager in preparation for a transaction that is known to abort.
      Specified by:
      prepareForAbort in interface AbortParticipant
      Parameters:
      id - the Transaction identifier
      context - transaction context
      Returns:
      0 [| NO_JOIN | READONLY)
    • commit

      public void commit(long id, Serializable context)
      Description copied from interface: TransactionParticipant
      Called by TransactionManager upon transaction commit. Warning: implementation should be able to handle multiple calls with the same transaction id (rare crash recovery)
      Specified by:
      commit in interface TransactionParticipant
      Parameters:
      id - the Transaction identifier
      context - transaction context
    • abort

      public void abort(long id, Serializable context)
      Description copied from interface: TransactionParticipant
      Called by TransactionManager upon transaction commit. Warning: implementation should be able to handle multiple calls with the same transaction id (rare crash recovery)
      Specified by:
      abort in interface TransactionParticipant
      Parameters:
      id - the Transaction identifier
      context - transaction context
    • setConfiguration

      public void setConfiguration(org.jdom2.Element e) throws ConfigurationException
      Description copied from interface: XmlConfigurable
      Configures this object from an XML element.
      Specified by:
      setConfiguration in interface XmlConfigurable
      Parameters:
      e - Configuration element
      Throws:
      ConfigurationException - on error