Package org.apache.qpid.protonj2.engine
Interface TransactionController
-
- All Superinterfaces:
Endpoint<TransactionController>
- All Known Implementing Classes:
ProtonTransactionController
public interface TransactionController extends Endpoint<TransactionController>
Transaction Controller link that implements the mechanics of declaring and discharging AMQP transactions. ATransactionController
is typically used at the client side of an AMQPLink
to createTransaction
instances which the client application will enlist its incoming and outgoing deliveries into.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TransactionController
addCapacityAvailableHandler(EventHandler<TransactionController> handler)
Allows the caller to add anEventHandler
that will be signaled when the underlying link for thisTransactionController
has been granted credit which would then allow for transactionDeclared
andDischarge
commands to be sent to the remote Transactional Resource.Transaction<TransactionController>
declare()
Request that the remoteTransactionManager
declare a new transaction and respond with a new transaction Id for that transaction.TransactionController
declare(Transaction<TransactionController> transaction)
Request that the remoteTransactionManager
declare a new transaction and respond with a new transaction Id for that transaction.TransactionController
declaredHandler(EventHandler<Transaction<TransactionController>> declaredEventHandler)
Called when theTransactionManager
end of the link has responded to a previousDeclare
request and the transaction can now be used to enroll deliveries into the active transaction.TransactionController
declareFailureHandler(EventHandler<Transaction<TransactionController>> declareFailureEventHandler)
Called when theTransactionManager
end of the link responds to aTransaction
declaration with anRejected
outcome indicating that the transaction could not be successfully declared.TransactionController
discharge(Transaction<TransactionController> transaction, boolean failed)
Request that the remoteTransactionManager
discharge the given transaction and with the specified failure state (true for failed).TransactionController
dischargedHandler(EventHandler<Transaction<TransactionController>> dischargedEventHandler)
Called when theTransactionManager
end of the link has responded to a previousdischarge(Transaction, boolean)
request and the transaction has been retired.TransactionController
dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler)
Called when theTransactionManager
end of the link has responded to a previousdischarge(Transaction, boolean)
request and the transaction discharge failed for some reason.Coordinator
getCoordinator()
Returns the currently set Coordinator target for thisLink
.Coordinator
getRemoteCoordinator()
Returns the remote targetTerminus
for this transaction controller which must be of typeCoordinator
or null if remote did not set a terminus.Source
getRemoteSource()
Source
getSource()
boolean
hasCapacity()
Returnstrue
if theTransactionController
has capacity to send or buffer andTransaction
command toDeclare
orDischarge
.Transaction<TransactionController>
newTransaction()
Creates a newTransaction
instances that is returned in theTransactionState.IDLE
state which can be populated with application specific attachments or assigned a linked resource prior to calling theTransactionController
parentEndpointClosedHandler(EventHandler<TransactionController> handler)
Sets aEventHandler
for when the parentSession
orConnection
of thisTransactionController
is locally closed.TransactionController
setCoordinator(Coordinator coordinator)
Sets theCoordinator
target to assign to the local end of thisTransactionController
.TransactionController
setSource(Source source)
Sets theSource
to assign to the local end of thisTransactionController
.java.util.Collection<Transaction<TransactionController>>
transactions()
Returns a list ofTransaction
objects that are active within thisTransactionController
which have not reached a terminal state meaning they have not been successfully discharged and have not failed in either theDeclare
phase or theDischarge
phase.-
Methods inherited from interface org.apache.qpid.protonj2.engine.Endpoint
close, closeHandler, engineShutdownHandler, getAttachments, getCondition, getDesiredCapabilities, getEngine, getLinkedResource, getLinkedResource, getOfferedCapabilities, getParent, getProperties, getRemoteCondition, getRemoteDesiredCapabilities, getRemoteOfferedCapabilities, getRemoteProperties, isLocallyClosed, isLocallyOpen, isRemotelyClosed, isRemotelyOpen, localCloseHandler, localOpenHandler, open, openHandler, setCondition, setDesiredCapabilities, setLinkedResource, setOfferedCapabilities, setProperties
-
-
-
-
Method Detail
-
hasCapacity
boolean hasCapacity()
Returnstrue
if theTransactionController
has capacity to send or buffer andTransaction
command toDeclare
orDischarge
. If no capacity then a call todeclare()
or todischarge(Transaction, boolean)
would throw an exception.- Returns:
- true if the controller will allow declaring or discharging a transaction at this time.
-
setSource
TransactionController setSource(Source source) throws java.lang.IllegalStateException
Sets theSource
to assign to the local end of thisTransactionController
. Must be called during setup, i.e. before calling theEndpoint.open()
method.- Parameters:
source
- TheSource
that will be set on the local end of this transaction controller.- Returns:
- this transaction controller instance.
- Throws:
java.lang.IllegalStateException
- if theTransactionController
has already been opened.
-
getSource
Source getSource()
- Returns:
- the
Source
for the local end of thisTransactionController
.
-
setCoordinator
TransactionController setCoordinator(Coordinator coordinator) throws java.lang.IllegalStateException
Sets theCoordinator
target to assign to the local end of thisTransactionController
. Must be called during setup, i.e. before calling theEndpoint.open()
method.- Parameters:
coordinator
- TheCoordinator
target that will be set on the local end of this transaction controller.- Returns:
- this transaction controller instance.
- Throws:
java.lang.IllegalStateException
- if theTransactionController
has already been opened.
-
getCoordinator
Coordinator getCoordinator()
Returns the currently set Coordinator target for thisLink
.- Returns:
- the link target
Coordinator
for the local end of this link.
-
getRemoteSource
Source getRemoteSource()
- Returns:
- the source
Source
for the remote end of thisTransactionController
.
-
getRemoteCoordinator
Coordinator getRemoteCoordinator()
Returns the remote targetTerminus
for this transaction controller which must be of typeCoordinator
or null if remote did not set a terminus.- Returns:
- the remote coordinator
Terminus
for the remote end of this link.
-
transactions
java.util.Collection<Transaction<TransactionController>> transactions()
Returns a list ofTransaction
objects that are active within thisTransactionController
which have not reached a terminal state meaning they have not been successfully discharged and have not failed in either theDeclare
phase or theDischarge
phase. If there are no transactions active within thisTransactionController
this method returns an emptyCollection
.- Returns:
- a list of Transactions that are allocated to this controller that have not reached a terminal state.
-
newTransaction
Transaction<TransactionController> newTransaction()
Creates a newTransaction
instances that is returned in theTransactionState.IDLE
state which can be populated with application specific attachments or assigned a linked resource prior to calling the- Returns:
- a new
Transaction
instance that can be correlated with later declared events.
-
declare
Transaction<TransactionController> declare()
Request that the remoteTransactionManager
declare a new transaction and respond with a new transaction Id for that transaction. Upon successful declaration of a new transaction the remote will respond and thedeclaredHandler(EventHandler)
event handler will be signaled. This is a convenience method that is the same as first callingnewTransaction()
and then passing the result of that to thedeclare(Transaction)
method.- Returns:
- a new
Transaction
instance that can be correlated with later declared events.
-
declare
TransactionController declare(Transaction<TransactionController> transaction)
Request that the remoteTransactionManager
declare a new transaction and respond with a new transaction Id for that transaction. Upon successful declaration of a new transaction the remote will respond and thedeclaredHandler(EventHandler)
event handler will be signaled.- Parameters:
transaction
- TheTransaction
that is will be associated with the eventual declared transaction.- Returns:
- this
TransactionController
-
discharge
TransactionController discharge(Transaction<TransactionController> transaction, boolean failed)
Request that the remoteTransactionManager
discharge the given transaction and with the specified failure state (true for failed). Upon successful declaration of a new transaction the remote will respond and thedeclaredHandler(EventHandler)
event handler will be signaled.- Parameters:
transaction
- TheTransaction
that is being discharged.failed
- boolean value indicating the the discharge indicates the transaction failed (rolled back).- Returns:
- this
TransactionController
-
declaredHandler
TransactionController declaredHandler(EventHandler<Transaction<TransactionController>> declaredEventHandler)
Called when theTransactionManager
end of the link has responded to a previousDeclare
request and the transaction can now be used to enroll deliveries into the active transaction.- Parameters:
declaredEventHandler
- AnEventHandler
that will act on the transaction declaration request.- Returns:
- this
TransactionController
.
-
declareFailureHandler
TransactionController declareFailureHandler(EventHandler<Transaction<TransactionController>> declareFailureEventHandler)
Called when theTransactionManager
end of the link responds to aTransaction
declaration with anRejected
outcome indicating that the transaction could not be successfully declared.- Parameters:
declareFailureEventHandler
- AnEventHandler
that will be called when a previous transaction declaration fails.- Returns:
- this
TransactionController
.
-
dischargedHandler
TransactionController dischargedHandler(EventHandler<Transaction<TransactionController>> dischargedEventHandler)
Called when theTransactionManager
end of the link has responded to a previousdischarge(Transaction, boolean)
request and the transaction has been retired.- Parameters:
dischargedEventHandler
- AnEventHandler
that will act on the transaction discharge request.- Returns:
- this
TransactionController
.
-
dischargeFailureHandler
TransactionController dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler)
Called when theTransactionManager
end of the link has responded to a previousdischarge(Transaction, boolean)
request and the transaction discharge failed for some reason.- Parameters:
dischargeFailureEventHandler
- AnEventHandler
that will act on the transaction discharge failed event.- Returns:
- this
TransactionController
.
-
addCapacityAvailableHandler
TransactionController addCapacityAvailableHandler(EventHandler<TransactionController> handler)
Allows the caller to add anEventHandler
that will be signaled when the underlying link for thisTransactionController
has been granted credit which would then allow for transactionDeclared
andDischarge
commands to be sent to the remote Transactional Resource. If the controller already has credit to send then the handler will be invoked immediately otherwise it will be stored until credit becomes available. Once a handler is signaled it is no longer retained for future updates and the caller will need to register it again once more transactional work is to be completed. Because more than one handler can be added at a time the caller should check again before attempting to perform a transactionDeclared
orDischarge
is performed as other tasks might have already consumed credit if work is done via some asynchronous mechanism.- Parameters:
handler
- TheEventHandler
that will be signaled once credit is available for transaction work.- Returns:
- this
TransactionController
instance.
-
parentEndpointClosedHandler
TransactionController parentEndpointClosedHandler(EventHandler<TransactionController> handler)
Sets aEventHandler
for when the parentSession
orConnection
of thisTransactionController
is locally closed. Typically used by clients for logging or other state update event processing. Clients should not perform any blocking calls within this context. It is an error for the handler to throw an exception and the outcome of doing so is undefined.- Parameters:
handler
- TheEventHandler
to notify when this transaction controller's parent endpoint is locally closed.- Returns:
- the link for chaining.
-
-