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

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.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • 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
    • defaultAbort

      protected void defaultAbort(long id, Serializable context, LogEvent ev)
      Default abort handling when no BeanShell abort method is configured (no-op).
      Parameters:
      id - transaction id
      context - transaction context
      ev - log event
    • 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
    • defaultCommit

      protected void defaultCommit(long id, Serializable context, LogEvent ev)
      Default commit implementation (no-op).
      Parameters:
      id - transaction id
      context - transaction context
      ev - log event
    • 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)
      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)
    • defaultPrepare

      protected int defaultPrepare(long id, Serializable context, LogEvent ev)
      Default prepare implementation; returns PREPARED|READONLY.
      Parameters:
      id - transaction id
      context - transaction context
      ev - log event
      Returns:
      transaction result code
    • 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
    • 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 execute
      id - transaction id
      context - transaction context
      evt - log event
      resultName - the result variable name
      Returns:
      the value of resultName after execution
      Throws:
      bsh.EvalError - on BeanShell evaluation error
      IOException - if the script cannot be read