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 void
closeConnection(int shutdownErrorCode)
Closes the connection if it hasn't been closed already.static CompletableFuture<Void>
connect(String hostName, int 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.CompletableFuture<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
addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, logNativeResources, removeReferenceTo, setDescription, 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, int 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. For 32bit values exceeding Integer.MAX_VALUE use two's complement (i.e. -1 == 0xFFFFFFFF).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.
-
-