The SessionHandleState class (package com.atomikos.datasource.xa.session) tracks the XA enlistment history of a JDBC or JMS connection/session handle. This class is used in packages com.atomikos.jdbc and com.atomikos.jms to enlist and delist JDBC and JMS connections.

Classes

The class diagram is shown below. The SessionHandleState can detect (and deal with) connection/session objects passing transaction boundaries (e.g., when passed as an argument to a method whose transaction attribute specifies REQUIRES_NEW). It does this by tracking all transaction contexts it detects. Each detected context has a TransactionContext instance with internal state transitions for enlistment/delistment of the corresponding XA branch. Note that for most uses, there will only be one TransactionContext.

SessionHandleStateClasses.png

State changes are detected via one of the notify methods. It is the responsibility of the resource adapter to call these methods when appropriate.

The most important method with respect to reusability in the pool is isReleased: once this returns true, all pending transactions on the session are terminated, and the session handle itself was closed by the application.

SessionHandleState State Transitions

Conceptually, the SessionHandleState objects react according to the following finite state diagram.

SessionHandleStateTransitions.png

TransactionContext State Transitions

The SessionHandleState objects maintain a TransactionContext object for each transaction detected on the borrow cycle.

The TransactionContext follows the state pattern for modeling its internal state (i.e., are we enlisted, delisted, ...). Each state is expressed via a separate state handler class. The transitions between states are shown below.

SessionBranchStates.png

Code location of Transitions: