private void initClientServer() { this.clientServer = new ClientServer(port, GatewayServer.defaultAddress(), pythonPort, GatewayServer.defaultAddress(), GatewayServer.DEFAULT_CONNECT_TIMEOUT, GatewayServer.DEFAULT_READ_TIMEOUT, ServerSocketFactory.getDefault(), SocketFactory.getDefault(), null); }
private PythonEntryPoint initPythonEntryPoint() { if (this.clientServer == null) { initClientServer(); } return (PythonEntryPoint) clientServer.getPythonServerEntryPoint(new Class[]{PythonEntryPoint.class}); }
public void exit() { if (pep != null) { pep.shutdownKernel(); pep = null; } if (clientServer != null) { clientServer.shutdown(); clientServer = null; } if (pythonProcess != null) { pythonProcess.destroy(); pythonProcess = null; } }
private ClientServer(int javaPort, InetAddress javaAddress, int pythonPort, InetAddress pythonAddress, int connectTimeout, int readTimeout, ServerSocketFactory sSocketFactory, SocketFactory socketFactory, Object entryPoint, boolean autoStartJavaServer, boolean enableMemoryManagement, String authToken) { this.javaPort = javaPort; this.javaAddress = javaAddress; this.pythonPort = pythonPort; this.pythonAddress = pythonAddress; this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; this.sSocketFactory = sSocketFactory; this.socketFactory = socketFactory; this.enableMemoryManagement = enableMemoryManagement; this.authToken = authToken; this.pythonClient = createPythonClient(); this.javaServer = createJavaServer(entryPoint, pythonClient); this.gateway = javaServer.getGateway(); pythonClient.setGateway(gateway); pythonClient.setJavaServer(javaServer); this.autoStartJavaServer = autoStartJavaServer; if (autoStartJavaServer) { this.javaServer.start(); } else { this.gateway.startup(); } }
/** * <p> * Starts the JavaServer on its own thread. * </p> * * <p> * Does nothing if autoStartJavaServer was set to true when constructing the instance. * </p> */ public void startServer() { startServer(true); }
@Override public void onShutdown() { // Reversed order of killing the script process. if (!isPythonScriptBeforeStartup()) { killPythonScript(); } if (server != null) { server.shutdown(); } if (isPythonScriptBeforeStartup()) { killPythonScript(); } }
setFacade((T) server.getPythonServerEntryPoint(new Class[] { ClassUtils.getClass(getFacadeInterfaceName()) })); } catch (Exception e) { throw SpongeUtils.wrapException(e);
public ClientServer build() { return new ClientServer(javaPort, javaAddress, pythonPort, pythonAddress, connectTimeout, readTimeout, serverSocketFactory, socketFactory, entryPoint, autoStartJavaServer, enableMemoryManagement, authToken); }