Class ProtonLink<L extends Link<L>>
- java.lang.Object
-
- org.apache.qpid.protonj2.engine.impl.ProtonEndpoint<L>
-
- org.apache.qpid.protonj2.engine.impl.ProtonLink<L>
-
- Direct Known Subclasses:
ProtonReceiver
,ProtonSender
public abstract class ProtonLink<L extends Link<L>> extends ProtonEndpoint<L> implements Link<L>
Common base for Proton Senders and Receivers.
-
-
Field Summary
Fields Modifier and Type Field Description protected ProtonConnection
connection
protected Attach
localAttach
protected Attach
remoteAttach
protected ProtonSession
session
-
Fields inherited from class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
engine
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ProtonLink(ProtonSession session, String name, ProtonLinkCreditState creditState)
Create a new link instance with the given parent session.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
areDeliveriesStillActive()
protected void
checkLinkOperable(String failurePrefix)
protected void
checkNotClosed(String errorMessage)
protected void
checkNotOpened(String errorMessage)
L
close()
Close the end point locally and send the closing performative immediately if possible or holds it until the Connection / Engine state allows it.protected abstract L
decorateOutgoingFlow(Flow flow)
L
detach()
Detach this end of the link.L
detachHandler(EventHandler<L> remoteDetachHandler)
Sets aEventHandler
for when an AMQP Detach frame is received from the remote peer for thisLink
which would have been locally opened previously, the Detach from would have been marked as not having been closed.ProtonConnection
getConnection()
Symbol[]
getDesiredCapabilities()
UnsignedLong
getMaxMessageSize()
Gets the local link max message size.String
getName()
Symbol[]
getOfferedCapabilities()
ProtonSession
getParent()
Gets the parent of thisEndpoint
which can be itself forConnection
instance.Map<Symbol,Object>
getProperties()
ReceiverSettleMode
getReceiverSettleMode()
Gets the local link receiver settlement mode.Symbol[]
getRemoteDesiredCapabilities()
UnsignedLong
getRemoteMaxMessageSize()
Gets the remote link max message size, as conveyed from the peer via the Attach frame when attaching the link to the session.Symbol[]
getRemoteOfferedCapabilities()
Map<Symbol,Object>
getRemoteProperties()
ReceiverSettleMode
getRemoteReceiverSettleMode()
Gets the remote link receiver settlement mode, as conveyed from the peer via the Attach frame when attaching the link to the session.SenderSettleMode
getRemoteSenderSettleMode()
Gets the remote link sender settlement mode, as conveyed from the peer via the Attach frame when attaching the link to the session.Source
getRemoteSource()
LinkState
getRemoteState()
<T extends Terminus>
TgetRemoteTarget()
Returns the remote targetTerminus
cast to the given type.SenderSettleMode
getSenderSettleMode()
Gets the local link sender settlement mode.ProtonSession
getSession()
Source
getSource()
LinkState
getState()
<T extends Terminus>
TgetTarget()
Returns the currently set Target for thisLink
.protected abstract L
handleRemoteAttach(Attach attach)
protected abstract L
handleRemoteDetach(Detach detach)
protected abstract L
handleRemoteDisposition(Disposition disposition, ProtonIncomingDelivery delivery)
protected abstract L
handleRemoteDisposition(Disposition disposition, ProtonOutgoingDelivery delivery)
protected abstract L
handleRemoteFlow(Flow flow)
protected abstract ProtonIncomingDelivery
handleRemoteTransfer(Transfer transfer, ProtonBuffer payload)
boolean
isLocallyClosed()
Returns true if thisEndpoint
is currently locally closed meaning that a call to theEndpoint.close()
method has occurred.boolean
isLocallyClosedOrDetached()
Returns true if thisLink
is currently locally detached or locally closed meaning the state returned fromLink.getState()
is equal toLinkState.DETACHED
orLinkState.CLOSED
.boolean
isLocallyDetached()
Returns true if thisLink
is currently locally detached meaning the state returned fromLink.getState()
is equal toLinkState.DETACHED
.boolean
isLocallyOpen()
Returns true if thisEndpoint
is currently locally open meaning that theEndpoint.open()
has been called but theEndpoint.close()
has not.boolean
isReceiver()
boolean
isRemotelyClosed()
Returns true if thisLink
is currently remotely closed meaning the state returned fromLink.getRemoteState()
is equal toLinkState.CLOSED
.boolean
isRemotelyClosedOrDetached()
Returns true if thisLink
is currently remotely detached or closed meaning the state returned fromLink.getRemoteState()
is equal toLinkState.DETACHED
orLinkState.CLOSED
.boolean
isRemotelyDetached()
Returns true if thisLink
is currently remotely detached meaning the state returned fromLink.getRemoteState()
is equal toLinkState.DETACHED
.boolean
isRemotelyOpen()
Returns true if thisLink
is currently remotely open meaning the state returned fromLink.getRemoteState()
is equal toLinkState.ACTIVE
.boolean
isSender()
L
localDetachHandler(EventHandler<L> localDetachHandler)
Sets aEventHandler
for when an this link is detached locally via a call toLink.detach()
This is a convenience event that supplements the normalEndpoint.localCloseHandler(EventHandler)
event point if set.L
open()
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.L
parentEndpointClosedHandler(EventHandler<L> handler)
protected abstract L
self()
L
setDesiredCapabilities(Symbol... capabilities)
Sets the capabilities that are desired from the remote when thisEndpoint
is opened.L
setMaxMessageSize(UnsignedLong maxMessageSize)
Sets the local link max message size, to be conveyed to the peer via the Attach frame when attaching the link to the session.L
setOfferedCapabilities(Symbol... capabilities)
Sets the capabilities to be offered on to the remote when thisEndpoint
is opened.L
setProperties(Map<Symbol,Object> properties)
Sets the properties to be sent to the remote when thisEndpoint
is Opened.L
setReceiverSettleMode(ReceiverSettleMode receiverSettleMode)
Sets the receiver settle mode.L
setSenderSettleMode(SenderSettleMode senderSettleMode)
Sets the sender settle mode.L
setSource(Source source)
L
setTarget(Target target)
L
setTarget(Coordinator coordinator)
Sets theCoordinator
target to assign to the local end of thisLink
.protected void
transitionedToLocallyClosed()
protected void
transitionedToLocallyDetached()
protected void
transitionedToLocallyOpened()
protected void
transitionToParentLocallyClosed()
protected void
transitionToParentRemotelyClosed()
protected void
transitionToRemotelyClosed()
protected void
transitionToRemotelyDetached()
protected void
transitionToRemotelyOpenedState()
-
Methods inherited from class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
closeHandler, engineShutdownHandler, getAttachments, getCondition, getEngine, getLinkedResource, getLinkedResource, getRemoteCondition, localCloseHandler, localOpenHandler, openHandler, setCondition, setLinkedResource
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.qpid.protonj2.engine.Endpoint
closeHandler, engineShutdownHandler, getAttachments, getCondition, getEngine, getLinkedResource, getLinkedResource, getRemoteCondition, localCloseHandler, localOpenHandler, openHandler, setCondition, setLinkedResource
-
Methods inherited from interface org.apache.qpid.protonj2.engine.Link
creditStateUpdateHandler, getCredit, getRole, isDraining
-
-
-
-
Field Detail
-
connection
protected final ProtonConnection connection
-
session
protected final ProtonSession session
-
localAttach
protected final Attach localAttach
-
remoteAttach
protected Attach remoteAttach
-
-
Constructor Detail
-
ProtonLink
protected ProtonLink(ProtonSession session, String name, ProtonLinkCreditState creditState)
Create a new link instance with the given parent session.
-
-
Method Detail
-
getConnection
public ProtonConnection getConnection()
- Specified by:
getConnection
in interfaceLink<L extends Link<L>>
- Returns:
- the parent
Connection
for theLink
-
getSession
public ProtonSession getSession()
-
getParent
public ProtonSession getParent()
Description copied from interface:Endpoint
Gets the parent of thisEndpoint
which can be itself forConnection
instance.
-
getName
public String getName()
-
isSender
public boolean isSender()
-
isReceiver
public boolean isReceiver()
-
self
protected abstract L self()
-
getState
public LinkState getState()
-
getRemoteState
public LinkState getRemoteState()
- Specified by:
getRemoteState
in interfaceLink<L extends Link<L>>
- Returns:
- the remote link state (as last communicated)
-
open
public L open()
Description copied from interface:Endpoint
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. The end point will signal any registered handler of the remote opening the Connection once the remote performative that signals open completion arrives.
-
close
public L close()
Description copied from interface:Endpoint
Close 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 theEndpoint
and clean up any local resources before returning normally.
-
setSenderSettleMode
public L setSenderSettleMode(SenderSettleMode senderSettleMode)
Description copied from interface:Link
Sets the sender settle mode.Should only be called during link set-up, i.e. before calling
Endpoint.open()
. If this endpoint is the initiator of the link, this method can be used to set a value other than the default.If this endpoint is not the initiator, this method should be used to set a local value. According to the AMQP spec, the application may choose to accept the sender's suggestion (accessed by calling
Link.getRemoteSenderSettleMode()
) or choose another value. The value has no effect on Proton, but may be useful to the application at a later point.In order to be AMQP compliant the application is responsible for honoring the settlement mode. See
Link
.- Specified by:
setSenderSettleMode
in interfaceLink<L extends Link<L>>
- Parameters:
senderSettleMode
- TheSenderSettleMode
that will be set on the local end of this link.- Returns:
- this Link.
-
getSenderSettleMode
public SenderSettleMode getSenderSettleMode()
Description copied from interface:Link
Gets the local link sender settlement mode.- Specified by:
getSenderSettleMode
in interfaceLink<L extends Link<L>>
- Returns:
- the local sender settlement mode, or null if none was set.
- See Also:
Link.setSenderSettleMode(SenderSettleMode)
-
setReceiverSettleMode
public L setReceiverSettleMode(ReceiverSettleMode receiverSettleMode)
Description copied from interface:Link
Sets the receiver settle mode.Should only be called during link set-up, i.e. before calling
Endpoint.open()
. If this endpoint is the initiator of the link, this method can be used to set a value other than the default. Used in analogous way toLink.setSenderSettleMode(SenderSettleMode)
- Specified by:
setReceiverSettleMode
in interfaceLink<L extends Link<L>>
- Parameters:
receiverSettleMode
- TheReceiverSettleMode
that will be set on the local end of this link.- Returns:
- this Link.
-
getReceiverSettleMode
public ReceiverSettleMode getReceiverSettleMode()
Description copied from interface:Link
Gets the local link receiver settlement mode.- Specified by:
getReceiverSettleMode
in interfaceLink<L extends Link<L>>
- Returns:
- the local receiver settlement mode, or null if none was set.
- See Also:
Link.setReceiverSettleMode(ReceiverSettleMode)
-
setSource
public L setSource(Source source)
Description copied from interface:Link
Sets theSource
to assign to the local end of thisLink
.Must be called during link setup, i.e. before calling the
Endpoint.open()
method.
-
getSource
public Source getSource()
-
setTarget
public L setTarget(Target target)
Description copied from interface:Link
Sets theTarget
to assign to the local end of thisLink
. Must be called during link setup, i.e. before calling theEndpoint.open()
method.
-
setTarget
public L setTarget(Coordinator coordinator) throws IllegalStateException
Description copied from interface:Link
Sets theCoordinator
target to assign to the local end of thisLink
.Must be called during link setup, i.e. before calling the
Endpoint.open()
method.- Specified by:
setTarget
in interfaceLink<L extends Link<L>>
- Parameters:
coordinator
- TheCoordinator
target that will be set on the local end of this link.- Returns:
- this Link.
- Throws:
IllegalStateException
- if theLink
has already been opened.
-
getTarget
public <T extends Terminus> T getTarget()
Description copied from interface:Link
Returns the currently set Target for thisLink
. A link target can be either aTarget
type for aSender
orReceiver
link or if the link is to be transaction resource then the target type will be aCoordinator
instance.
-
setProperties
public L setProperties(Map<Symbol,Object> properties)
Description copied from interface:Endpoint
Sets the properties to be sent to the remote when thisEndpoint
is Opened. TheEndpoint
properties value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.
-
getProperties
public Map<Symbol,Object> getProperties()
- Specified by:
getProperties
in interfaceEndpoint<L extends Link<L>>
- Returns:
- the configured properties sent to the remote when this Connection is opened.
-
setOfferedCapabilities
public L setOfferedCapabilities(Symbol... capabilities)
Description copied from interface:Endpoint
Sets the capabilities to be offered on to the remote when thisEndpoint
is opened. The offered capabilities value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.
-
getOfferedCapabilities
public Symbol[] getOfferedCapabilities()
-
setDesiredCapabilities
public L setDesiredCapabilities(Symbol... capabilities)
Description copied from interface:Endpoint
Sets the capabilities that are desired from the remote when thisEndpoint
is opened. The desired capabilities value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.
-
getDesiredCapabilities
public Symbol[] getDesiredCapabilities()
- Specified by:
getDesiredCapabilities
in interfaceEndpoint<L extends Link<L>>
- Returns:
- the configured desired capabilities that are sent to the remote when the Connection is opened.
-
setMaxMessageSize
public L setMaxMessageSize(UnsignedLong maxMessageSize)
Description copied from interface:Link
Sets the local link max message size, to be conveyed to the peer via the Attach frame when attaching the link to the session. Null or 0 means no limit.Must be called during link setup, i.e. before calling the
Endpoint.open()
method.- Specified by:
setMaxMessageSize
in interfaceLink<L extends Link<L>>
- Parameters:
maxMessageSize
- the local max message size value, or null to clear. 0 also means no limit.- Returns:
- this Link.
-
getMaxMessageSize
public UnsignedLong getMaxMessageSize()
Description copied from interface:Link
Gets the local link max message size.- Specified by:
getMaxMessageSize
in interfaceLink<L extends Link<L>>
- Returns:
- the local max message size, or null if none was set. 0 also means no limit.
- See Also:
Link.setMaxMessageSize(UnsignedLong)
-
isLocallyOpen
public boolean isLocallyOpen()
Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently locally open meaning that theEndpoint.open()
has been called but theEndpoint.close()
has not.- Specified by:
isLocallyOpen
in interfaceEndpoint<L extends Link<L>>
- Returns:
true
if theEndpoint
is locally open.- See Also:
Endpoint.isLocallyClosed()
-
isLocallyClosed
public boolean isLocallyClosed()
Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently locally closed meaning that a call to theEndpoint.close()
method has occurred.- Specified by:
isLocallyClosed
in interfaceEndpoint<L extends Link<L>>
- Returns:
true
if theEndpoint
is locally closed.- See Also:
Endpoint.isLocallyOpen()
-
isLocallyDetached
public boolean isLocallyDetached()
Description copied from interface:Link
Returns true if thisLink
is currently locally detached meaning the state returned fromLink.getState()
is equal toLinkState.DETACHED
. A link is locally detached after a call toLink.detach()
.- Specified by:
isLocallyDetached
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is locally closed.
- See Also:
Endpoint.isLocallyOpen()
,Endpoint.isLocallyClosed()
-
isLocallyClosedOrDetached
public boolean isLocallyClosedOrDetached()
Description copied from interface:Link
Returns true if thisLink
is currently locally detached or locally closed meaning the state returned fromLink.getState()
is equal toLinkState.DETACHED
orLinkState.CLOSED
. A link is locally detached after a call toLink.detach()
and is locally closed after a call toEndpoint.close()
.- Specified by:
isLocallyClosedOrDetached
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is locally closed or detached.
- See Also:
Endpoint.isLocallyOpen()
,Link.isLocallyDetached()
,Endpoint.isLocallyClosed()
-
isRemotelyOpen
public boolean isRemotelyOpen()
Description copied from interface:Link
Returns true if thisLink
is currently remotely open meaning the state returned fromLink.getRemoteState()
is equal toLinkState.ACTIVE
. A link is remotely opened after anAttach
has been received from the remote and before aDetach
has been received from the remote.- Specified by:
isRemotelyOpen
in interfaceEndpoint<L extends Link<L>>
- Specified by:
isRemotelyOpen
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is remotely open.
- See Also:
Link.isRemotelyClosed()
,Link.isRemotelyDetached()
-
isRemotelyClosed
public boolean isRemotelyClosed()
Description copied from interface:Link
Returns true if thisLink
is currently remotely closed meaning the state returned fromLink.getRemoteState()
is equal toLinkState.CLOSED
. A link is remotely closed after anDetach
has been received from the remote with the close flag equal to true.- Specified by:
isRemotelyClosed
in interfaceEndpoint<L extends Link<L>>
- Specified by:
isRemotelyClosed
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is remotely closed.
- See Also:
Link.isRemotelyOpen()
,Link.isRemotelyDetached()
-
isRemotelyDetached
public boolean isRemotelyDetached()
Description copied from interface:Link
Returns true if thisLink
is currently remotely detached meaning the state returned fromLink.getRemoteState()
is equal toLinkState.DETACHED
. A link is remotely detached after anDetach
has been received from the remote with the close flag equal to false.- Specified by:
isRemotelyDetached
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is remotely detached.
- See Also:
Link.isRemotelyOpen()
,Link.isRemotelyClosed()
-
isRemotelyClosedOrDetached
public boolean isRemotelyClosedOrDetached()
Description copied from interface:Link
Returns true if thisLink
is currently remotely detached or closed meaning the state returned fromLink.getRemoteState()
is equal toLinkState.DETACHED
orLinkState.CLOSED
. A link is remotely detached or closed after aDetach
has been received from the remote.- Specified by:
isRemotelyClosedOrDetached
in interfaceLink<L extends Link<L>>
- Returns:
- true if the link is remotely detached or closed.
- See Also:
Link.isRemotelyOpen()
,Link.isRemotelyClosed()
,Link.isRemotelyDetached()
-
getRemoteSenderSettleMode
public SenderSettleMode getRemoteSenderSettleMode()
Description copied from interface:Link
Gets the remote link sender settlement mode, as conveyed from the peer via the Attach frame when attaching the link to the session.- Specified by:
getRemoteSenderSettleMode
in interfaceLink<L extends Link<L>>
- Returns:
- the sender settlement mode conveyed by the peer, or null if there was none.
- See Also:
Link.setSenderSettleMode(SenderSettleMode)
-
getRemoteReceiverSettleMode
public ReceiverSettleMode getRemoteReceiverSettleMode()
Description copied from interface:Link
Gets the remote link receiver settlement mode, as conveyed from the peer via the Attach frame when attaching the link to the session.- Specified by:
getRemoteReceiverSettleMode
in interfaceLink<L extends Link<L>>
- Returns:
- the sender receiver mode conveyed by the peer, or null if there was none.
- See Also:
Link.setReceiverSettleMode(ReceiverSettleMode)
-
getRemoteSource
public Source getRemoteSource()
-
getRemoteTarget
public <T extends Terminus> T getRemoteTarget()
Description copied from interface:Link
Returns the remote targetTerminus
cast to the given type. This can be used when the underlying type is known by the caller or as a control to validate the assumption of the underlying type.the currently set Target for this
Link
. A link target can be either aTarget
type for aSender
orReceiver
link or if the link is to be transaction resource then the target type will be aCoordinator
instance.
-
getRemoteOfferedCapabilities
public Symbol[] getRemoteOfferedCapabilities()
-
getRemoteDesiredCapabilities
public Symbol[] getRemoteDesiredCapabilities()
-
getRemoteMaxMessageSize
public UnsignedLong getRemoteMaxMessageSize()
Description copied from interface:Link
Gets the remote link max message size, as conveyed from the peer via the Attach frame when attaching the link to the session.- Specified by:
getRemoteMaxMessageSize
in interfaceLink<L extends Link<L>>
- Returns:
- the remote max message size conveyed by the peer, or null if none was set. 0 also means no limit.
-
localDetachHandler
public L localDetachHandler(EventHandler<L> localDetachHandler)
Description copied from interface:Link
Sets aEventHandler
for when an this link is detached locally via a call toLink.detach()
This is a convenience event that supplements the normalEndpoint.localCloseHandler(EventHandler)
event point if set. If no local detached event handler is set the endpoint will route the detached event to the local closed event handler if set and allow it to process the event in one location.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:
localDetachHandler
in interfaceLink<L extends Link<L>>
- Parameters:
localDetachHandler
- TheEventHandler
to notify when this link is locally detached.- Returns:
- the link for chaining.
-
detachHandler
public L detachHandler(EventHandler<L> remoteDetachHandler)
Description copied from interface:Link
Sets aEventHandler
for when an AMQP Detach frame is received from the remote peer for thisLink
which would have been locally opened previously, the Detach from would have been marked as not having been closed.This is a convenience event that supplements the normal
Endpoint.closeHandler(EventHandler)
event point if set. If no detached event handler is set the endpoint will route the detached event to the closed event handler if set and allow it to process the event in one location.- Specified by:
detachHandler
in interfaceLink<L extends Link<L>>
- Parameters:
remoteDetachHandler
- TheEventHandler
to notify when this link is remotely closed.- Returns:
- the
Link
for chaining.
-
parentEndpointClosedHandler
public L parentEndpointClosedHandler(EventHandler<L> handler)
Description copied from interface:Link
Sets aEventHandler
for when the parentSession
orConnection
of this link 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.
- Specified by:
parentEndpointClosedHandler
in interfaceLink<L extends Link<L>>
- Parameters:
handler
- TheEventHandler
to notify when this link's parent Session is locally closed.- Returns:
- the link for chaining.
-
transitionedToLocallyOpened
protected void transitionedToLocallyOpened()
-
transitionedToLocallyDetached
protected void transitionedToLocallyDetached()
-
transitionedToLocallyClosed
protected void transitionedToLocallyClosed()
-
transitionToRemotelyOpenedState
protected void transitionToRemotelyOpenedState()
-
transitionToRemotelyDetached
protected void transitionToRemotelyDetached()
-
transitionToRemotelyClosed
protected void transitionToRemotelyClosed()
-
transitionToParentLocallyClosed
protected void transitionToParentLocallyClosed()
-
transitionToParentRemotelyClosed
protected void transitionToParentRemotelyClosed()
-
handleRemoteDisposition
protected abstract L handleRemoteDisposition(Disposition disposition, ProtonOutgoingDelivery delivery)
-
handleRemoteDisposition
protected abstract L handleRemoteDisposition(Disposition disposition, ProtonIncomingDelivery delivery)
-
handleRemoteTransfer
protected abstract ProtonIncomingDelivery handleRemoteTransfer(Transfer transfer, ProtonBuffer payload)
-
checkLinkOperable
protected void checkLinkOperable(String failurePrefix)
-
areDeliveriesStillActive
protected boolean areDeliveriesStillActive()
-
checkNotOpened
protected void checkNotOpened(String errorMessage)
-
checkNotClosed
protected void checkNotClosed(String errorMessage)
-
-