Class ClientConnection
- java.lang.Object
-
- software.amazon.awssdk.crt.CrtResource
-
- software.amazon.awssdk.crt.eventstream.ClientConnection
-
- All Implemented Interfaces:
AutoCloseable
public class ClientConnection extends CrtResource
Wrapper around an event stream rpc client initiated connection.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class software.amazon.awssdk.crt.CrtResource
CrtResource.ResourceInstance
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canReleaseReferencesImmediately()
Override that determines whether a resource releases its dependencies at the same time the native handle is released or if it waits.void
closeConnection(int shutdownErrorCode)
Closes the connection if it hasn't been closed already.static CompletableFuture<Void>
connect(String hostName, short port, SocketOptions socketOptions, ClientTlsContext tlsContext, ClientBootstrap bootstrap, ClientConnectionHandler connectionHandler)
Initiates a new outgoing event-stream-rpc connection.CompletableFuture<Integer>
getClosedFuture()
boolean
isOpen()
ClientConnectionContinuation
newStream(ClientConnectionContinuationHandler continuationHandler)
Create a new stream.protected void
releaseNativeHandle()
Required override method that must begin the release process of the acquired native handleCompletableFuture<Void>
sendProtocolMessage(List<Header> headers, byte[] payload, MessageType messageType, int messageFlags)
Sends a protocol message on the connection.void
sendProtocolMessage(List<Header> headers, byte[] payload, MessageType messageType, int messageFlags, MessageFlushCallback callback)
Sends a protocol message on the connection.-
Methods inherited from class software.amazon.awssdk.crt.CrtResource
acquireNativeHandle, addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, releaseReferences, removeReferenceTo, setDescription, swapReferenceTo, waitForNoResources
-
-
-
-
Method Detail
-
closeConnection
public void closeConnection(int shutdownErrorCode)
Closes the connection if it hasn't been closed already.- Parameters:
shutdownErrorCode
- aws-c-* error code to shutdown with. Specify 0 for success.
-
isOpen
public boolean isOpen()
- Returns:
- true if the connection is open, false otherwise.
-
sendProtocolMessage
public CompletableFuture<Void> sendProtocolMessage(List<Header> headers, byte[] payload, MessageType messageType, int messageFlags)
Sends a protocol message on the connection. Returns a completable future for synchronizing on the message flushing to the underlying transport.- Parameters:
headers
- List of event-stream headers. Can be null.payload
- Payload to send for the message. Can be null.messageType
- Message type for the rpc message.messageFlags
- Union of message flags from MessageFlags.getByteValue()- Returns:
- completable future for synchronizing on the message flushing to the underlying transport.
-
sendProtocolMessage
public void sendProtocolMessage(List<Header> headers, byte[] payload, MessageType messageType, int messageFlags, MessageFlushCallback callback)
Sends a protocol message on the connection. Callback will be invoked upon the message flushing to the underlying transport- Parameters:
headers
- List of event-stream headers. Can be null.payload
- Payload to send for the message. Can be null.messageType
- Message type for the rpc message.messageFlags
- Union of message flags from MessageFlags.getByteValue()callback
- will be invoked upon the message flushing to the underlying transport
-
newStream
public ClientConnectionContinuation newStream(ClientConnectionContinuationHandler continuationHandler)
Create a new stream. Activate() must be called on the stream for it to actually initiate the new stream.- Parameters:
continuationHandler
- handler to process continuation messages and state changes.- Returns:
- The new continuation object.
-
connect
public static CompletableFuture<Void> connect(String hostName, short port, SocketOptions socketOptions, ClientTlsContext tlsContext, ClientBootstrap bootstrap, ClientConnectionHandler connectionHandler)
Initiates a new outgoing event-stream-rpc connection. The future will be completed once the connection either succeeds or fails.- Parameters:
hostName
- hostname to connect to, this can be an IPv4 address, IPv6 address, a local socket address, or a dns name.port
- port to connect to hostName with. For local socket address, this value is ignored.socketOptions
- socketOptions to use.tlsContext
- (optional) tls context to use for using SSL/TLS in the connection.bootstrap
- clientBootstrap object to run the connection on.connectionHandler
- handler to process connection messages and state changes.- Returns:
- The future will be completed once the connection either succeeds or fails.
-
getClosedFuture
public CompletableFuture<Integer> getClosedFuture()
- Returns:
- a future for syncing on Connection closed.
-
releaseNativeHandle
protected void releaseNativeHandle()
Description copied from class:CrtResource
Required override method that must begin the release process of the acquired native handle- Specified by:
releaseNativeHandle
in classCrtResource
-
canReleaseReferencesImmediately
protected boolean canReleaseReferencesImmediately()
Description copied from class:CrtResource
Override that determines whether a resource releases its dependencies at the same time the native handle is released or if it waits. Resources with asynchronous shutdown processes should override this with false, and establish a callback from native code that invokes releaseReferences() when the asynchronous shutdown process has completed. See HttpClientConnectionManager for an example.- Specified by:
canReleaseReferencesImmediately
in classCrtResource
- Returns:
- true if this resource releases synchronously, false if this resource performs async shutdown
-
-