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>
Type Parameters:
L - the type of link, Sender or Receiver.
All Implemented Interfaces:
Endpoint<L>, Link<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 Details

  • Constructor Details

    • ProtonLink

      protected ProtonLink(ProtonSession session, String name, ProtonLinkCreditState creditState)
      Create a new link instance with the given parent session.
      Parameters:
      session - The Session that this link resides within.
      name - The name assigned to this Link
      creditState - The link credit state used to track credit for the link.
  • Method Details

    • getConnection

      public ProtonConnection getConnection()
      Specified by:
      getConnection in interface Link<L extends Link<L>>
      Returns:
      the parent Connection for the Link
    • getSession

      public ProtonSession getSession()
      Specified by:
      getSession in interface Link<L extends Link<L>>
      Returns:
      the parent Session of the Link
    • getParent

      public ProtonSession getParent()
      Description copied from interface: Endpoint
      Gets the parent of this Endpoint which can be itself for Connection instance.
      Specified by:
      getParent in interface Endpoint<L extends Link<L>>
      Specified by:
      getParent in interface Link<L extends Link<L>>
      Returns:
      the parent Session of the Link
    • getName

      public String getName()
      Specified by:
      getName in interface Link<L extends Link<L>>
      Returns:
      the link name that is assigned to this Link
    • isSender

      public boolean isSender()
      Specified by:
      isSender in interface Link<L extends Link<L>>
      Returns:
      true if this link is acting in a sender Role.
    • isReceiver

      public boolean isReceiver()
      Specified by:
      isReceiver in interface Link<L extends Link<L>>
      Returns:
      true if this link is acting in a receiver Role.
    • self

      protected abstract L self()
    • getState

      public LinkState getState()
      Specified by:
      getState in interface Link<L extends Link<L>>
      Returns:
      the local link state
    • getRemoteState

      public LinkState getRemoteState()
      Specified by:
      getRemoteState in interface Link<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.
      Specified by:
      open in interface Endpoint<L extends Link<L>>
      Returns:
      this Endpoint instance.
    • detach

      public L detach()
      Description copied from interface: Link
      Detach this end of the link.
      Specified by:
      detach in interface Link<L extends Link<L>>
      Returns:
      this Link.
    • 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 the Endpoint and clean up any local resources before returning normally.
      Specified by:
      close in interface Endpoint<L extends Link<L>>
      Returns:
      this Endpoint instance.
    • 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 interface Link<L extends Link<L>>
      Parameters:
      senderSettleMode - The SenderSettleMode 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 interface Link<L extends Link<L>>
      Returns:
      the local sender settlement mode, or null if none was set.
      See Also:
    • 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 to Link.setSenderSettleMode(SenderSettleMode)

      Specified by:
      setReceiverSettleMode in interface Link<L extends Link<L>>
      Parameters:
      receiverSettleMode - The ReceiverSettleMode 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 interface Link<L extends Link<L>>
      Returns:
      the local receiver settlement mode, or null if none was set.
      See Also:
    • setSource

      public L setSource(Source source)
      Description copied from interface: Link
      Sets the Source to assign to the local end of this Link.

      Must be called during link setup, i.e. before calling the Endpoint.open() method.

      Specified by:
      setSource in interface Link<L extends Link<L>>
      Parameters:
      source - The Source that will be set on the local end of this link.
      Returns:
      this Link.
    • getSource

      public Source getSource()
      Specified by:
      getSource in interface Link<L extends Link<L>>
      Returns:
      the Source for the local end of this link.
    • setTarget

      public L setTarget(Target target)
      Description copied from interface: Link
      Sets the Target to assign to the local end of this Link. Must be called during link setup, i.e. before calling the Endpoint.open() method.
      Specified by:
      setTarget in interface Link<L extends Link<L>>
      Parameters:
      target - The Target that will be set on the local end of this link.
      Returns:
      this Link.
    • setTarget

      public L setTarget(Coordinator coordinator) throws IllegalStateException
      Description copied from interface: Link
      Sets the Coordinator target to assign to the local end of this Link.

      Must be called during link setup, i.e. before calling the Endpoint.open() method.

      Specified by:
      setTarget in interface Link<L extends Link<L>>
      Parameters:
      coordinator - The Coordinator target that will be set on the local end of this link.
      Returns:
      this Link.
      Throws:
      IllegalStateException - if the Link has already been opened.
    • getTarget

      public <T extends Terminus> T getTarget()
      Description copied from interface: Link
      Returns the currently set Target for this Link. A link target can be either a Target type for a Sender or Receiver link or if the link is to be transaction resource then the target type will be a Coordinator instance.
      Specified by:
      getTarget in interface Link<L extends Link<L>>
      Type Parameters:
      T - The terminus type that the target should be cast to on return.
      Returns:
      the link target Terminus for the local end of this link.
    • setProperties

      public L setProperties(Map<Symbol,Object> properties)
      Description copied from interface: Endpoint
      Sets the properties to be sent to the remote when this Endpoint is Opened. The Endpoint properties value can only be modified prior to a call to Endpoint.open(), once the Endpoint has been opened locally an error will be thrown if this method is called.
      Specified by:
      setProperties in interface Endpoint<L extends Link<L>>
      Parameters:
      properties - The properties that will be sent to the remote when this Connection is opened.
      Returns:
      this Endpoint instance.
    • getProperties

      public Map<Symbol,Object> getProperties()
      Specified by:
      getProperties in interface Endpoint<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 this Endpoint is opened. The offered capabilities value can only be modified prior to a call to Endpoint.open(), once the Endpoint has been opened locally an error will be thrown if this method is called.
      Specified by:
      setOfferedCapabilities in interface Endpoint<L extends Link<L>>
      Parameters:
      capabilities - The capabilities to be offered to the remote when the Endpoint is opened.
      Returns:
      this Endpoint instance.
    • getOfferedCapabilities

      public Symbol[] getOfferedCapabilities()
      Specified by:
      getOfferedCapabilities in interface Endpoint<L extends Link<L>>
      Returns:
      the configured capabilities that are offered to the remote when the Endpoint is opened.
    • setDesiredCapabilities

      public L setDesiredCapabilities(Symbol... capabilities)
      Description copied from interface: Endpoint
      Sets the capabilities that are desired from the remote when this Endpoint is opened. The desired capabilities value can only be modified prior to a call to Endpoint.open(), once the Endpoint has been opened locally an error will be thrown if this method is called.
      Specified by:
      setDesiredCapabilities in interface Endpoint<L extends Link<L>>
      Parameters:
      capabilities - The capabilities desired from the remote when the Endpoint is opened.
      Returns:
      this Endpoint instance.
    • getDesiredCapabilities

      public Symbol[] getDesiredCapabilities()
      Specified by:
      getDesiredCapabilities in interface Endpoint<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 interface Link<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 interface Link<L extends Link<L>>
      Returns:
      the local max message size, or null if none was set. 0 also means no limit.
      See Also:
    • isLocallyOpen

      public boolean isLocallyOpen()
      Description copied from interface: Endpoint
      Returns true if this Endpoint is currently locally open meaning that the Endpoint.open() has been called but the Endpoint.close() has not.
      Specified by:
      isLocallyOpen in interface Endpoint<L extends Link<L>>
      Returns:
      true if the Endpoint is locally open.
      See Also:
    • isLocallyClosed

      public boolean isLocallyClosed()
      Description copied from interface: Endpoint
      Returns true if this Endpoint is currently locally closed meaning that a call to the Endpoint.close() method has occurred.
      Specified by:
      isLocallyClosed in interface Endpoint<L extends Link<L>>
      Returns:
      true if the Endpoint is locally closed.
      See Also:
    • isLocallyDetached

      public boolean isLocallyDetached()
      Description copied from interface: Link
      Returns true if this Link is currently locally detached meaning the state returned from Link.getState() is equal to LinkState.DETACHED. A link is locally detached after a call to Link.detach().
      Specified by:
      isLocallyDetached in interface Link<L extends Link<L>>
      Returns:
      true if the link is locally closed.
      See Also:
    • isLocallyClosedOrDetached

      public boolean isLocallyClosedOrDetached()
      Description copied from interface: Link
      Returns true if this Link is currently locally detached or locally closed meaning the state returned from Link.getState() is equal to LinkState.DETACHED or LinkState.CLOSED. A link is locally detached after a call to Link.detach() and is locally closed after a call to Endpoint.close().
      Specified by:
      isLocallyClosedOrDetached in interface Link<L extends Link<L>>
      Returns:
      true if the link is locally closed or detached.
      See Also:
    • isRemotelyOpen

      public boolean isRemotelyOpen()
      Description copied from interface: Link
      Returns true if this Link is currently remotely open meaning the state returned from Link.getRemoteState() is equal to LinkState.ACTIVE. A link is remotely opened after an Attach has been received from the remote and before a Detach has been received from the remote.
      Specified by:
      isRemotelyOpen in interface Endpoint<L extends Link<L>>
      Specified by:
      isRemotelyOpen in interface Link<L extends Link<L>>
      Returns:
      true if the link is remotely open.
      See Also:
    • isRemotelyClosed

      public boolean isRemotelyClosed()
      Description copied from interface: Link
      Returns true if this Link is currently remotely closed meaning the state returned from Link.getRemoteState() is equal to LinkState.CLOSED. A link is remotely closed after an Detach has been received from the remote with the close flag equal to true.
      Specified by:
      isRemotelyClosed in interface Endpoint<L extends Link<L>>
      Specified by:
      isRemotelyClosed in interface Link<L extends Link<L>>
      Returns:
      true if the link is remotely closed.
      See Also:
    • isRemotelyDetached

      public boolean isRemotelyDetached()
      Description copied from interface: Link
      Returns true if this Link is currently remotely detached meaning the state returned from Link.getRemoteState() is equal to LinkState.DETACHED. A link is remotely detached after an Detach has been received from the remote with the close flag equal to false.
      Specified by:
      isRemotelyDetached in interface Link<L extends Link<L>>
      Returns:
      true if the link is remotely detached.
      See Also:
    • isRemotelyClosedOrDetached

      public boolean isRemotelyClosedOrDetached()
      Description copied from interface: Link
      Returns true if this Link is currently remotely detached or closed meaning the state returned from Link.getRemoteState() is equal to LinkState.DETACHED or LinkState.CLOSED. A link is remotely detached or closed after a Detach has been received from the remote.
      Specified by:
      isRemotelyClosedOrDetached in interface Link<L extends Link<L>>
      Returns:
      true if the link is remotely detached or closed.
      See Also:
    • 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 interface Link<L extends Link<L>>
      Returns:
      the sender settlement mode conveyed by the peer, or null if there was none.
      See Also:
    • 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 interface Link<L extends Link<L>>
      Returns:
      the sender receiver mode conveyed by the peer, or null if there was none.
      See Also:
    • getRemoteSource

      public Source getRemoteSource()
      Specified by:
      getRemoteSource in interface Link<L extends Link<L>>
      Returns:
      the source Terminus for the remote end of this link.
    • getRemoteTarget

      public <T extends Terminus> T getRemoteTarget()
      Description copied from interface: Link
      Returns the remote target Terminus 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 a Target type for a Sender or Receiver link or if the link is to be transaction resource then the target type will be a Coordinator instance.

      Specified by:
      getRemoteTarget in interface Link<L extends Link<L>>
      Type Parameters:
      T - The type that the remote Terminus will be cast to on return.
      Returns:
      the source Terminus for the remote end of this link.
    • getRemoteOfferedCapabilities

      public Symbol[] getRemoteOfferedCapabilities()
      Specified by:
      getRemoteOfferedCapabilities in interface Endpoint<L extends Link<L>>
      Returns:
      the capabilities offered by the remote when it opened its end of the Endpoint.
    • getRemoteDesiredCapabilities

      public Symbol[] getRemoteDesiredCapabilities()
      Specified by:
      getRemoteDesiredCapabilities in interface Endpoint<L extends Link<L>>
      Returns:
      the capabilities desired by the remote when it opened its end of the Endpoint.
    • getRemoteProperties

      public Map<Symbol,Object> getRemoteProperties()
      Specified by:
      getRemoteProperties in interface Endpoint<L extends Link<L>>
      Returns:
      the properties sent by the remote when it opened its end of the Endpoint.
    • 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 interface Link<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 a EventHandler for when an this link is detached locally via a call to Link.detach() This is a convenience event that supplements the normal Endpoint.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 interface Link<L extends Link<L>>
      Parameters:
      localDetachHandler - The EventHandler 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 a EventHandler for when an AMQP Detach frame is received from the remote peer for this Link 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 interface Link<L extends Link<L>>
      Parameters:
      remoteDetachHandler - The EventHandler 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 a EventHandler for when the parent Session or Connection 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 interface Link<L extends Link<L>>
      Parameters:
      handler - The EventHandler 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()
    • handleRemoteAttach

      protected abstract L handleRemoteAttach(Attach attach)
    • handleRemoteDetach

      protected abstract L handleRemoteDetach(Detach detach)
    • handleRemoteFlow

      protected abstract L handleRemoteFlow(Flow flow)
    • 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)
    • decorateOutgoingFlow

      protected abstract L decorateOutgoingFlow(Flow flow)
    • checkLinkOperable

      protected void checkLinkOperable(String failurePrefix)
    • areDeliveriesStillActive

      protected boolean areDeliveriesStillActive()
    • checkNotOpened

      protected void checkNotOpened(String errorMessage)
    • checkNotClosed

      protected void checkNotClosed(String errorMessage)