Class ProtonTransactionController
java.lang.Object
org.apache.qpid.protonj2.engine.impl.ProtonEndpoint<TransactionController>
org.apache.qpid.protonj2.engine.impl.ProtonTransactionController
- All Implemented Interfaces:
Endpoint<TransactionController>,TransactionController
public class ProtonTransactionController
extends ProtonEndpoint<TransactionController>
implements TransactionController
TransactionController implementation that implements the abstraction
around a sender link that initiates requests to Declare and to
Discharge AMQP Transaction instance.-
Field Summary
Fields inherited from class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
engine -
Constructor Summary
ConstructorsConstructorDescriptionProtonTransactionController(ProtonSender senderLink) Creates a newTransactionControllerinstance that wraps the givenSenderlink. -
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.close()Close the end point locally and send the closing performative immediately if possible or holds it until the Connection / Engine state allows it.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 previousTransactionController.discharge(Transaction, boolean)request and the transaction has been retired.dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler) Called when theTransactionManagerend of the link has responded to a previousTransactionController.discharge(Transaction, boolean)request and the transaction discharge failed for some reason.Returns the currently set Coordinator target for thisLink.Symbol[]Symbol[]Gets the parent of thisEndpointwhich can be itself forConnectioninstance.If the remote has closed thisEndpointand provided anErrorConditionas part of the closing AMQP performative then this method will return it.Returns the remote targetTerminusfor this transaction controller which must be of typeCoordinatoror null if remote did not set a terminus.Symbol[]Symbol[]booleanReturnstrueif theTransactionControllerhas capacity to send or buffer andTransactioncommand toDeclareorDischarge.booleanReturns true if thisEndpointis currently locally closed meaning that a call to theEndpoint.close()method has occurred.booleanReturns true if thisEndpointis currently locally open meaning that theEndpoint.open()has been called but theEndpoint.close()has not.booleanbooleanorg.apache.qpid.protonj2.engine.impl.ProtonTransactionController.ProtonControllerTransactionCreates a newTransactioninstances that is returned in theTransactionState.IDLEstate which can be populated with application specific attachments or assigned a linked resource prior to calling theopen()Open the end point locally, sending the Open performative immediately if possible or holding it until SASL negotiations or the AMQP header exchange and other required performative exchanges has completed.Sets aEventHandlerfor when the parentSessionorConnectionof thisTransactionControlleris locally closed.setCondition(ErrorCondition condition) Sets the localErrorConditionto be applied to aEndpointclose.setCoordinator(Coordinator coordinator) Sets theCoordinatortarget to assign to the local end of thisTransactionController.setDesiredCapabilities(Symbol... desiredCapabilities) Sets the capabilities that are desired from the remote when thisEndpointis opened.setOfferedCapabilities(Symbol... offeredCapabilities) Sets the capabilities to be offered on to the remote when thisEndpointis opened.setProperties(Map<Symbol, Object> properties) Sets the properties to be sent to the remote when thisEndpointis Opened.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 class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
closeHandler, engineShutdownHandler, getAttachments, getEngine, getLinkedResource, getLinkedResource, localCloseHandler, localOpenHandler, openHandler, setLinkedResourceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.qpid.protonj2.engine.Endpoint
closeHandler, engineShutdownHandler, getAttachments, getEngine, getLinkedResource, getLinkedResource, localCloseHandler, localOpenHandler, openHandler, setLinkedResource
-
Constructor Details
-
ProtonTransactionController
Creates a newTransactionControllerinstance that wraps the givenSenderlink.- Parameters:
senderLink- TheSenderthat thisTransactionControllerwraps.
-
-
Method Details
-
getParent
Description copied from interface:EndpointGets the parent of thisEndpointwhich can be itself forConnectioninstance.- Specified by:
getParentin interfaceEndpoint<TransactionController>- Returns:
- the parent of this
Endpointor itself if this is aConnection;
-
hasCapacity
public boolean hasCapacity()Description copied from interface:TransactionControllerReturnstrueif theTransactionControllerhas capacity to send or buffer andTransactioncommand toDeclareorDischarge. If no capacity then a call toTransactionController.declare()or toTransactionController.discharge(Transaction, boolean)would throw an exception.- Specified by:
hasCapacityin interfaceTransactionController- Returns:
- true if the controller will allow declaring or discharging a transaction at this time.
-
addCapacityAvailableHandler
public ProtonTransactionController addCapacityAvailableHandler(EventHandler<TransactionController> handler) Description copied from interface:TransactionControllerAllows 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.- Specified by:
addCapacityAvailableHandlerin interfaceTransactionController- Parameters:
handler- TheEventHandlerthat will be signaled once credit is available for transaction work.- Returns:
- this
TransactionControllerinstance.
-
transactions
Description copied from interface:TransactionControllerReturns 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.- Specified by:
transactionsin interfaceTransactionController- Returns:
- a list of Transactions that are allocated to this controller that have not reached a terminal state.
-
newTransaction
public org.apache.qpid.protonj2.engine.impl.ProtonTransactionController.ProtonControllerTransaction newTransaction()Description copied from interface:TransactionControllerCreates 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- Specified by:
newTransactionin interfaceTransactionController- Returns:
- a new
Transactioninstance that can be correlated with later declared events.
-
declare
Description copied from interface:TransactionControllerRequest 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 theTransactionController.declaredHandler(EventHandler)event handler will be signaled. This is a convenience method that is the same as first callingTransactionController.newTransaction()and then passing the result of that to theTransactionController.declare(Transaction)method.- Specified by:
declarein interfaceTransactionController- Returns:
- a new
Transactioninstance that can be correlated with later declared events.
-
declare
Description copied from interface:TransactionControllerRequest 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 theTransactionController.declaredHandler(EventHandler)event handler will be signaled.- Specified by:
declarein interfaceTransactionController- Parameters:
transaction- TheTransactionthat is will be associated with the eventual declared transaction.- Returns:
- this
TransactionController
-
discharge
public TransactionController discharge(Transaction<TransactionController> transaction, boolean failed) Description copied from interface:TransactionControllerRequest 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 theTransactionController.declaredHandler(EventHandler)event handler will be signaled.- Specified by:
dischargein interfaceTransactionController- Parameters:
transaction- TheTransactionthat is being discharged.failed- boolean value indicating the the discharge indicates the transaction failed (rolled back).- Returns:
- this
TransactionController
-
declaredHandler
public TransactionController declaredHandler(EventHandler<Transaction<TransactionController>> declaredEventHandler) Description copied from interface:TransactionControllerCalled when theTransactionManagerend of the link has responded to a previousDeclarerequest and the transaction can now be used to enroll deliveries into the active transaction.- Specified by:
declaredHandlerin interfaceTransactionController- Parameters:
declaredEventHandler- AnEventHandlerthat will act on the transaction declaration request.- Returns:
- this
TransactionController.
-
declareFailureHandler
public TransactionController declareFailureHandler(EventHandler<Transaction<TransactionController>> declareFailureEventHandler) Description copied from interface:TransactionControllerCalled when theTransactionManagerend of the link responds to aTransactiondeclaration with anRejectedoutcome indicating that the transaction could not be successfully declared.- Specified by:
declareFailureHandlerin interfaceTransactionController- Parameters:
declareFailureEventHandler- AnEventHandlerthat will be called when a previous transaction declaration fails.- Returns:
- this
TransactionController.
-
dischargedHandler
public TransactionController dischargedHandler(EventHandler<Transaction<TransactionController>> dischargedEventHandler) Description copied from interface:TransactionControllerCalled when theTransactionManagerend of the link has responded to a previousTransactionController.discharge(Transaction, boolean)request and the transaction has been retired.- Specified by:
dischargedHandlerin interfaceTransactionController- Parameters:
dischargedEventHandler- AnEventHandlerthat will act on the transaction discharge request.- Returns:
- this
TransactionController.
-
dischargeFailureHandler
public TransactionController dischargeFailureHandler(EventHandler<Transaction<TransactionController>> dischargeFailureEventHandler) Description copied from interface:TransactionControllerCalled when theTransactionManagerend of the link has responded to a previousTransactionController.discharge(Transaction, boolean)request and the transaction discharge failed for some reason.- Specified by:
dischargeFailureHandlerin interfaceTransactionController- Parameters:
dischargeFailureEventHandler- AnEventHandlerthat will act on the transaction discharge failed event.- Returns:
- this
TransactionController.
-
parentEndpointClosedHandler
public TransactionController parentEndpointClosedHandler(EventHandler<TransactionController> handler) Description copied from interface:TransactionControllerSets 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.- Specified by:
parentEndpointClosedHandlerin interfaceTransactionController- Parameters:
handler- TheEventHandlerto notify when this transaction controller's parent endpoint is locally closed.- Returns:
- the link for chaining.
-
open
Description copied from interface:EndpointOpen the end point locally, sending the Open performative immediately if possible or holding it until SASL negotiations or the AMQP header exchange and other required performative exchanges has completed. The end point will signal any registered handler of the remote opening the Connection once the remote performative that signals open completion arrives.- Specified by:
openin interfaceEndpoint<TransactionController>- Returns:
- this
Endpointinstance. - Throws:
EngineStateException- if an error occurs opening the Connection or the Engine is shutdown.IllegalStateException
-
close
Description copied from interface:EndpointClose the end point locally and send the closing performative immediately if possible or holds it until the Connection / Engine state allows it. If the engine encounters an error writing the performative or the engine is in a failed state from a previous error then this method will throw an exception. If the engine has been shutdown then this method will close out the local end of theEndpointand clean up any local resources before returning normally.- Specified by:
closein interfaceEndpoint<TransactionController>- Returns:
- this
Endpointinstance. - Throws:
EngineFailedException- if an error occurs closing the end point or the Engine is in a failed state.
-
isLocallyOpen
public boolean isLocallyOpen()Description copied from interface:EndpointReturns true if thisEndpointis currently locally open meaning that theEndpoint.open()has been called but theEndpoint.close()has not.- Specified by:
isLocallyOpenin interfaceEndpoint<TransactionController>- Returns:
trueif theEndpointis locally open.- See Also:
-
isLocallyClosed
public boolean isLocallyClosed()Description copied from interface:EndpointReturns true if thisEndpointis currently locally closed meaning that a call to theEndpoint.close()method has occurred.- Specified by:
isLocallyClosedin interfaceEndpoint<TransactionController>- Returns:
trueif theEndpointis locally closed.- See Also:
-
setSource
Description copied from interface:TransactionControllerSets theSourceto assign to the local end of thisTransactionController. Must be called during setup, i.e. before calling theEndpoint.open()method.- Specified by:
setSourcein interfaceTransactionController- 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
- Specified by:
getSourcein interfaceTransactionController- Returns:
- the
Sourcefor the local end of thisTransactionController.
-
setCoordinator
Description copied from interface:TransactionControllerSets theCoordinatortarget to assign to the local end of thisTransactionController. Must be called during setup, i.e. before calling theEndpoint.open()method.- Specified by:
setCoordinatorin interfaceTransactionController- 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
Description copied from interface:TransactionControllerReturns the currently set Coordinator target for thisLink.- Specified by:
getCoordinatorin interfaceTransactionController- Returns:
- the link target
Coordinatorfor the local end of this link.
-
getCondition
- Specified by:
getConditionin interfaceEndpoint<TransactionController>- Overrides:
getConditionin classProtonEndpoint<TransactionController>- Returns:
- the local
Endpointerror, or null if there is none
-
setCondition
Description copied from interface:EndpointSets the localErrorConditionto be applied to aEndpointclose.- Specified by:
setConditionin interfaceEndpoint<TransactionController>- Overrides:
setConditionin classProtonEndpoint<TransactionController>- Parameters:
condition- The error condition to convey to the remote peer on close of this end point.- Returns:
- this
Endpointinstance.
-
getProperties
- Specified by:
getPropertiesin interfaceEndpoint<TransactionController>- Returns:
- the configured properties sent to the remote when this Connection is opened.
-
setProperties
public TransactionController setProperties(Map<Symbol, Object> properties) throws IllegalStateExceptionDescription copied from interface:EndpointSets the properties to be sent to the remote when thisEndpointis Opened. TheEndpointproperties value can only be modified prior to a call toEndpoint.open(), once theEndpointhas been opened locally an error will be thrown if this method is called.- Specified by:
setPropertiesin interfaceEndpoint<TransactionController>- Parameters:
properties- The properties that will be sent to the remote when this Connection is opened.- Returns:
- this
Endpointinstance. - Throws:
IllegalStateException- if theEndpointhas already been opened.
-
setOfferedCapabilities
public TransactionController setOfferedCapabilities(Symbol... offeredCapabilities) throws IllegalStateException Description copied from interface:EndpointSets the capabilities to be offered on to the remote when thisEndpointis opened. The offered capabilities value can only be modified prior to a call toEndpoint.open(), once theEndpointhas been opened locally an error will be thrown if this method is called.- Specified by:
setOfferedCapabilitiesin interfaceEndpoint<TransactionController>- Parameters:
offeredCapabilities- The capabilities to be offered to the remote when theEndpointis opened.- Returns:
- this
Endpointinstance. - Throws:
IllegalStateException- if theEndpointhas already been opened.
-
getOfferedCapabilities
- Specified by:
getOfferedCapabilitiesin interfaceEndpoint<TransactionController>- Returns:
- the configured capabilities that are offered to the remote when the
Endpointis opened.
-
setDesiredCapabilities
public TransactionController setDesiredCapabilities(Symbol... desiredCapabilities) throws IllegalStateException Description copied from interface:EndpointSets the capabilities that are desired from the remote when thisEndpointis opened. The desired capabilities value can only be modified prior to a call toEndpoint.open(), once theEndpointhas been opened locally an error will be thrown if this method is called.- Specified by:
setDesiredCapabilitiesin interfaceEndpoint<TransactionController>- Parameters:
desiredCapabilities- The capabilities desired from the remote when theEndpointis opened.- Returns:
- this
Endpointinstance. - Throws:
IllegalStateException- if theEndpointhas already been opened.
-
getDesiredCapabilities
- Specified by:
getDesiredCapabilitiesin interfaceEndpoint<TransactionController>- Returns:
- the configured desired capabilities that are sent to the remote when the Connection is opened.
-
isRemotelyOpen
public boolean isRemotelyOpen()Description copied from interface:EndpointReturns true if thisEndpointis currently remotely open meaning that the AMQP performative that completes the open phase of thisEndpoint's lifetime has arrived but the performative that closes it has not.- Specified by:
isRemotelyOpenin interfaceEndpoint<TransactionController>- Returns:
trueif theEndpointis remotely open.- See Also:
-
isRemotelyClosed
public boolean isRemotelyClosed()Description copied from interface:EndpointReturns true if thisEndpointis currently remotely closed meaning that the AMQP performative that completes the close phase of thisEndpoint's lifetime has arrived.- Specified by:
isRemotelyClosedin interfaceEndpoint<TransactionController>- Returns:
trueif theEndpointis remotely closed.- See Also:
-
getRemoteOfferedCapabilities
- Specified by:
getRemoteOfferedCapabilitiesin interfaceEndpoint<TransactionController>- Returns:
- the capabilities offered by the remote when it opened its end of the
Endpoint.
-
getRemoteDesiredCapabilities
- Specified by:
getRemoteDesiredCapabilitiesin interfaceEndpoint<TransactionController>- Returns:
- the capabilities desired by the remote when it opened its end of the
Endpoint.
-
getRemoteProperties
- Specified by:
getRemotePropertiesin interfaceEndpoint<TransactionController>- Returns:
- the properties sent by the remote when it opened its end of the
Endpoint.
-
getRemoteCondition
Description copied from interface:EndpointIf the remote has closed thisEndpointand provided anErrorConditionas part of the closing AMQP performative then this method will return it.- Specified by:
getRemoteConditionin interfaceEndpoint<TransactionController>- Overrides:
getRemoteConditionin classProtonEndpoint<TransactionController>- Returns:
- the remote supplied
ErrorCondition, or null if there is none.
-
getRemoteSource
- Specified by:
getRemoteSourcein interfaceTransactionController- Returns:
- the source
Sourcefor the remote end of thisTransactionController.
-
getRemoteCoordinator
Description copied from interface:TransactionControllerReturns the remote targetTerminusfor this transaction controller which must be of typeCoordinatoror null if remote did not set a terminus.- Specified by:
getRemoteCoordinatorin interfaceTransactionController- Returns:
- the remote coordinator
Terminusfor the remote end of this link.
-