use of py4j.Gateway in project flink by apache.
the class PythonEnvUtils method startGatewayServer.
/**
* Creates a GatewayServer run in a daemon thread.
*
* @return The created GatewayServer
*/
static GatewayServer startGatewayServer() throws ExecutionException, InterruptedException {
CompletableFuture<GatewayServer> gatewayServerFuture = new CompletableFuture<>();
Thread thread = new Thread(() -> {
try (NetUtils.Port port = NetUtils.getAvailablePort()) {
int freePort = port.getPort();
GatewayServer server = new GatewayServer.GatewayServerBuilder().gateway(new Gateway(new ConcurrentHashMap<String, Object>(), new CallbackClient(freePort))).javaPort(0).build();
resetCallbackClientExecutorService(server);
gatewayServerFuture.complete(server);
server.start(true);
} catch (Throwable e) {
gatewayServerFuture.completeExceptionally(e);
}
});
thread.setName("py4j-gateway");
thread.setDaemon(true);
thread.start();
thread.join();
return gatewayServerFuture.get();
}
Aggregations