Class ClientConnection

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ClientConnection
    extends CrtResource
    Wrapper around an event stream rpc client initiated connection.
    • 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 java.util.concurrent.CompletableFuture<java.lang.Void> sendProtocolMessage​(java.util.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​(java.util.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 java.util.concurrent.CompletableFuture<java.lang.Void> connect​(java.lang.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 java.util.concurrent.CompletableFuture<java.lang.Integer> getClosedFuture()
        Returns:
        a future for syncing on Connection closed.