Class ClientStreamReceiver
- java.lang.Object
-
- org.apache.qpid.protonj2.client.impl.ClientLinkType<ReceiverType,Receiver>
-
- org.apache.qpid.protonj2.client.impl.ClientReceiverLinkType<StreamReceiver>
-
- org.apache.qpid.protonj2.client.impl.ClientStreamReceiver
-
- All Implemented Interfaces:
AutoCloseable
,Link<StreamReceiver>
,StreamReceiver
public final class ClientStreamReceiver extends ClientReceiverLinkType<StreamReceiver> implements StreamReceiver
Client implementation of aStreamReceiver
.
-
-
Field Summary
-
Fields inherited from class org.apache.qpid.protonj2.client.impl.ClientReceiverLinkType
protonReceiver
-
Fields inherited from class org.apache.qpid.protonj2.client.impl.ClientLinkType
closed, CLOSED_UPDATER, closeFuture, executor, failureCause, linkId, linkRemotelyClosedHandler, openFuture, remoteSource, remoteTarget, session
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StreamReceiver
addCredit(int credits)
Adds credit to theStreamReceiver
link for use when the receiver has not been configured with a credit window.Future<StreamReceiver>
drain()
Requests the remote to drain previously granted credit for thisStreamReceiver
link.protected void
handleDeliveryRead(IncomingDelivery delivery)
protected void
linkSpecificCleanupHandler(ClientException failureCause)
long
queuedDeliveries()
Returns the number of Deliveries that are currently held in theReceiver
delivery queue.StreamDelivery
receive()
Blocking receive method that waits forever for the remote to provide aStreamReceiverMessage
for consumption.StreamDelivery
receive(long timeout, TimeUnit unit)
Blocking receive method that waits the given time interval for the remote to provide aStreamReceiverMessage
for consumption.protected void
recreateLinkForReconnect()
protected void
replenishCreditIfNeeded()
protected StreamReceiver
self()
StreamDelivery
tryReceive()
Non-blocking receive method that either returns a message is one is immediately available or returns null if none is currently at hand.-
Methods inherited from class org.apache.qpid.protonj2.client.impl.ClientReceiverLinkType
handleDeliveryAborted, handleDeliveryStateRemotelyUpdated, handleReceiverCreditUpdated, linkSpecificLocalCloseHandler, linkSpecificLocalOpenHandler, linkSpecificRemoteCloseHandler, linkSpecificRemoteOpenHandler, protonLink
-
Methods inherited from class org.apache.qpid.protonj2.client.impl.ClientLinkType
address, checkClosedOrFailed, client, close, close, closeAsync, closeAsync, connection, desiredCapabilities, detach, detach, detachAsync, detachAsync, handleEngineShutdown, handleLocalCloseOrDetach, handleLocalOpen, handleParentEndpointClosed, handleRemoteCloseOrDetach, handleRemoteOpen, immediateLinkShutdown, notClosedOrFailed, notClosedOrFailed, offeredCapabilities, openFuture, properties, session, source, target, waitForOpenToComplete
-
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.client.Link
address, client, close, close, closeAsync, closeAsync, connection, desiredCapabilities, detach, detach, detachAsync, detachAsync, offeredCapabilities, openFuture, properties, session, source, target
-
-
-
-
Method Detail
-
receive
public StreamDelivery receive() throws ClientException
Description copied from interface:StreamReceiver
Blocking receive method that waits forever for the remote to provide aStreamReceiverMessage
for consumption.Receive calls will only grant credit on their own if a credit window is configured in the
StreamReceiverOptions
which is done by default. If the client application has configured no credit window than this method will not grant any credit when it enters the wait for new incoming messages.- Specified by:
receive
in interfaceStreamReceiver
- Returns:
- a new
Delivery
received from the remote. - Throws:
ClientException
- if theStreamReceiver
or its parent is closed when the call to receive is made.
-
receive
public StreamDelivery receive(long timeout, TimeUnit unit) throws ClientException
Description copied from interface:StreamReceiver
Blocking receive method that waits the given time interval for the remote to provide aStreamReceiverMessage
for consumption. The amount of time this method blocks is based on the timeout value. If timeout is equal to-1
then it blocks until a Delivery is received. If timeout is equal to zero then it will not block and simply return aStreamReceiverMessage
if one is available locally. If timeout value is greater than zero then it blocks up to timeout amount of time.Receive calls will only grant credit on their own if a credit window is configured in the
StreamReceiverOptions
which is done by default. If the client application has not configured a credit window or granted credit manually this method will not automatically grant any credit when it enters the wait for a new incomingStreamReceiverMessage
.- Specified by:
receive
in interfaceStreamReceiver
- Parameters:
timeout
- The timeout value used to control how long the receive method waits for a newDelivery
.unit
- The unit of time that the given timeout represents.- Returns:
- a new
StreamReceiverMessage
received from the remote. - Throws:
ClientException
- if theStreamReceiver
or its parent is closed when the call to receive is made.
-
tryReceive
public StreamDelivery tryReceive() throws ClientException
Description copied from interface:StreamReceiver
Non-blocking receive method that either returns a message is one is immediately available or returns null if none is currently at hand.- Specified by:
tryReceive
in interfaceStreamReceiver
- Returns:
- a new
StreamReceiverMessage
received from the remote or null if no pending deliveries are available. - Throws:
ClientException
- if theStreamReceiver
or its parent is closed when the call to try to receive is made.
-
addCredit
public StreamReceiver addCredit(int credits) throws ClientException
Description copied from interface:StreamReceiver
Adds credit to theStreamReceiver
link for use when the receiver has not been configured with a credit window. When credit window is configured credit replenishment is automatic and calling this method will result in an exception indicating that the operation is invalid.If the
Receiver
is draining and this method is called an exception will be thrown to indicate that credit cannot be replenished until the remote has drained the existing link credit.- Specified by:
addCredit
in interfaceStreamReceiver
- Parameters:
credits
- The number of credits to add to theReceiver
link.- Returns:
- this
StreamReceiver
instance. - Throws:
ClientException
- if an error occurs while attempting to add newStreamReceiver
link credit.
-
drain
public Future<StreamReceiver> drain() throws ClientException
Description copied from interface:StreamReceiver
Requests the remote to drain previously granted credit for thisStreamReceiver
link.- Specified by:
drain
in interfaceStreamReceiver
- Returns:
- a
Future
that will be completed when the remote drains thisStreamReceiver
link. - Throws:
ClientException
- if an error occurs while attempting to drain the link credit.
-
queuedDeliveries
public long queuedDeliveries() throws ClientException
Description copied from interface:StreamReceiver
Returns the number of Deliveries that are currently held in theReceiver
delivery queue. This number is likely to change immediately following the call as more deliveries arrive but can be used to determine if any pendingDelivery
work is ready.- Specified by:
queuedDeliveries
in interfaceStreamReceiver
- Returns:
- the number of deliveries that are currently buffered locally.
- Throws:
ClientException
- if an error occurs while attempting to fetch the queue count.
-
self
protected StreamReceiver self()
- Specified by:
self
in classClientLinkType<StreamReceiver,Receiver>
-
handleDeliveryRead
protected void handleDeliveryRead(IncomingDelivery delivery)
- Specified by:
handleDeliveryRead
in classClientReceiverLinkType<StreamReceiver>
-
replenishCreditIfNeeded
protected void replenishCreditIfNeeded()
- Specified by:
replenishCreditIfNeeded
in classClientReceiverLinkType<StreamReceiver>
-
linkSpecificCleanupHandler
protected void linkSpecificCleanupHandler(ClientException failureCause)
- Overrides:
linkSpecificCleanupHandler
in classClientReceiverLinkType<StreamReceiver>
-
recreateLinkForReconnect
protected void recreateLinkForReconnect()
- Specified by:
recreateLinkForReconnect
in classClientLinkType<StreamReceiver,Receiver>
-
-