Interface Receiver
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Subinterfaces:
StreamReceiver
- All Known Implementing Classes:
ClientReceiver
,ClientStreamReceiver
public interface Receiver extends java.lang.AutoCloseable
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.java.lang.String
address()
Returns the address that theReceiver
instance will be subscribed to.Client
client()
void
close()
Requests a close of theReceiver
at the remote and waits until the Receiver has been fully closed or until the configuredReceiverOptions.closeTimeout()
is exceeded.void
close(ErrorCondition error)
Requests a close of theReceiver
at the remote and waits until the Receiver has been fully closed or until the configuredReceiverOptions.closeTimeout()
is exceeded.java.util.concurrent.Future<Receiver>
closeAsync()
Requests a close of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been closed.java.util.concurrent.Future<Receiver>
closeAsync(ErrorCondition error)
Requests a close of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been closed.Connection
connection()
java.lang.String[]
desiredCapabilities()
Returns the desired capabilities that the remote provided upon successfully opening theReceiver
.void
detach()
Requests a detach of theReceiver
at the remote and waits until the Receiver has been fully detached or until the configuredSenderOptions.closeTimeout()
is exceeded.void
detach(ErrorCondition error)
Requests a detach of theReceiver
at the remote and waits until the Receiver has been fully detached or until the configuredSenderOptions.closeTimeout()
is exceeded.java.util.concurrent.Future<Receiver>
detachAsync()
Requests a detach of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been detached.java.util.concurrent.Future<Receiver>
detachAsync(ErrorCondition error)
Requests a detach of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been detached.java.util.concurrent.Future<Receiver>
drain()
Requests the remote to drain previously granted credit for thisReceiver
link.java.lang.String[]
offeredCapabilities()
Returns the offered capabilities that the remote provided upon successfully opening theReceiver
.java.util.concurrent.Future<Receiver>
openFuture()
java.util.Map<java.lang.String,java.lang.Object>
properties()
Returns the properties that the remote provided upon successfully opening theReceiver
.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, java.util.concurrent.TimeUnit unit)
Blocking receive method that waits the given time interval for the remote to provide aDelivery
for consumption.Session
session()
Source
source()
Returns an immutable view of the remoteSource
object assigned to this receiver link.Target
target()
Returns an immutable view of the remoteTarget
object assigned to this receiver link.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.
-
-
-
Method Detail
-
openFuture
java.util.concurrent.Future<Receiver> openFuture()
- Returns:
- a
Future
that will be completed when the remote opens thisReceiver
.
-
close
void close()
Requests a close of theReceiver
at the remote and waits until the Receiver has been fully closed or until the configuredReceiverOptions.closeTimeout()
is exceeded.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
close
void close(ErrorCondition error)
Requests a close of theReceiver
at the remote and waits until the Receiver has been fully closed or until the configuredReceiverOptions.closeTimeout()
is exceeded.- Parameters:
error
- TheErrorCondition
to transmit to the remote along with the close operation.
-
detach
void detach()
Requests a detach of theReceiver
at the remote and waits until the Receiver has been fully detached or until the configuredSenderOptions.closeTimeout()
is exceeded.
-
detach
void detach(ErrorCondition error)
Requests a detach of theReceiver
at the remote and waits until the Receiver has been fully detached or until the configuredSenderOptions.closeTimeout()
is exceeded.- Parameters:
error
- TheErrorCondition
to transmit to the remote along with the detach operation.
-
closeAsync
java.util.concurrent.Future<Receiver> closeAsync()
Requests a close of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been closed.- Returns:
- a
Future
that will be completed when the remote closes thisReceiver
link.
-
closeAsync
java.util.concurrent.Future<Receiver> closeAsync(ErrorCondition error)
Requests a close of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been closed.- Parameters:
error
- TheErrorCondition
to transmit to the remote along with the close operation.- Returns:
- a
Future
that will be completed when the remote closes thisReceiver
link.
-
detachAsync
java.util.concurrent.Future<Receiver> detachAsync()
Requests a detach of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been detached.- Returns:
- a
Future
that will be completed when the remote detaches thisReceiver
link.
-
detachAsync
java.util.concurrent.Future<Receiver> detachAsync(ErrorCondition error)
Requests a detach of theReceiver
link at the remote and returns aFuture
that will be completed once the link has been detached.- Parameters:
error
- TheErrorCondition
to transmit to the remote along with the detach operation.- Returns:
- a
Future
that will be completed when the remote detaches thisReceiver
link.
-
address
java.lang.String address() throws ClientException
Returns the address that theReceiver
instance will be subscribed to.- If the Receiver was created with the dynamic receiver methods then the method will return the dynamically created address once the remote has attached its end of the receiver link. Due to the need to await the remote peer to populate the dynamic address this method will block until the open of the receiver link has completed.
-
If not a dynamic receiver then the address returned is the address passed to the original
Session.openReceiver(String)
orSession.openReceiver(String, ReceiverOptions)
methods.
- Returns:
- the address that this
Receiver
is sending to. - Throws:
ClientException
- if an error occurs while obtaining theReceiver
address.
-
source
Source source() throws ClientException
Returns an immutable view of the remoteSource
object assigned to this receiver link. If the attach has not completed yet this method will block to await the attach response which carries the remoteSource
.- Returns:
- the remote
Source
node configuration. - Throws:
ClientException
- if an error occurs while obtaining theReceiver
remoteSource
.
-
target
Target target() throws ClientException
Returns an immutable view of the remoteTarget
object assigned to this receiver link. If the attach has not completed yet this method will block to await the attach response which carries the remoteSource
.- Returns:
- the remote
Target
node configuration. - Throws:
ClientException
- if an error occurs while obtaining theReceiver
remoteTarget
.
-
properties
java.util.Map<java.lang.String,java.lang.Object> properties() throws ClientException
Returns the properties that the remote provided upon successfully opening theReceiver
. If the attach has not completed yet this method will block to await the attach response which carries the remote properties. If the remote provides no properties this method will return null.- Returns:
- any properties provided from the remote once the receiver has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theReceiver
remote properties.
-
offeredCapabilities
java.lang.String[] offeredCapabilities() throws ClientException
Returns the offered capabilities that the remote provided upon successfully opening theReceiver
. If the attach has not completed yet this method will block to await the attach response which carries the remote offered capabilities. If the remote provides no capabilities this method will return null.- Returns:
- any capabilities provided from the remote once the receiver has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theReceiver
remote offered capabilities.
-
desiredCapabilities
java.lang.String[] desiredCapabilities() throws ClientException
Returns the desired capabilities that the remote provided upon successfully opening theReceiver
. If the attach has not completed yet this method will block to await the attach response which carries the remote desired capabilities. If the remote provides no capabilities this method will return null.- Returns:
- any desired capabilities provided from the remote once the receiver has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theReceiver
remote desired capabilities.
-
connection
Connection connection()
- Returns:
- the
Connection
instance that holds this session'sReceiver
-
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, java.util.concurrent.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
java.util.concurrent.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.
-
-