use of com.aws.greengrass.ipc.common.DefaultOperationHandler in project aws-greengrass-nucleus by aws-greengrass.
the class IPCEventStreamService method startup.
@SuppressWarnings({ "PMD.AvoidCatchingGenericException", "PMD.ExceptionAsFlowControl" })
@Override
public void startup() {
Path rootPath = kernel.getNucleusPaths().rootPath();
try {
greengrassCoreIPCService.getAllOperations().forEach(operation -> greengrassCoreIPCService.setOperationHandler(operation, (context) -> new DefaultOperationHandler(GreengrassCoreIPCServiceModel.getInstance().getOperationModelContext(operation), context)));
greengrassCoreIPCService.setAuthenticationHandler((List<Header> headers, byte[] bytes) -> ipcAuthenticationHandler(bytes));
greengrassCoreIPCService.setAuthorizationHandler(this::ipcAuthorizationHandler);
socketOptions = new SocketOptions();
socketOptions.connectTimeoutMs = 3000;
socketOptions.domain = SocketOptions.SocketDomain.LOCAL;
socketOptions.type = SocketOptions.SocketType.STREAM;
eventLoopGroup = new EventLoopGroup(1);
Topic kernelUri = config.getRoot().lookup(SETENV_CONFIG_NAMESPACE, NUCLEUS_DOMAIN_SOCKET_FILEPATH);
kernelUri.withValue(Platform.getInstance().prepareIpcFilepath(rootPath));
Topic kernelRelativeUri = config.getRoot().lookup(SETENV_CONFIG_NAMESPACE, NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT);
kernelRelativeUri.withValue(Platform.getInstance().prepareIpcFilepathForComponent(rootPath));
// For domain sockets:
// 1. Port number is ignored. RpcServer does not accept a null value so we are using a default value.
// 2. The hostname parameter expects the socket filepath
rpcServer = new RpcServer(eventLoopGroup, socketOptions, null, Platform.getInstance().prepareIpcFilepathForRpcServer(rootPath), DEFAULT_PORT_NUMBER, greengrassCoreIPCService);
rpcServer.runServer();
} catch (RuntimeException e) {
// Make sure to cleanup anything we created since we don't know where exactly we failed
close();
throw e;
}
logger.debug("Set IPC permissions");
Platform.getInstance().setIpcFilePermissions(rootPath);
}
Aggregations