Package org.apache.qpid.protonj2.engine
Interface TransactionController
- All Superinterfaces:
Endpoint<TransactionController>
- All Known Implementing Classes:
ProtonTransactionController
Transaction Controller link that implements the mechanics of declaring and discharging
AMQP transactions. A
TransactionController is typically used at the client side
of an AMQP Link to create Transaction instances which the client application
will enlist its incoming and outgoing deliveries into.-
Method Summary
Modifier and TypeMethodDescriptionAllows the caller to add anEventHandlerthat will be signaled when the underlying link for thisTransactionControllerhas been granted credit which would then allow for transactionDeclaredandDischargecommands to be sent to the remote Transactional Resource.declare()Request that the remoteTransactionManagerdeclare a new transaction and respond with a new transaction Id for that transaction.declare(Transaction<TransactionController> transaction) Request that the remoteTransactionManagerdeclare a new transaction and respond with a new transaction Id for that transaction.declaredHandler(EventHandler<Transaction<TransactionController>> declaredEventHandler) Called when theTransactionManagerend of the link has responded to a previousDeclarerequest and the transaction can now be used to enroll deliveries into the active transaction.declareFailureHandler(EventHandler<Transaction<TransactionController>> declareFailureEventHandler) Called when theTransactionManagerend of the link responds to aTransactiondeclaration with anRejectedoutcome indicating that the transaction could not be successfully declared.discharge(Transaction<TransactionController> transaction, boolean failed) Request that the remoteTransactionManagerdischarge the given transaction and with the specified failure state (true for failed).dischargedHandler(EventHandler<Transaction<TransactionController>> dischargedEventHandler) Called when theTransactionManagerend of the link has responded to a previousdischarge(Transaction, boolean)request and the transaction has been retired.dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler) Called when theTransactionManagerend of the link has responded to a previousdischarge(Transaction, boolean)request and the transaction discharge failed for some reason.Returns the currently set Coordinator target for thisLink.Returns the remote targetTerminusfor this transaction controller which must be of typeCoordinatoror null if remote did not set a terminus.booleanReturnstrueif theTransactionControllerhas capacity to send or buffer andTransactioncommand toDeclareorDischarge.Creates a newTransactioninstances that is returned in theTransactionState.IDLEstate which can be populated with application specific attachments or assigned a linked resource prior to calling theSets aEventHandlerfor when the parentSessionorConnectionof thisTransactionControlleris locally closed.setCoordinator(Coordinator coordinator) Sets theCoordinatortarget to assign to the local end of thisTransactionController.Sets theSourceto assign to the local end of thisTransactionController.Returns a list ofTransactionobjects that are active within thisTransactionControllerwhich have not reached a terminal state meaning they have not been successfully discharged and have not failed in either theDeclarephase or theDischargephase.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 Details
-
hasCapacity
boolean hasCapacity()Returnstrueif theTransactionControllerhas capacity to send or buffer andTransactioncommand toDeclareorDischarge. 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
Sets theSourceto assign to the local end of thisTransactionController. Must be called during setup, i.e. before calling theEndpoint.open()method.- Parameters:
source- TheSourcethat will be set on the local end of this transaction controller.- Returns:
- this transaction controller instance.
- Throws:
IllegalStateException- if theTransactionControllerhas already been opened.
-
getSource
Source getSource()- Returns:
- the
Sourcefor the local end of thisTransactionController.
-
setCoordinator
Sets theCoordinatortarget to assign to the local end of thisTransactionController. Must be called during setup, i.e. before calling theEndpoint.open()method.- Parameters:
coordinator- TheCoordinatortarget that will be set on the local end of this transaction controller.- Returns:
- this transaction controller instance.
- Throws:
IllegalStateException- if theTransactionControllerhas already been opened.
-
getCoordinator
Coordinator getCoordinator()Returns the currently set Coordinator target for thisLink.- Returns:
- the link target
Coordinatorfor the local end of this link.
-
getRemoteSource
Source getRemoteSource()- Returns:
- the source
Sourcefor the remote end of thisTransactionController.
-
getRemoteCoordinator
Coordinator getRemoteCoordinator()Returns the remote targetTerminusfor this transaction controller which must be of typeCoordinatoror null if remote did not set a terminus.- Returns:
- the remote coordinator
Terminusfor the remote end of this link.
-
transactions
Collection<Transaction<TransactionController>> transactions()Returns a list ofTransactionobjects that are active within thisTransactionControllerwhich have not reached a terminal state meaning they have not been successfully discharged and have not failed in either theDeclarephase or theDischargephase. If there are no transactions active within thisTransactionControllerthis 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 newTransactioninstances that is returned in theTransactionState.IDLEstate which can be populated with application specific attachments or assigned a linked resource prior to calling the- Returns:
- a new
Transactioninstance that can be correlated with later declared events.
-
declare
Transaction<TransactionController> declare()Request that the remoteTransactionManagerdeclare 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
Transactioninstance that can be correlated with later declared events.
-
declare
Request that the remoteTransactionManagerdeclare 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- TheTransactionthat is will be associated with the eventual declared transaction.- Returns:
- this
TransactionController
-
discharge
Request that the remoteTransactionManagerdischarge 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- TheTransactionthat 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 theTransactionManagerend of the link has responded to a previousDeclarerequest and the transaction can now be used to enroll deliveries into the active transaction.- Parameters:
declaredEventHandler- AnEventHandlerthat will act on the transaction declaration request.- Returns:
- this
TransactionController.
-
declareFailureHandler
TransactionController declareFailureHandler(EventHandler<Transaction<TransactionController>> declareFailureEventHandler) Called when theTransactionManagerend of the link responds to aTransactiondeclaration with anRejectedoutcome indicating that the transaction could not be successfully declared.- Parameters:
declareFailureEventHandler- AnEventHandlerthat will be called when a previous transaction declaration fails.- Returns:
- this
TransactionController.
-
dischargedHandler
TransactionController dischargedHandler(EventHandler<Transaction<TransactionController>> dischargedEventHandler) Called when theTransactionManagerend of the link has responded to a previousdischarge(Transaction, boolean)request and the transaction has been retired.- Parameters:
dischargedEventHandler- AnEventHandlerthat will act on the transaction discharge request.- Returns:
- this
TransactionController.
-
dischargeFailureHandler
TransactionController dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler) Called when theTransactionManagerend of the link has responded to a previousdischarge(Transaction, boolean)request and the transaction discharge failed for some reason.- Parameters:
dischargeFailureEventHandler- AnEventHandlerthat will act on the transaction discharge failed event.- Returns:
- this
TransactionController.
-
addCapacityAvailableHandler
Allows the caller to add anEventHandlerthat will be signaled when the underlying link for thisTransactionControllerhas been granted credit which would then allow for transactionDeclaredandDischargecommands 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 transactionDeclaredorDischargeis performed as other tasks might have already consumed credit if work is done via some asynchronous mechanism.- Parameters:
handler- TheEventHandlerthat will be signaled once credit is available for transaction work.- Returns:
- this
TransactionControllerinstance.
-
parentEndpointClosedHandler
Sets aEventHandlerfor when the parentSessionorConnectionof thisTransactionControlleris 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- TheEventHandlerto notify when this transaction controller's parent endpoint is locally closed.- Returns:
- the link for chaining.
-