Class ProtonIncomingDelivery
- java.lang.Object
-
- org.apache.qpid.protonj2.engine.impl.ProtonIncomingDelivery
-
- All Implemented Interfaces:
IncomingDelivery
public class ProtonIncomingDelivery extends java.lang.Object implements IncomingDelivery
Proton Incoming Delivery implementation
-
-
Constructor Summary
Constructors Constructor Description ProtonIncomingDelivery(ProtonReceiver link, long deliveryId, DeliveryTag deliveryTag)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes currently available for reading form this delivery, which may not be complete yet.IncomingDelivery
claimAvailableBytes()
Marks all available bytes as being claimed by the caller meaning that available byte count value can be returned to the session which can expand the session incoming window to allow more bytes to be sent from the remote peer.ProtonIncomingDelivery
deliveryAbortedHandler(EventHandler<IncomingDelivery> handler)
Handler for aborted deliveries that is called if this delivery is aborted by theSender
.ProtonIncomingDelivery
deliveryReadHandler(EventHandler<IncomingDelivery> handler)
ProtonIncomingDelivery
deliveryStateUpdatedHandler(EventHandler<IncomingDelivery> handler)
Handler for updates to the remote state of incoming deliveries that have previously been received.IncomingDelivery
disposition(DeliveryState state)
updates the state of the deliveryIncomingDelivery
disposition(DeliveryState state, boolean settle)
Update the delivery with the given disposition if not locally settled and optionally settles the delivery if not already settled.ProtonAttachments
getAttachments()
DeliveryState
getDefaultDeliveryState()
ProtonReceiver
getLink()
<T> T
getLinkedResource()
<T> T
getLinkedResource(java.lang.Class<T> typeClass)
Gets the linked resource (if set) and returns it using the type information provided to cast the returned value.int
getMessageFormat()
Gets the message-format for this Delivery, representing the 32bit value using an int.DeliveryState
getRemoteState()
DeliveryState
getState()
DeliveryTag
getTag()
int
getTransferCount()
Returns the total number of transfer frames that have occurred for the givenIncomingDelivery
.boolean
isAborted()
boolean
isPartial()
Check for whether the delivery is still partial.boolean
isRemotelySettled()
boolean
isSettled()
ProtonBuffer
readAll()
Returns the current read buffer without copying it effectively consuming all currently available bytes from this delivery.ProtonIncomingDelivery
readBytes(byte[] array, int offset, int length)
Reads bytes from this delivery and writes them into the destination array starting at the given offset and continuing for the specified length reducing the available bytes by the value of the number of bytes written to the target.ProtonIncomingDelivery
readBytes(ProtonBuffer buffer)
Reads bytes from this delivery and writes them into the destination ProtonBuffer reducing the available bytes by the value of the number of bytes written to the target.ProtonIncomingDelivery
setDefaultDeliveryState(DeliveryState state)
Configures a default DeliveryState to be used if a received delivery is settled/freed without any disposition state having been previously applied.ProtonIncomingDelivery
setLinkedResource(java.lang.Object resource)
Links a given resource to thisIncomingDelivery
.IncomingDelivery
settle()
Settles this delivery locally, transmitting aDisposition
frame to the remote if the remote has not already settled the delivery.java.lang.String
toString()
-
-
-
Constructor Detail
-
ProtonIncomingDelivery
public ProtonIncomingDelivery(ProtonReceiver link, long deliveryId, DeliveryTag deliveryTag)
- Parameters:
link
- The link that this delivery is associated withdeliveryId
- The Delivery Id that is assigned to this delivery.deliveryTag
- The delivery tag assigned to this delivery
-
-
Method Detail
-
getLink
public ProtonReceiver getLink()
- Specified by:
getLink
in interfaceIncomingDelivery
- Returns:
- the link that this
IncomingDelivery
is bound to.
-
getAttachments
public ProtonAttachments getAttachments()
- Specified by:
getAttachments
in interfaceIncomingDelivery
- Returns:
- the
Attachments
instance that is associated with thisIncomingDelivery
-
setLinkedResource
public ProtonIncomingDelivery setLinkedResource(java.lang.Object resource)
Description copied from interface:IncomingDelivery
Links a given resource to thisIncomingDelivery
.- Specified by:
setLinkedResource
in interfaceIncomingDelivery
- Parameters:
resource
- The resource to link to thisIncomingDelivery
.- Returns:
- this
IncomingDelivery
instance.
-
getLinkedResource
public <T> T getLinkedResource()
- Specified by:
getLinkedResource
in interfaceIncomingDelivery
- Type Parameters:
T
- The type that the linked resource should be cast to on return.- Returns:
- the user set linked resource for this
Endpoint
instance.
-
getLinkedResource
public <T> T getLinkedResource(java.lang.Class<T> typeClass)
Description copied from interface:IncomingDelivery
Gets the linked resource (if set) and returns it using the type information provided to cast the returned value.- Specified by:
getLinkedResource
in interfaceIncomingDelivery
- Type Parameters:
T
- The type to cast the linked resource to if one is set.- Parameters:
typeClass
- the type's Class which is used for casting the returned value.- Returns:
- the user set linked resource for this Context instance.
-
getTag
public DeliveryTag getTag()
- Specified by:
getTag
in interfaceIncomingDelivery
- Returns:
- the
DeliveryTag
assigned to this Delivery.
-
getState
public DeliveryState getState()
- Specified by:
getState
in interfaceIncomingDelivery
- Returns:
- the
DeliveryState
at the local side of this Delivery.
-
getRemoteState
public DeliveryState getRemoteState()
- Specified by:
getRemoteState
in interfaceIncomingDelivery
- Returns:
- the
DeliveryState
at the remote side of this Delivery.
-
getMessageFormat
public int getMessageFormat()
Description copied from interface:IncomingDelivery
Gets the message-format for this Delivery, representing the 32bit value using an int.The default value is 0 as per the message format defined in the core AMQP 1.0 specification.
See the following for more details:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-transfer
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-message-format
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#definition-MESSAGE-FORMAT- Specified by:
getMessageFormat
in interfaceIncomingDelivery
- Returns:
- the message-format for this Delivery.
-
isPartial
public boolean isPartial()
Description copied from interface:IncomingDelivery
Check for whether the delivery is still partial.For a receiving Delivery, this means the delivery does not hold a complete message payload as all the content hasn't been received yet. Note that an
aborted
delivery will also be considered partial and the full payload won't be received.For a sending Delivery, this means that the application has not marked the delivery as complete yet.
- Specified by:
isPartial
in interfaceIncomingDelivery
- Returns:
- true if the delivery is partial
- See Also:
IncomingDelivery.isAborted()
-
isAborted
public boolean isAborted()
- Specified by:
isAborted
in interfaceIncomingDelivery
- Returns:
- true if the delivery has been aborted.
-
isSettled
public boolean isSettled()
- Specified by:
isSettled
in interfaceIncomingDelivery
- Returns:
- true if the delivery has been settled locally.
-
isRemotelySettled
public boolean isRemotelySettled()
- Specified by:
isRemotelySettled
in interfaceIncomingDelivery
- Returns:
- true if the delivery has been settled by the remote.
-
setDefaultDeliveryState
public ProtonIncomingDelivery setDefaultDeliveryState(DeliveryState state)
Description copied from interface:IncomingDelivery
Configures a default DeliveryState to be used if a received delivery is settled/freed without any disposition state having been previously applied.- Specified by:
setDefaultDeliveryState
in interfaceIncomingDelivery
- Parameters:
state
- the default delivery state- Returns:
- this
IncomingDelivery
instance.
-
getDefaultDeliveryState
public DeliveryState getDefaultDeliveryState()
- Specified by:
getDefaultDeliveryState
in interfaceIncomingDelivery
- Returns:
- the default delivery state for this delivery
-
disposition
public IncomingDelivery disposition(DeliveryState state)
Description copied from interface:IncomingDelivery
updates the state of the delivery- Specified by:
disposition
in interfaceIncomingDelivery
- Parameters:
state
- the new delivery state- Returns:
- this
IncomingDelivery
instance.
-
disposition
public IncomingDelivery disposition(DeliveryState state, boolean settle)
Description copied from interface:IncomingDelivery
Update the delivery with the given disposition if not locally settled and optionally settles the delivery if not already settled.Applies the given delivery state and local settlement value to this delivery writing a new
Disposition
frame if the remote has not already settled the delivery. Once locally settled no additional updates to the localDeliveryState
can be applied and if attempted anIllegalStateException
will be thrown to indicate this is not possible.- Specified by:
disposition
in interfaceIncomingDelivery
- Parameters:
state
- the new delivery statesettle
- if true the delivery is settled.- Returns:
- this
IncomingDelivery
instance.
-
settle
public IncomingDelivery settle()
Description copied from interface:IncomingDelivery
Settles this delivery locally, transmitting aDisposition
frame to the remote if the remote has not already settled the delivery. Once locally settled the delivery will not accept any additional updates to theDeliveryState
via one of theIncomingDelivery.disposition(DeliveryState)
orIncomingDelivery.disposition(DeliveryState, boolean)
methods.- Specified by:
settle
in interfaceIncomingDelivery
- Returns:
- this
IncomingDelivery
instance.
-
available
public int available()
Description copied from interface:IncomingDelivery
Returns the number of bytes currently available for reading form this delivery, which may not be complete yet.Note that this value will change as bytes are received, and is in general not equal to the total length of a delivery, except the point where
IncomingDelivery.isPartial()
returns false and no content has yet been received by the application.- Specified by:
available
in interfaceIncomingDelivery
- Returns:
- the number of bytes currently available to read from this delivery.
-
readAll
public ProtonBuffer readAll()
Description copied from interface:IncomingDelivery
Returns the current read buffer without copying it effectively consuming all currently available bytes from this delivery. If no data is available then this method returnsnull
.- Specified by:
readAll
in interfaceIncomingDelivery
- Returns:
- the currently available read bytes for this delivery.
-
readBytes
public ProtonIncomingDelivery readBytes(ProtonBuffer buffer)
Description copied from interface:IncomingDelivery
Reads bytes from this delivery and writes them into the destination ProtonBuffer reducing the available bytes by the value of the number of bytes written to the target. The number of bytes written will be the equal to the writable bytes of the target buffer. The write index of the target buffer will be incremented by the number of bytes written into it.- Specified by:
readBytes
in interfaceIncomingDelivery
- Parameters:
buffer
- The target buffer that will be written into.- Returns:
- this
IncomingDelivery
instance.
-
readBytes
public ProtonIncomingDelivery readBytes(byte[] array, int offset, int length)
Description copied from interface:IncomingDelivery
Reads bytes from this delivery and writes them into the destination array starting at the given offset and continuing for the specified length reducing the available bytes by the value of the number of bytes written to the target.- Specified by:
readBytes
in interfaceIncomingDelivery
- Parameters:
array
- The target buffer that will be written into.offset
- The offset into the given array to begin writing.length
- The number of bytes to write to the given array.- Returns:
- this
IncomingDelivery
instance.
-
claimAvailableBytes
public IncomingDelivery claimAvailableBytes()
Description copied from interface:IncomingDelivery
Marks all available bytes as being claimed by the caller meaning that available byte count value can be returned to the session which can expand the session incoming window to allow more bytes to be sent from the remote peer.This method is useful in the case where the
Session
has been configured with a small incoming capacity and the receiver needs to expand the session window in order to read the entire contents of a delivery whose payload exceeds the configured session capacity. TheIncomingDelivery
implementation will track the amount of claimed bytes and ensure that it never releases back more bytes to theSession
than has actually been received as a whole which allows this method to be called with each incomingTransfer
frame of a large split framed delivery.- Specified by:
claimAvailableBytes
in interfaceIncomingDelivery
- Returns:
- this
IncomingDelivery
instance.
-
deliveryReadHandler
public ProtonIncomingDelivery deliveryReadHandler(EventHandler<IncomingDelivery> handler)
Description copied from interface:IncomingDelivery
Handler for incoming deliveries that is called for each incomingTransfer
frame that comprises either one complete delivery or a chunk of a split framedTransfer
. The handler should check that the delivery being read is partial or not and act accordingly, as partial deliveries expect additional updates as more frames comprising thatIncomingDelivery
arrive or the remote aborts the transfer.This handler is useful in cases where an incoming delivery is split across many incoming
Transfer
frames either due to a large size or a small max frame size setting and the processing is handed off to some other resource other than theReceiver
that original handling the first transfer frame. If the initialTransfer
carries the entire delivery payload then this event handler will never be called. Once set this event handler receiver all updates of incoming deliveryTransfer
frames which would otherwise have been sent to theReceiver.deliveryReadHandler(EventHandler)
instance.- Specified by:
deliveryReadHandler
in interfaceIncomingDelivery
- Parameters:
handler
- The handler that will be invoked whenTransfer
frames arrive on this receiver link.- Returns:
- this
IncomingDelivery
instance.
-
deliveryAbortedHandler
public ProtonIncomingDelivery deliveryAbortedHandler(EventHandler<IncomingDelivery> handler)
Description copied from interface:IncomingDelivery
Handler for aborted deliveries that is called if this delivery is aborted by theSender
.This handler is an optional convenience handler that supplements the standard
IncomingDelivery.deliveryReadHandler(EventHandler)
in cases where the users wishes to break out the processing of inbound delivery data from abort processing. If this handler is not set theReceiver
will call the registeredIncomingDelivery.deliveryAbortedHandler(EventHandler)
if one is set.- Specified by:
deliveryAbortedHandler
in interfaceIncomingDelivery
- Parameters:
handler
- The handler that will be invoked whenTransfer
frames arrive on this receiver link.- Returns:
- this
IncomingDelivery
instance.
-
deliveryStateUpdatedHandler
public ProtonIncomingDelivery deliveryStateUpdatedHandler(EventHandler<IncomingDelivery> handler)
Description copied from interface:IncomingDelivery
Handler for updates to the remote state of incoming deliveries that have previously been received.Remote state updates for an
IncomingDelivery
can happen when the remote settles a completeIncomingDelivery
or otherwise modifies the delivery outcome and the user needs to act on those changes such as a spontaneous update to theDeliveryState
. If the initialTransfer
of an incoming delivery already indicates settlement then this handler will never be called.- Specified by:
deliveryStateUpdatedHandler
in interfaceIncomingDelivery
- Parameters:
handler
- The handler that will be invoked when a new remote state update for anIncomingDelivery
arrives on this link.- Returns:
- this
IncomingDelivery
instance.
-
getTransferCount
public int getTransferCount()
Description copied from interface:IncomingDelivery
Returns the total number of transfer frames that have occurred for the givenIncomingDelivery
.- Specified by:
getTransferCount
in interfaceIncomingDelivery
- Returns:
- the number of
Transfer
frames that thisOutgoingDelivery
has initiated.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-