Package org.apache.qpid.protonj2.client
Interface Connection
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
ClientConnection
public interface Connection extends AutoCloseable
Top levelConnection
object that can be used as a stand alone API for sending messages and creatingReceiver
instances for message consumption. The Connection API also exposes aSession
based API for more advanced messaging use cases. When a Connection is closed all the resources created by the connection are implicitly closed.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Client
client()
void
close()
Requests a close of theConnection
at the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()
is exceeded.void
close(ErrorCondition error)
Requests a close of theConnection
at the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()
is exceeded.Future<Connection>
closeAsync()
Requests a close of theConnection
at the remote and returns aFuture
that will be completed once the Connection has been fully closed.Future<Connection>
closeAsync(ErrorCondition error)
Requests a close of theConnection
at the remote and returns aFuture
that will be completed once the Connection has been fully closed.Sender
defaultSender()
Returns the default anonymous sender used by thisConnection
forsend(Message)
calls.Session
defaultSession()
String[]
desiredCapabilities()
Returns the desired capabilities that the remote provided upon successfully opening theConnection
.Receiver
nextReceiver()
Waits indefinitely for a receiver created from the connection default session to have a delivery ready for receipt.Receiver
nextReceiver(long timeout, TimeUnit unit)
Waits for the configured time interval for a receiver created from the connection default session to have a delivery ready for receipt.Receiver
nextReceiver(NextReceiverPolicy policy)
Waits indefinitely for a receiver created from the connection default session to have a delivery ready for receipt.Receiver
nextReceiver(NextReceiverPolicy policy, long timeout, TimeUnit unit)
Waits for the configured time interval for a receiver created from the connection default session to have a delivery ready for receipt.String[]
offeredCapabilities()
Returns the offered capabilities that the remote provided upon successfully opening theConnection
.Sender
openAnonymousSender()
Creates a sender that is established to the 'anonymous relay' and as such each message that is sent using this sender must specify an address in its destination address field.Sender
openAnonymousSender(SenderOptions senderOptions)
Creates a sender that is established to the 'anonymous relay' and as such each message that is sent using this sender must specify an address in its destination address field.Receiver
openDurableReceiver(String address, String subscriptionName)
Creates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node.Receiver
openDurableReceiver(String address, String subscriptionName, ReceiverOptions receiverOptions)
Creates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node.Receiver
openDynamicReceiver()
Creates a dynamic receiver used to consume messages from the given node address.Receiver
openDynamicReceiver(Map<String,Object> dynamicNodeProperties)
Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote..Receiver
openDynamicReceiver(Map<String,Object> dynamicNodeProperties, ReceiverOptions receiverOptions)
Creates a dynamic receiver used to consume messages from the given node address.Receiver
openDynamicReceiver(ReceiverOptions receiverOptions)
Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote..Future<Connection>
openFuture()
When aConnection
is created it may not be opened on the remote peer, the future returned from this method allows the caller to await the completion of the Connection open by the remote before proceeding on to other messaging operations.Receiver
openReceiver(String address)
Creates a receiver used to consumer messages from the given node address.Receiver
openReceiver(String address, ReceiverOptions receiverOptions)
Creates a receiver used to consumer messages from the given node address.Sender
openSender(String address)
Creates a sender used to send messages to the given node address.Sender
openSender(String address, SenderOptions senderOptions)
Creates a sender used to send messages to the given node address.Session
openSession()
Creates a newSession
instance for use by the client application.Session
openSession(SessionOptions options)
Creates a newSession
instance for use by the client application.StreamReceiver
openStreamReceiver(String address)
Creates a streaming message receiver used to consume large messages from the given node address.StreamReceiver
openStreamReceiver(String address, StreamReceiverOptions receiverOptions)
Creates a streaming message receiver used to consume large messages from the given node address.StreamSender
openStreamSender(String address)
Creates a stream sender used to send large messages to the given node address.StreamSender
openStreamSender(String address, StreamSenderOptions senderOptions)
Creates a streaming sender used to send large messages to the given node address.Map<String,Object>
properties()
Returns the properties that the remote provided upon successfully opening theConnection
.Tracker
send(Message<?> message)
Sends the givenMessage
using the internal connection sender.
-
-
-
Method Detail
-
client
Client client()
- Returns:
- the
Client
instance that holds thisConnection
-
openFuture
Future<Connection> openFuture()
When aConnection
is created it may not be opened on the remote peer, the future returned from this method allows the caller to await the completion of the Connection open by the remote before proceeding on to other messaging operations. If the open of the connection fails at the remote anException
is thrown from theFuture.get()
method when called.- Returns:
- a
Future
that will be completed when the remote opens thisConnection
.
-
close
void close()
Requests a close of theConnection
at the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()
is exceeded.- Specified by:
close
in interfaceAutoCloseable
-
close
void close(ErrorCondition error)
Requests a close of theConnection
at the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()
is exceeded.- Parameters:
error
- TheErrorCondition
to transmit to the remote along with the close operation.
-
closeAsync
Future<Connection> closeAsync()
Requests a close of theConnection
at the remote and returns aFuture
that will be completed once the Connection has been fully closed.- Returns:
- a
Future
that will be completed when the remote closes thisConnection
.
-
closeAsync
Future<Connection> closeAsync(ErrorCondition error)
Requests a close of theConnection
at the remote and returns aFuture
that will be completed once the Connection has been fully 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 thisConnection
.
-
openReceiver
Receiver openReceiver(String address) throws ClientException
Creates a receiver used to consumer messages from the given node address. The returned receiver will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.- Returns:
- the consumer.
- Throws:
ClientException
- if an internal error occurs.
-
openReceiver
Receiver openReceiver(String address, ReceiverOptions receiverOptions) throws ClientException
Creates a receiver used to consumer messages from the given node address. The returned receiver will be configured using the options provided in the givenReceiverOptions
instance. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.receiverOptions
- The options for this receiver.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDurableReceiver
Receiver openDurableReceiver(String address, String subscriptionName) throws ClientException
Creates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node. The returned receiver will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.subscriptionName
- The name to give the subscription (link name).- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDurableReceiver
Receiver openDurableReceiver(String address, String subscriptionName, ReceiverOptions receiverOptions) throws ClientException
Creates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node. The returned receiver will be configured using provided options. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.subscriptionName
- The name to give the subscription (link name).receiverOptions
- The options for this receiver.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDynamicReceiver
Receiver openDynamicReceiver() throws ClientException
Creates a dynamic receiver used to consume messages from the given node address. The returned receiver will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDynamicReceiver
Receiver openDynamicReceiver(Map<String,Object> dynamicNodeProperties) throws ClientException
Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote.. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
dynamicNodeProperties
- The dynamic node properties to be applied to the node created by the remote.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDynamicReceiver
Receiver openDynamicReceiver(ReceiverOptions receiverOptions) throws ClientException
Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote.. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
receiverOptions
- The options for this receiver.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openDynamicReceiver
Receiver openDynamicReceiver(Map<String,Object> dynamicNodeProperties, ReceiverOptions receiverOptions) throws ClientException
Creates a dynamic receiver used to consume messages from the given node address. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceiver
can block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
dynamicNodeProperties
- The dynamic node properties to be applied to the node created by the remote.receiverOptions
- The options for this receiver.- Returns:
- the newly created
Receiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openStreamReceiver
StreamReceiver openStreamReceiver(String address) throws ClientException
Creates a streaming message receiver used to consume large messages from the given node address. The returnedStreamReceiver
will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returned stream receiver may not have been opened on the remote when it is returned. Some methods of theStreamReceiver
can block until the remote fully opens the receiver link, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.- Returns:
- the newly created
StreamReceiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
openStreamReceiver
StreamReceiver openStreamReceiver(String address, StreamReceiverOptions receiverOptions) throws ClientException
Creates a streaming message receiver used to consume large messages from the given node address. The returned receiver will be configured using the options provided in the givenReceiverOptions
instance. The returnedStreamReceiver
may not have been opened on the remote when it is returned. Some methods of theStreamReceiver
can block until the remote fully opens the receiver link, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The source address to attach the consumer to.receiverOptions
- The options for this receiver.- Returns:
- the newly created
StreamReceiver
instance. - Throws:
ClientException
- if an internal error occurs.
-
defaultSender
Sender defaultSender() throws ClientException
Returns the default anonymous sender used by thisConnection
forsend(Message)
calls. If the sender has not been created yet this call will initiate its creation and open with the remote peer.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs opening the default sender.ClientUnsupportedOperationException
- if the remote did not signal support for anonymous relays.
-
openSender
Sender openSender(String address) throws ClientException
Creates a sender used to send messages to the given node address. The returned sender will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returnedSender
may not have been opened on the remote when it is returned. Some methods of theSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The target address to attach to, cannot be null.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs.
-
openSender
Sender openSender(String address, SenderOptions senderOptions) throws ClientException
Creates a sender used to send messages to the given node address. The returnedSender
may not have been opened on the remote when it is returned. Some methods of theSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The target address to attach to, cannot be null.senderOptions
- The options for this sender.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs.
-
openStreamSender
StreamSender openStreamSender(String address) throws ClientException
Creates a stream sender used to send large messages to the given node address. The returned sender will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returnedStreamSender
may not have been opened on the remote when it is returned. Some methods of theStreamSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The target address to attach to, cannot be null.- Returns:
- the stream sender.
- Throws:
ClientException
- if an internal error occurs.
-
openStreamSender
StreamSender openStreamSender(String address, StreamSenderOptions senderOptions) throws ClientException
Creates a streaming sender used to send large messages to the given node address.The returned
StreamSender
may not have been opened on the remote when it is returned. Some methods of theStreamSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
address
- The target address to attach to, cannot be null.senderOptions
- The options for this sender.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs.
-
openAnonymousSender
Sender openAnonymousSender() throws ClientException
Creates a sender that is established to the 'anonymous relay' and as such each message that is sent using this sender must specify an address in its destination address field. The returned sender will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returnedSender
may not have been opened on the remote when it is returned. Some methods of theSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs.ClientUnsupportedOperationException
- if the remote did not signal support for anonymous relays.
-
openAnonymousSender
Sender openAnonymousSender(SenderOptions senderOptions) throws ClientException
Creates a sender that is established to the 'anonymous relay' and as such each message that is sent using this sender must specify an address in its destination address field. The returnedSender
may not have been opened on the remote when it is returned. Some methods of theSender
can block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theLink.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
senderOptions
- The options for this sender.- Returns:
- the sender.
- Throws:
ClientException
- if an internal error occurs.ClientUnsupportedOperationException
- if the remote did not signal support for anonymous relays.
-
defaultSession
Session defaultSession() throws ClientException
Returns the defaultSession
instance that is used by this Connection to create the default anonymous connectionSender
as well as creating those resources created from theConnection
such asSender
andReceiver
instances not married to a specificSession
.- Returns:
- a new
Session
instance. - Throws:
ClientException
- if an internal error occurs.
-
openSession
Session openSession() throws ClientException
Creates a newSession
instance for use by the client application. The returned session will be configured using default options and will take its timeout configuration values from those specified in the parentConnection
. The returnedSession
may not have been opened on the remote when it is returned. Some methods of theSession
can block until the remote fully opens the session, the user can wait for the remote to respond to the open request by calling theSession.openFuture()
method and using theFuture.get()
methods to wait for completion.- Returns:
- a new
Session
instance. - Throws:
ClientException
- if an internal error occurs.
-
openSession
Session openSession(SessionOptions options) throws ClientException
Creates a newSession
instance for use by the client application. The returnedSession
may not have been opened on the remote when it is returned. Some methods of theSession
can block until the remote fully opens the session, the user can wait for the remote to respond to the open request by calling theSession.openFuture()
method and using theFuture.get()
methods to wait for completion.- Parameters:
options
- TheSessionOptions
that control properties of the created session.- Returns:
- a new
Session
instance. - Throws:
ClientException
- if an internal error occurs.
-
send
Tracker send(Message<?> message) throws ClientException
Sends the givenMessage
using the internal connection sender.The connection
Sender
is an anonymous AMQP sender which requires that the given message has a valid to value set.- Parameters:
message
- The message to send- Returns:
- a
Tracker
that allows the client to track settlement of the message. - Throws:
ClientException
- if an internal error occurs.
-
nextReceiver
Receiver nextReceiver() throws ClientException
Waits indefinitely for a receiver created from the connection default session to have a delivery ready for receipt. The selection of the next receiver when more than one exists which has pending deliveries is based upon the configured value of theConnectionOptions.defaultNextReceiverPolicy()
.- Returns:
- the next receiver that has a pending delivery available based on policy.
- Throws:
ClientException
- if an internal error occurs.
-
nextReceiver
Receiver nextReceiver(NextReceiverPolicy policy) throws ClientException
Waits indefinitely for a receiver created from the connection default session to have a delivery ready for receipt. The selection of the next receiver when more than one exists which has pending deliveries is based upon the value of theNextReceiverPolicy
that is provided by the caller.- Parameters:
policy
- The policy to apply when selecting the next receiver.- Returns:
- the next receiver that has a pending delivery available based on policy.
- Throws:
ClientException
- if an internal error occurs.
-
nextReceiver
Receiver nextReceiver(long timeout, TimeUnit unit) throws ClientException
Waits for the configured time interval for a receiver created from the connection default session to have a delivery ready for receipt. The selection of the next receiver when more than one exists which has pending deliveries is based upon the configured value of theConnectionOptions.defaultNextReceiverPolicy()
. If no receiver has an incoming delivery before the given timeout expires the method returns null.- Parameters:
timeout
- The timeout value used to control how long the method waits for a newDelivery
to be available.unit
- The unit of time that the given timeout represents.- Returns:
- the next receiver that has a pending delivery available based on policy or null if the timeout is reached.
- Throws:
ClientException
- if an internal error occurs.
-
nextReceiver
Receiver nextReceiver(NextReceiverPolicy policy, long timeout, TimeUnit unit) throws ClientException
Waits for the configured time interval for a receiver created from the connection default session to have a delivery ready for receipt. The selection of the next receiver when more than one exists which has pending deliveries is based upon theNextReceiverPolicy
provided by the caller. If no receiver has an incoming delivery before the given timeout expires the method returns null.- Parameters:
policy
- The policy to apply when selecting the next receiver.timeout
- The timeout value used to control how long the method waits for a newDelivery
to be available.unit
- The unit of time that the given timeout represents.- Returns:
- the next receiver that has a pending delivery available based on policy or null if the timeout is reached.
- Throws:
ClientException
- if an internal error occurs.
-
properties
Map<String,Object> properties() throws ClientException
Returns the properties that the remote provided upon successfully opening theConnection
. If the open has not completed yet this method will block to await the open 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 connection has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theConnection
remote properties.
-
offeredCapabilities
String[] offeredCapabilities() throws ClientException
Returns the offered capabilities that the remote provided upon successfully opening theConnection
. If the open has not completed yet this method will block to await the open 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 connection has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theConnection
remote offered capabilities.
-
desiredCapabilities
String[] desiredCapabilities() throws ClientException
Returns the desired capabilities that the remote provided upon successfully opening theConnection
. If the open has not completed yet this method will block to await the open 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 connection has successfully opened.
- Throws:
ClientException
- if an error occurs while obtaining theConnection
remote desired capabilities.
-
-