org.jpos.transaction.participant
Class BSHTransactionParticipant

java.lang.Object
  extended by org.jpos.util.SimpleLogSource
      extended by org.jpos.transaction.participant.BSHTransactionParticipant
All Implemented Interfaces:
XmlConfigurable, AbortParticipant, TransactionConstants, TransactionParticipant, LogSource
Direct Known Subclasses:
BSHGroupSelector

public class BSHTransactionParticipant
extends SimpleLogSource
implements TransactionParticipant, AbortParticipant, XmlConfigurable

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.

Author:
AMarques
See Also:
BSHMethod

Field Summary
protected  BSHMethod abortMethod
           
protected  BSHMethod commitMethod
           
protected  BSHMethod prepareForAbortMethod
           
protected  BSHMethod prepareMethod
           
 
Fields inherited from class org.jpos.util.SimpleLogSource
logger, realm
 
Fields inherited from interface org.jpos.transaction.TransactionConstants
ABORTED, NO_JOIN, PAUSE, PREPARED, READONLY, RETRY
 
Constructor Summary
BSHTransactionParticipant()
          Creates a new instance of BSHTransactionParticipant
 
Method Summary
 void abort(long id, Serializable context)
          Called by TransactionManager upon transaction commit.
 void commit(long id, Serializable context)
          Called by TransactionManager upon transaction commit.
protected  void defaultAbort(long id, Serializable context, LogEvent ev)
           
protected  void defaultCommit(long id, Serializable context, LogEvent ev)
           
protected  int defaultPrepare(long id, Serializable context, LogEvent ev)
           
protected  Object executeMethod(BSHMethod m, long id, Serializable context, LogEvent evt, String resultName)
           
 int prepare(long id, Serializable context)
          Called by TransactionManager in preparation for a transaction
 int prepareForAbort(long id, Serializable context)
          Called by TransactionManager in preparation for a transaction that is known to abort.
 void setConfiguration(org.jdom.Element e)
           
 
Methods inherited from class org.jpos.util.SimpleLogSource
error, error, getLogger, getRealm, info, info, setLogger, setRealm, warning, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prepareMethod

protected BSHMethod prepareMethod

prepareForAbortMethod

protected BSHMethod prepareForAbortMethod

commitMethod

protected BSHMethod commitMethod

abortMethod

protected BSHMethod abortMethod
Constructor Detail

BSHTransactionParticipant

public BSHTransactionParticipant()
Creates a new instance of BSHTransactionParticipant

Method Detail

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)

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)

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)

defaultPrepare

protected int defaultPrepare(long id,
                             Serializable context,
                             LogEvent ev)

setConfiguration

public void setConfiguration(org.jdom.Element e)
                      throws ConfigurationException
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,
                               FileNotFoundException,
                               IOException
Throws:
bsh.EvalError
FileNotFoundException
IOException


Copyright © 1998-2012 jPOS.org. All Rights Reserved.