Interface Receiver
-
- All Superinterfaces:
AutoCloseable
,Link<Receiver>
- All Known Implementing Classes:
ClientReceiver
public interface Receiver extends Link<Receiver>
AMQP Receiver that provides an interface to receive complete Deliveries from a remote peer. Deliveries that are returned from thereceive()
methods will be complete and can be read immediately without blocking waiting for additional delivery data to arrive.- See Also:
StreamReceiver
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Receiver
addCredit(int credits)
Adds credit to theReceiver
link for use when there receiver has not been configured with a credit window.Future<Receiver>
drain()
Requests the remote to drain previously granted credit for thisReceiver
link.long
queuedDeliveries()
Returns the number of Deliveries that are currently held in theReceiver
delivery queue.Delivery
receive()
Blocking receive method that waits forever for the remote to provide aDelivery
for consumption.Delivery
receive(long timeout, TimeUnit unit)
Blocking receive method that waits the given time interval for the remote to provide aDelivery
for consumption.Delivery
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 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
-
addCredit
Receiver addCredit(int credits) throws ClientException
Adds credit to theReceiver
link for use when there 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.- Parameters:
credits
- The number of credits to add to theReceiver
link.- Returns:
- this
Receiver
instance. - Throws:
ClientException
- if an error occurs while attempting to add newReceiver
link credit.
-
receive
Delivery receive() throws ClientException
Blocking receive method that waits forever for the remote to provide aDelivery
for consumption.Receive calls will only grant credit on their own if a credit window is configured in the
ReceiverOptions
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.- Returns:
- a new
Delivery
received from the remote. - Throws:
ClientException
- if theReceiver
or its parent is closed when the call to receive is made.
-
receive
Delivery receive(long timeout, TimeUnit unit) throws ClientException
Blocking receive method that waits the given time interval for the remote to provide aDelivery
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 aDelivery
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
ReceiverOptions
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 incomingDelivery
.- 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
Delivery
received from the remote. - Throws:
ClientException
- if theReceiver
or its parent is closed when the call to receive is made.
-
tryReceive
Delivery tryReceive() throws ClientException
Non-blocking receive method that either returns a message is one is immediately available or returns null if none is currently at hand.- Returns:
- a new
Delivery
received from the remote or null if no pending deliveries are available. - Throws:
ClientException
- if theReceiver
or its parent is closed when the call to try to receive is made.
-
drain
Future<Receiver> drain() throws ClientException
Requests the remote to drain previously granted credit for thisReceiver
link.- Returns:
- a
Future
that will be completed when the remote drains thisReceiver
link. - Throws:
ClientException
- if an error occurs while attempting to drain the link credit.
-
queuedDeliveries
long queuedDeliveries() throws ClientException
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.- Returns:
- the number of deliveries that are currently buffered locally.
- Throws:
ClientException
- if an error occurs while attempting to fetch the queue count.
-
-