org.objectweb.jotm.impl.core.transaction
Class CoreTransaction

java.lang.Object
  |
  +--org.objectweb.jotm.impl.core.transaction.CoreTransaction
All Implemented Interfaces:
BasicTransaction, Demarcable, EventSource, Interrogable, Locker, Suspendable, TwoPhaseCommitInterrogable, TwoPhaseCommitTransaction

public class CoreTransaction
extends java.lang.Object
implements TwoPhaseCommitTransaction, Locker

CoreTransaction is an implementation of a simple transaction with two phase commit. I.e., it emits events that are implementations of TransactionalEvent or TwoPhaseCommitEvent. CoreTransaction also implements Interrogable, Demarcable, and Suspendable.
CoreTransaction serves as an event source for the events as follows:

It is possible to register a listener of an event only if the transaction is in the Interrogable.STATUS_ACTIVE state. Important note: It is not possible to register a listener of each individual event in the list above. This is done for: Therefore, it is not possible to register to the TwoPhaseCommitEvent TYPE_PREPARE, TYPE_ONE_PHASE_COMMIT, TYPE_COMMIT, and TYPE_ABORT events individually. Instead, it is necessary to register a listener that handles the TwoPhaseCommitEvent.TYPE_TWO_PHASE_COMMIT event which covers all of these events.

Note: The TwoPhaseCommitEvent.TYPE_SYNCHRONIZATION event covers the TransactionalEvent.TYPE_BEFORE_COMPLETION, TransactionalEvent.TYPE_AFTER_COMPLETION, but it is also possible to register individual listeners of these events, since this is not an incorrect behavior.


Field Summary
 
Fields inherited from interface org.objectweb.jotm.core.transaction.Interrogable
STATUS_ABORTED, STATUS_ABORTING, STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_NO_TRANSACTION
 
Fields inherited from interface org.objectweb.jotm.core.transaction.TwoPhaseCommitInterrogable
STATUS_PREPARED, STATUS_PREPARING
 
Constructor Summary
CoreTransaction(TransactionManager iTm)
           
CoreTransaction(TransactionManager iTm, java.lang.String name)
           
 
Method Summary
 void abort()
          Aborts transaction.
 void addListener(int eventType, EventListener listener)
          Adds a new listener.
 void begin()
          Begins transaction.
 void commit()
          Commits transaction.
 java.lang.String getName()
          Get transaction name.
 int getStatus()
          Get transaction status.
 int getTimeout()
          Get transaction timeout.
static CoreTransaction getTransaction()
           
 java.lang.Object getWrapper()
           
 void removeListener(int eventType, EventListener listener)
          Removes a listener.
 void resume()
           
 void setWrapper(java.lang.Object object)
           
 void suspend()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoreTransaction

public CoreTransaction(TransactionManager iTm)

CoreTransaction

public CoreTransaction(TransactionManager iTm,
                       java.lang.String name)
Method Detail

begin

public void begin()
           throws InvalidStateException
Description copied from interface: Demarcable
Begins transaction. The method starts this transaction.

Specified by:
begin in interface Demarcable
Throws:
InvalidStateException - if the transaction is in a state different from Interrogable.STATUS_NO_TRANSACTION

commit

public void commit()
            throws InvalidStateException,
                   TransactionAbortedException
Description copied from interface: Demarcable
Commits transaction. The method commits this transaction.

Specified by:
commit in interface Demarcable
Throws:
TransactionAbortedException - commit of the transaction did not succeeded and the transaction has been aborted
InvalidStateException - if the transaction is in a state different from Interrogable.STATUS_ACTIVE

abort

public void abort()
           throws InvalidStateException
Description copied from interface: Demarcable
Aborts transaction. The method aborts this transaction.

Specified by:
abort in interface Demarcable
Throws:
InvalidStateException - if the transaction is in a state different from Interrogable.STATUS_ACTIVE

getTimeout

public int getTimeout()
Description copied from interface: Interrogable
Get transaction timeout.

Specified by:
getTimeout in interface Interrogable
Returns:
transaction timoeut

getName

public java.lang.String getName()
Description copied from interface: Interrogable
Get transaction name.

Specified by:
getName in interface Interrogable
Returns:
name of transaction

suspend

public void suspend()
Specified by:
suspend in interface Suspendable

resume

public void resume()
Specified by:
resume in interface Suspendable

getStatus

public int getStatus()
Description copied from interface: Interrogable
Get transaction status.

Specified by:
getStatus in interface Interrogable
Returns:
status of transaction

addListener

public void addListener(int eventType,
                        EventListener listener)
Adds a new listener. One of the following transactional events is allowed to be registered: It is not allowed to register to individual events that together compose the TwoPhaseCommitEvent.
It is allowed to register to several events at the same time by passing bitwise or of those events.

Specified by:
addListener in interface EventSource
Parameters:
eventType - type of events to be delivered to the listener
listener - listener that will receive events of the specified type

removeListener

public void removeListener(int eventType,
                           EventListener listener)
Removes a listener. For the list of allowed transactional events look to addListener(int, org.objectweb.jotm.core.events.EventListener). It is allowed to remove listeners to several events at the same time by passing bitwise or of those events.

Specified by:
removeListener in interface EventSource
Parameters:
eventType - type of events that are delivered to the listener
listener - listener that receives events of the specified type

getTransaction

public static CoreTransaction getTransaction()
                                      throws NoTransactionException
NoTransactionException

getWrapper

public java.lang.Object getWrapper()
Returns:
wrapper object. Null if there is none

setWrapper

public void setWrapper(java.lang.Object object)
Parameters:
object - wrapper object