use of software.amazon.awssdk.crt.eventstream.ServerListenerHandler 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...");
}
use of software.amazon.awssdk.crt.eventstream.ServerListenerHandler in project aws-greengrass-nucleus by aws-greengrass.
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());
}
});
LOGGER.info("IpcServer started...");
}
Aggregations