Class ClientConnection
- java.lang.Object
-
- org.apache.qpid.protonj2.client.impl.ClientConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable,Connection
public class ClientConnection extends java.lang.Object implements Connection
AConnectionimplementation that uses the Proton engine for AMQP protocol support.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckClosedOrFailed()ClientInstanceclient()voidclose()Requests a close of theConnectionat the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()is exceeded.voidclose(ErrorCondition error)Requests a close of theConnectionat the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()is exceeded.java.util.concurrent.Future<Connection>closeAsync()Requests a close of theConnectionat the remote and returns aFuturethat will be completed once the Connection has been fully closed.java.util.concurrent.Future<Connection>closeAsync(ErrorCondition error)Requests a close of theConnectionat the remote and returns aFuturethat will be completed once the Connection has been fully closed.SenderdefaultSender()Returns the default anonymous sender used by thisConnectionforConnection.send(Message)calls.SessiondefaultSession()java.lang.String[]desiredCapabilities()Returns the desired capabilities that the remote provided upon successfully opening theConnection.java.lang.String[]offeredCapabilities()Returns the offered capabilities that the remote provided upon successfully opening theConnection.SenderopenAnonymousSender()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.SenderopenAnonymousSender(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.ReceiveropenDurableReceiver(java.lang.String address, java.lang.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.ReceiveropenDurableReceiver(java.lang.String address, java.lang.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.ReceiveropenDynamicReceiver()Creates a dynamic receiver used to consume messages from the given node address.ReceiveropenDynamicReceiver(java.util.Map<java.lang.String,java.lang.Object> dynamicNodeProperties)Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote..ReceiveropenDynamicReceiver(java.util.Map<java.lang.String,java.lang.Object> dynamicNodeProperties, ReceiverOptions receiverOptions)Creates a dynamic receiver used to consume messages from the given node address.ReceiveropenDynamicReceiver(ReceiverOptions receiverOptions)Creates a dynamic receiver used to consume messages from a dynamically generated node on the remote..java.util.concurrent.Future<Connection>openFuture()When aConnectionis 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.ReceiveropenReceiver(java.lang.String address)Creates a receiver used to consumer messages from the given node address.ReceiveropenReceiver(java.lang.String address, ReceiverOptions receiverOptions)Creates a receiver used to consumer messages from the given node address.SenderopenSender(java.lang.String address)Creates a sender used to send messages to the given node address.SenderopenSender(java.lang.String address, SenderOptions senderOptions)Creates a sender used to send messages to the given node address.SessionopenSession()Creates a newSessioninstance for use by the client application.SessionopenSession(SessionOptions sessionOptions)Creates a newSessioninstance for use by the client application.StreamReceiveropenStreamReceiver(java.lang.String address)Creates a streaming message receiver used to consume large messages from the given node address.StreamReceiveropenStreamReceiver(java.lang.String address, StreamReceiverOptions receiverOptions)Creates a streaming message receiver used to consume large messages from the given node address.StreamSenderopenStreamSender(java.lang.String address)Creates a stream sender used to send large messages to the given node address.StreamSenderopenStreamSender(java.lang.String address, StreamSenderOptions senderOptions)Creates a streaming sender used to send large messages to the given node address.java.util.Map<java.lang.String,java.lang.Object>properties()Returns the properties that the remote provided upon successfully opening theConnection.Trackersend(Message<?> message)Sends the givenMessageusing the internal connection sender.java.lang.StringtoString()
-
-
-
Method Detail
-
client
public ClientInstance client()
- Specified by:
clientin interfaceConnection- Returns:
- the
Clientinstance that holds thisConnection
-
openFuture
public java.util.concurrent.Future<Connection> openFuture()
Description copied from interface:ConnectionWhen aConnectionis 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 anExceptionis thrown from theFuture.get()method when called.- Specified by:
openFuturein interfaceConnection- Returns:
- a
Futurethat will be completed when the remote opens thisConnection.
-
close
public void close()
Description copied from interface:ConnectionRequests a close of theConnectionat the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()is exceeded.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceConnection
-
close
public void close(ErrorCondition error)
Description copied from interface:ConnectionRequests a close of theConnectionat the remote and waits until the Connection has been fully closed or until the configuredConnectionOptions.closeTimeout()is exceeded.- Specified by:
closein interfaceConnection- Parameters:
error- TheErrorConditionto transmit to the remote along with the close operation.
-
closeAsync
public java.util.concurrent.Future<Connection> closeAsync()
Description copied from interface:ConnectionRequests a close of theConnectionat the remote and returns aFuturethat will be completed once the Connection has been fully closed.- Specified by:
closeAsyncin interfaceConnection- Returns:
- a
Futurethat will be completed when the remote closes thisConnection.
-
closeAsync
public java.util.concurrent.Future<Connection> closeAsync(ErrorCondition error)
Description copied from interface:ConnectionRequests a close of theConnectionat the remote and returns aFuturethat will be completed once the Connection has been fully closed.- Specified by:
closeAsyncin interfaceConnection- Parameters:
error- TheErrorConditionto transmit to the remote along with the close operation.- Returns:
- a
Futurethat will be completed when the remote closes thisConnection.
-
defaultSession
public Session defaultSession() throws ClientException
Description copied from interface:ConnectionReturns the defaultSessioninstance that is used by this Connection to create the default anonymous connectionSenderas well as creating those resources created from theConnectionsuch asSenderandReceiverinstances not married to a specificSession.- Specified by:
defaultSessionin interfaceConnection- Returns:
- a new
Sessioninstance. - Throws:
ClientException- if an internal error occurs.
-
openSession
public Session openSession() throws ClientException
Description copied from interface:ConnectionCreates a newSessioninstance 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 returnedSessionmay not have been opened on the remote when it is returned. Some methods of theSessioncan 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.- Specified by:
openSessionin interfaceConnection- Returns:
- a new
Sessioninstance. - Throws:
ClientException- if an internal error occurs.
-
openSession
public Session openSession(SessionOptions sessionOptions) throws ClientException
Description copied from interface:ConnectionCreates a newSessioninstance for use by the client application. The returnedSessionmay not have been opened on the remote when it is returned. Some methods of theSessioncan 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.- Specified by:
openSessionin interfaceConnection- Parameters:
sessionOptions- TheSessionOptionsthat control properties of the created session.- Returns:
- a new
Sessioninstance. - Throws:
ClientException- if an internal error occurs.
-
openReceiver
public Receiver openReceiver(java.lang.String address) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openReceiverin interfaceConnection- Parameters:
address- The source address to attach the consumer to.- Returns:
- the consumer.
- Throws:
ClientException- if an internal error occurs.
-
openReceiver
public Receiver openReceiver(java.lang.String address, ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:ConnectionCreates a receiver used to consumer messages from the given node address. The returned receiver will be configured using the options provided in the givenReceiverOptionsinstance. The returned receiver may not have been opened on the remote when it is returned. Some methods of theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openReceiverin interfaceConnection- Parameters:
address- The source address to attach the consumer to.receiverOptions- The options for this receiver.- Returns:
- the newly created
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDurableReceiver
public Receiver openDurableReceiver(java.lang.String address, java.lang.String subscriptionName) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDurableReceiverin interfaceConnection- Parameters:
address- The source address to attach the consumer to.subscriptionName- The name to give the subscription (link name).- Returns:
- the newly created
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDurableReceiver
public Receiver openDurableReceiver(java.lang.String address, java.lang.String subscriptionName, ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDurableReceiverin interfaceConnection- 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
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver() throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDynamicReceiverin interfaceConnection- Returns:
- the newly created
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver(java.util.Map<java.lang.String,java.lang.Object> dynamicNodeProperties) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDynamicReceiverin interfaceConnection- Parameters:
dynamicNodeProperties- The dynamic node properties to be applied to the node created by the remote.- Returns:
- the newly created
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver(ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDynamicReceiverin interfaceConnection- Parameters:
receiverOptions- The options for this receiver.- Returns:
- the newly created
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver(java.util.Map<java.lang.String,java.lang.Object> dynamicNodeProperties, ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:ConnectionCreates 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 theReceivercan block until the remote fully opens the receiver, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openDynamicReceiverin interfaceConnection- 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
Receiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openStreamReceiver
public StreamReceiver openStreamReceiver(java.lang.String address) throws ClientException
Description copied from interface:ConnectionCreates a streaming message receiver used to consume large messages from the given node address. The returnedStreamReceiverwill 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 theStreamReceivercan block until the remote fully opens the receiver link, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openStreamReceiverin interfaceConnection- Parameters:
address- The source address to attach the consumer to.- Returns:
- the newly created
StreamReceiverinstance. - Throws:
ClientException- if an internal error occurs.
-
openStreamReceiver
public StreamReceiver openStreamReceiver(java.lang.String address, StreamReceiverOptions receiverOptions) throws ClientException
Description copied from interface:ConnectionCreates 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 givenReceiverOptionsinstance. The returnedStreamReceivermay not have been opened on the remote when it is returned. Some methods of theStreamReceivercan block until the remote fully opens the receiver link, the user can wait for the remote to respond to the open request by calling theReceiver.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openStreamReceiverin interfaceConnection- Parameters:
address- The source address to attach the consumer to.receiverOptions- The options for this receiver.- Returns:
- the newly created
StreamReceiverinstance. - Throws:
ClientException- if an internal error occurs.
-
defaultSender
public Sender defaultSender() throws ClientException
Description copied from interface:ConnectionReturns the default anonymous sender used by thisConnectionforConnection.send(Message)calls. If the sender has not been created yet this call will initiate its creation and open with the remote peer.- Specified by:
defaultSenderin interfaceConnection- 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
public Sender openSender(java.lang.String address) throws ClientException
Description copied from interface:ConnectionCreates 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 returnedSendermay not have been opened on the remote when it is returned. Some methods of theSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openSenderin interfaceConnection- Parameters:
address- The target address to attach to, cannot be null.- Returns:
- the sender.
- Throws:
ClientException- if an internal error occurs.
-
openSender
public Sender openSender(java.lang.String address, SenderOptions senderOptions) throws ClientException
Description copied from interface:ConnectionCreates a sender used to send messages to the given node address. The returnedSendermay not have been opened on the remote when it is returned. Some methods of theSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openSenderin interfaceConnection- 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
public Sender openAnonymousSender() throws ClientException
Description copied from interface:ConnectionCreates 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 returnedSendermay not have been opened on the remote when it is returned. Some methods of theSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openAnonymousSenderin interfaceConnection- Returns:
- the sender.
- Throws:
ClientException- if an internal error occurs.ClientUnsupportedOperationException- if the remote did not signal support for anonymous relays.
-
openAnonymousSender
public Sender openAnonymousSender(SenderOptions senderOptions) throws ClientException
Description copied from interface:ConnectionCreates 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 returnedSendermay not have been opened on the remote when it is returned. Some methods of theSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openAnonymousSenderin interfaceConnection- 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.
-
openStreamSender
public StreamSender openStreamSender(java.lang.String address) throws ClientException
Description copied from interface:ConnectionCreates 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 returnedStreamSendermay not have been opened on the remote when it is returned. Some methods of theStreamSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openStreamSenderin interfaceConnection- Parameters:
address- The target address to attach to, cannot be null.- Returns:
- the stream sender.
- Throws:
ClientException- if an internal error occurs.
-
openStreamSender
public StreamSender openStreamSender(java.lang.String address, StreamSenderOptions senderOptions) throws ClientException
Description copied from interface:ConnectionCreates a streaming sender used to send large messages to the given node address.The returned
StreamSendermay not have been opened on the remote when it is returned. Some methods of theStreamSendercan block until the remote fully opens the sender, the user can wait for the remote to respond to the open request by calling theSender.openFuture()method and using theFuture.get()methods to wait for completion.- Specified by:
openStreamSenderin interfaceConnection- 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.
-
send
public Tracker send(Message<?> message) throws ClientException
Description copied from interface:ConnectionSends the givenMessageusing the internal connection sender.The connection
Senderis an anonymous AMQP sender which requires that the given message has a valid to value set.- Specified by:
sendin interfaceConnection- Parameters:
message- The message to send- Returns:
- a
Trackerthat allows the client to track settlement of the message. - Throws:
ClientException- if an internal error occurs.
-
properties
public java.util.Map<java.lang.String,java.lang.Object> properties() throws ClientExceptionDescription copied from interface:ConnectionReturns 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.- Specified by:
propertiesin interfaceConnection- Returns:
- any properties provided from the remote once the connection has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theConnectionremote properties.
-
offeredCapabilities
public java.lang.String[] offeredCapabilities() throws ClientExceptionDescription copied from interface:ConnectionReturns 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.- Specified by:
offeredCapabilitiesin interfaceConnection- Returns:
- any capabilities provided from the remote once the connection has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theConnectionremote offered capabilities.
-
desiredCapabilities
public java.lang.String[] desiredCapabilities() throws ClientExceptionDescription copied from interface:ConnectionReturns 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.- Specified by:
desiredCapabilitiesin interfaceConnection- Returns:
- any desired capabilities provided from the remote once the connection has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theConnectionremote desired capabilities.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
checkClosedOrFailed
protected void checkClosedOrFailed() throws ClientException- Throws:
ClientException
-
-