Search in sources :

Example 1 with ServerTlsContext

use of software.amazon.awssdk.crt.io.ServerTlsContext in project aws-iot-device-sdk-java-v2 by aws.

the class RpcServer method runServer.

/**
 * Runs the server in the constructor supplied event loop group
 */
public void runServer() {
    validateServiceHandler();
    if (!serverRunning.compareAndSet(false, true)) {
        throw new IllegalStateException("Failed to start IpcServer. It's already started or has not completed a prior shutdown!");
    }
    serverBootstrap = new ServerBootstrap(eventLoopGroup);
    tlsContext = tlsContextOptions != null ? new ServerTlsContext(tlsContextOptions) : null;
    listener = new ServerListener(hostname, (short) port, socketOptions, tlsContext, serverBootstrap, new ServerListenerHandler() {

        @Override
        public ServerConnectionHandler onNewConnection(ServerConnection serverConnection, int errorCode) {
            try {
                LOGGER.info("New connection code [" + CRT.awsErrorName(errorCode) + "] for " + serverConnection.getResourceLogDescription());
                final ServiceOperationMappingContinuationHandler operationHandler = new ServiceOperationMappingContinuationHandler(serverConnection, eventStreamRPCServiceHandler);
                return operationHandler;
            } catch (Throwable e) {
                LOGGER.error("Throwable caught in new connection: " + e.getMessage(), e);
                return null;
            }
        }

        @Override
        public void onConnectionShutdown(ServerConnection serverConnection, int errorCode) {
            LOGGER.info("Server connection closed code [" + CRT.awsErrorString(errorCode) + "]: " + serverConnection.getResourceLogDescription());
        }
    });
    boundPort = listener.getBoundPort();
    LOGGER.info("IpcServer started...");
}
Also used : ServerListenerHandler(software.amazon.awssdk.crt.eventstream.ServerListenerHandler) ServerTlsContext(software.amazon.awssdk.crt.io.ServerTlsContext) ServerConnection(software.amazon.awssdk.crt.eventstream.ServerConnection) ServerListener(software.amazon.awssdk.crt.eventstream.ServerListener) ServerBootstrap(software.amazon.awssdk.crt.io.ServerBootstrap)

Aggregations

ServerConnection (software.amazon.awssdk.crt.eventstream.ServerConnection)1 ServerListener (software.amazon.awssdk.crt.eventstream.ServerListener)1 ServerListenerHandler (software.amazon.awssdk.crt.eventstream.ServerListenerHandler)1 ServerBootstrap (software.amazon.awssdk.crt.io.ServerBootstrap)1 ServerTlsContext (software.amazon.awssdk.crt.io.ServerTlsContext)1