Class ClientSession
- java.lang.Object
-
- org.apache.qpid.protonj2.client.impl.ClientSession
-
- All Implemented Interfaces:
java.lang.AutoCloseable,Session
- Direct Known Subclasses:
ClientStreamSession
public class ClientSession extends java.lang.Object implements Session
Client implementation of the Session API.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SessionbeginTransaction()Opens a new transaction scoped to thisSessionif one is not already active.protected voidcheckClosedOrFailed()ClientInstanceclient()voidclose()Requests a close of theSessionat the remote and waits until the Session has been fully closed or until the configuredSessionOptions.closeTimeout()is exceeded.voidclose(ErrorCondition error)Requests a close of theSessionat the remote and waits until the Session has been fully closed or until the configuredSessionOptions.closeTimeout()is exceeded.java.util.concurrent.Future<Session>closeAsync()Requests a close of theSessionat the remote and returns aFuturethat will be completed once the session has been remotely closed or an error occurs.java.util.concurrent.Future<Session>closeAsync(ErrorCondition error)Requests a close of theSessionat the remote and returns aFuturethat will be completed once the session has been remotely closed or an error occurs.SessioncommitTransaction()Commit the currently active transaction in this Session.ClientConnectionconnection()java.lang.String[]desiredCapabilities()Returns the desired capabilities that the remote provided upon successfully opening theSession.java.lang.String[]offeredCapabilities()Returns the offered capabilities that the remote provided upon successfully opening theSession.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 the given node address.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 the given node address.java.util.concurrent.Future<Session>openFuture()ReceiveropenReceiver(java.lang.String address)Creates a receiver used to consume messages from the given node address.ReceiveropenReceiver(java.lang.String address, ReceiverOptions receiverOptions)Creates a receiver used to consume 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.java.util.Map<java.lang.String,java.lang.Object>properties()Returns the properties that the remote provided upon successfully opening theSession.SessionrollbackTransaction()Roll back the currently active transaction in this Session.
-
-
-
Method Detail
-
client
public ClientInstance client()
- Specified by:
clientin interfaceSession- Returns:
- the
Clientinstance that holds this session'sConnection
-
connection
public ClientConnection connection()
- Specified by:
connectionin interfaceSession- Returns:
- the
Connectionthat created and holds thisSession.
-
openFuture
public java.util.concurrent.Future<Session> openFuture()
- Specified by:
openFuturein interfaceSession- Returns:
- a
Futurethat will be completed when the remote opens thisSession.
-
close
public void close()
Description copied from interface:SessionRequests a close of theSessionat the remote and waits until the Session has been fully closed or until the configuredSessionOptions.closeTimeout()is exceeded.
-
close
public void close(ErrorCondition error)
Description copied from interface:SessionRequests a close of theSessionat the remote and waits until the Session has been fully closed or until the configuredSessionOptions.closeTimeout()is exceeded.- Specified by:
closein interfaceSession- Parameters:
error- TheErrorConditionto transmit to the remote along with the close operation.
-
closeAsync
public java.util.concurrent.Future<Session> closeAsync()
Description copied from interface:SessionRequests a close of theSessionat the remote and returns aFuturethat will be completed once the session has been remotely closed or an error occurs.- Specified by:
closeAsyncin interfaceSession- Returns:
- a
Futurethat will be completed when the remote closes thisSession.
-
closeAsync
public java.util.concurrent.Future<Session> closeAsync(ErrorCondition error)
Description copied from interface:SessionRequests a close of theSessionat the remote and returns aFuturethat will be completed once the session has been remotely closed or an error occurs.- Specified by:
closeAsyncin interfaceSession- Parameters:
error- TheErrorConditionto transmit to the remote along with the close operation.- Returns:
- a
Futurethat will be completed when the remote closes thisSession.
-
openReceiver
public Receiver openReceiver(java.lang.String address) throws ClientException
Description copied from interface:SessionCreates a receiver used to consume messages from the given node address.- Specified by:
openReceiverin interfaceSession- Parameters:
address- The source address to attach the consumer to.- Returns:
- the newly created
Receiver - Throws:
ClientException- if an internal error occurs.
-
openReceiver
public Receiver openReceiver(java.lang.String address, ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:SessionCreates a receiver used to consume messages from the given node address.- Specified by:
openReceiverin interfaceSession- Parameters:
address- The source address to attach the consumer to.receiverOptions- The options for this receiver.- Returns:
- the newly created
Receiver - 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:SessionCreates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node.- Specified by:
openDurableReceiverin interfaceSession- Parameters:
address- The source address to attach the consumer to.subscriptionName- The name to give the subscription (link name).- Returns:
- the newly created
Receiver - 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:SessionCreates a receiver used to consume messages from the given node address and configure it such that the remote create a durable node.- Specified by:
openDurableReceiverin interfaceSession- 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 - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver() throws ClientException
Description copied from interface:SessionCreates a dynamic receiver used to consume messages from the given node address.- Specified by:
openDynamicReceiverin interfaceSession- Returns:
- the newly created
Receiver - 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:SessionCreates a dynamic receiver used to consume messages from the given node address.- Specified by:
openDynamicReceiverin interfaceSession- Parameters:
dynamicNodeProperties- The dynamic node properties to be applied to the node created by the remote.- Returns:
- the newly created
Receiver - Throws:
ClientException- if an internal error occurs.
-
openDynamicReceiver
public Receiver openDynamicReceiver(ReceiverOptions receiverOptions) throws ClientException
Description copied from interface:SessionCreates a dynamic receiver used to consume messages from the given node address.- Specified by:
openDynamicReceiverin interfaceSession- Parameters:
receiverOptions- The options for this receiver.- Returns:
- the newly created
Receiver - 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:SessionCreates a dynamic receiver used to consume messages from the given node address.- Specified by:
openDynamicReceiverin interfaceSession- 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 - Throws:
ClientException- if an internal error occurs.
-
openSender
public Sender openSender(java.lang.String address) throws ClientException
Description copied from interface:SessionCreates a sender used to send messages to the given node address. If no address (i.e null) is specified then a sender will be established to the 'anonymous relay' and each message must specify its destination address.- Specified by:
openSenderin interfaceSession- Parameters:
address- The target address to attach to, or null to attach to the anonymous relay.- Returns:
- the newly created
Sender. - Throws:
ClientException- if an internal error occurs.
-
openSender
public Sender openSender(java.lang.String address, SenderOptions senderOptions) throws ClientException
Description copied from interface:SessionCreates a sender used to send messages to the given node address. If no address (i.e null) is specified then a sender will be established to the 'anonymous relay' and each message must specify its destination address.- Specified by:
openSenderin interfaceSession- Parameters:
address- The target address to attach to, or null to attach to the anonymous relay.senderOptions- The options for this sender.- Returns:
- the newly created
Sender. - Throws:
ClientException- if an internal error occurs.
-
openAnonymousSender
public Sender openAnonymousSender() throws ClientException
Description copied from interface:SessionCreates 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.- Specified by:
openAnonymousSenderin interfaceSession- Returns:
- the newly created
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:SessionCreates 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.- Specified by:
openAnonymousSenderin interfaceSession- Parameters:
senderOptions- The options for this sender.- Returns:
- the newly created
Sender. - Throws:
ClientException- if an internal error occurs.ClientUnsupportedOperationException- if the remote did not signal support for anonymous relays.
-
properties
public java.util.Map<java.lang.String,java.lang.Object> properties() throws ClientExceptionDescription copied from interface:SessionReturns the properties that the remote provided upon successfully opening theSession. 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 interfaceSession- Returns:
- any properties provided from the remote once the session has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theSessionremote properties.
-
offeredCapabilities
public java.lang.String[] offeredCapabilities() throws ClientExceptionDescription copied from interface:SessionReturns the offered capabilities that the remote provided upon successfully opening theSession. 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 interfaceSession- Returns:
- any capabilities provided from the remote once the session has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theSessionremote offered capabilities.
-
desiredCapabilities
public java.lang.String[] desiredCapabilities() throws ClientExceptionDescription copied from interface:SessionReturns the desired capabilities that the remote provided upon successfully opening theSession. 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 interfaceSession- Returns:
- any desired capabilities provided from the remote once the session has successfully opened.
- Throws:
ClientException- if an error occurs while obtaining theSessionremote desired capabilities.
-
beginTransaction
public Session beginTransaction() throws ClientException
Description copied from interface:SessionOpens a new transaction scoped to thisSessionif one is not already active. ASessionthat has an active transaction will perform all sends and all delivery dispositions under that active transaction. If the user wishes to send with the same session but outside of a transaction they user must commit the active transaction and not request that a new one be started. A session can only have one active transaction at a time and as such any call to begin while there is a currently active transaction will throw anClientTransactionNotActiveExceptionto indicate that the operation being requested is not valid at that time. This is a blocking method that will return successfully only after a new transaction has been started.- Specified by:
beginTransactionin interfaceSession- Returns:
- this
Sessioninstance. - Throws:
ClientException- if an error occurs while attempting to begin a new transaction.
-
commitTransaction
public Session commitTransaction() throws ClientException
Description copied from interface:SessionCommit the currently active transaction in this Session. Commit the currently active transaction in this Session but does not start a new transaction automatically. If there is no current transaction this method will throw anClientTransactionNotActiveExceptionto indicate this error. If the active transaction has entered an in doubt state or was remotely rolled back this method will throw an error to indicate that the commit failed and that a new transaction need to be started by the user. When a transaction rolled back error occurs the user should assume that all work performed under that transaction has failed and will need to be attempted under a new transaction. This is a blocking method that will return successfully only after the current transaction has been committed.- Specified by:
commitTransactionin interfaceSession- Returns:
- this
Sessioninstance. - Throws:
ClientException- if an error occurs while attempting to commit the current transaction.
-
rollbackTransaction
public Session rollbackTransaction() throws ClientException
Description copied from interface:SessionRoll back the currently active transaction in this Session. Roll back the currently active transaction in this Session but does not automatically start a new transaction. If there is no current transaction this method will throw anClientTransactionNotActiveExceptionto indicate this error. If the active transaction has entered an in doubt state or was remotely rolled back this method will throw an error to indicate that the roll back failed and that a new transaction need to be started by the user.- Specified by:
rollbackTransactionin interfaceSession- Returns:
- this
Sessioninstance. - Throws:
ClientException- if an error occurs while attempting to roll back the current transaction.
-
checkClosedOrFailed
protected void checkClosedOrFailed() throws ClientException- Throws:
ClientException
-
-