in src/main/java/com/aws/iot/edgeconnectorforkvs/util/IPCUtils.java [51:92]
private static EventStreamRPCConnection connectToGGCOverEventStreamIPC(String authToken,
String ipcServerSocketPath)
throws ExecutionException, InterruptedException {
try (EventLoopGroup elGroup = new EventLoopGroup(1);
ClientBootstrap clientBootstrap = new ClientBootstrap(elGroup, null)) {
SocketOptions socketOptions = getSocketOptionsForIPC();
final EventStreamRPCConnectionConfig config =
new EventStreamRPCConnectionConfig(clientBootstrap, elGroup, socketOptions, null,
ipcServerSocketPath, DEFAULT_PORT_NUMBER,
GreengrassConnectMessageSupplier.connectMessageSupplier(authToken));
final CompletableFuture<Void> connected = new CompletableFuture<>();
final EventStreamRPCConnection connection = getConnectionInstance(config);
final boolean[] disconnected = {false};
final int[] disconnectedCode = {-1};
connection.connect(new EventStreamRPCConnection.LifecycleHandler() {
@Override
public void onConnect() {
connected.complete(null);
}
@Override
public void onDisconnect(int errorCode) {
disconnected[0] = true;
disconnectedCode[0] = errorCode;
clientConnection = null;
}
@Override
public boolean onError(Throwable t) {
connected.completeExceptionally(t);
clientConnection = null;
return true;
}
});
// waits for future to complete
connected.get();
return connection;
}
}