Package py4j
Class ClientServer
- java.lang.Object
-
- py4j.ClientServer
-
public class ClientServer extends java.lang.ObjectThis class creates the JavaServer and the PythonClient necessary to communicate with a Python virtual machine with the new threading model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClientServer.ClientServerBuilderHelper class to make it easier and self-documenting how aClientServeris constructed.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringauthTokenprotected booleanautoStartJavaServerprotected intconnectTimeoutprotected booleanenableMemoryManagementprotected Gatewaygatewayprotected java.net.InetAddressjavaAddressprotected intjavaPortprotected Py4JJavaServerjavaServerprotected java.util.logging.Loggerloggerprotected java.net.InetAddresspythonAddressprotected Py4JPythonClientPerThreadpythonClientprotected intpythonPortprotected intreadTimeoutprotected javax.net.SocketFactorysocketFactoryprotected javax.net.ServerSocketFactorysSocketFactory
-
Constructor Summary
Constructors Constructor Description ClientServer(int javaPort, java.net.InetAddress javaAddress, int pythonPort, java.net.InetAddress pythonAddress, int connectTimeout, int readTimeout, javax.net.ServerSocketFactory sSocketFactory, javax.net.SocketFactory socketFactory, java.lang.Object entryPoint)ClientServer(int javaPort, java.net.InetAddress javaAddress, int pythonPort, java.net.InetAddress pythonAddress, int connectTimeout, int readTimeout, javax.net.ServerSocketFactory sSocketFactory, javax.net.SocketFactory socketFactory, java.lang.Object entryPoint, boolean autoStartJavaServer, boolean enableMemoryManagement)ClientServer(java.lang.Object entryPoint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Py4JJavaServercreateJavaServer(java.lang.Object entryPoint, Py4JPythonClientPerThread pythonClient)protected Py4JPythonClientPerThreadcreatePythonClient()Py4JJavaServergetJavaServer()Py4JPythonClientgetPythonClient()java.lang.ObjectgetPythonServerEntryPoint(java.lang.Class[] interfacesToImplement)Gets a reference to the entry point on the Python side.voidshutdown()Shuts down the Java Server so that it stops accepting requests and it closes existing connections.voidstartServer()Starts the JavaServer on its own thread.voidstartServer(boolean fork)Starts the JavaServer, which will handle requests from the Python side.
-
-
-
Field Detail
-
javaPort
protected final int javaPort
-
javaAddress
protected final java.net.InetAddress javaAddress
-
pythonPort
protected final int pythonPort
-
pythonAddress
protected final java.net.InetAddress pythonAddress
-
connectTimeout
protected final int connectTimeout
-
readTimeout
protected final int readTimeout
-
sSocketFactory
protected final javax.net.ServerSocketFactory sSocketFactory
-
socketFactory
protected final javax.net.SocketFactory socketFactory
-
gateway
protected final Gateway gateway
-
javaServer
protected final Py4JJavaServer javaServer
-
pythonClient
protected final Py4JPythonClientPerThread pythonClient
-
autoStartJavaServer
protected final boolean autoStartJavaServer
-
enableMemoryManagement
protected final boolean enableMemoryManagement
-
authToken
protected final java.lang.String authToken
-
logger
protected final java.util.logging.Logger logger
-
-
Constructor Detail
-
ClientServer
public ClientServer(java.lang.Object entryPoint)
- Parameters:
entryPoint-
-
ClientServer
public ClientServer(int javaPort, java.net.InetAddress javaAddress, int pythonPort, java.net.InetAddress pythonAddress, int connectTimeout, int readTimeout, javax.net.ServerSocketFactory sSocketFactory, javax.net.SocketFactory socketFactory, java.lang.Object entryPoint)- Parameters:
javaPort-javaAddress-pythonPort-pythonAddress-connectTimeout-readTimeout-sSocketFactory-socketFactory-entryPoint-
-
ClientServer
public ClientServer(int javaPort, java.net.InetAddress javaAddress, int pythonPort, java.net.InetAddress pythonAddress, int connectTimeout, int readTimeout, javax.net.ServerSocketFactory sSocketFactory, javax.net.SocketFactory socketFactory, java.lang.Object entryPoint, boolean autoStartJavaServer, boolean enableMemoryManagement)- Parameters:
javaPort-javaAddress-pythonPort-pythonAddress-connectTimeout-readTimeout-sSocketFactory-socketFactory-entryPoint-autoStartJavaServer-enableMemoryManagement-
-
-
Method Detail
-
createPythonClient
protected Py4JPythonClientPerThread createPythonClient()
-
createJavaServer
protected Py4JJavaServer createJavaServer(java.lang.Object entryPoint, Py4JPythonClientPerThread pythonClient)
-
getJavaServer
public Py4JJavaServer getJavaServer()
-
getPythonClient
public Py4JPythonClient getPythonClient()
-
startServer
public void startServer()
Starts the JavaServer on its own thread.
Does nothing if autoStartJavaServer was set to true when constructing the instance.
-
startServer
public void startServer(boolean fork)
Starts the JavaServer, which will handle requests from the Python side.
Does nothing if autoStartJavaServer was set to true when constructing the instance.
- Parameters:
fork- If the JavaServer is started in this thread or in its own thread.
-
shutdown
public void shutdown()
Shuts down the Java Server so that it stops accepting requests and it closes existing connections.
-
getPythonServerEntryPoint
public java.lang.Object getPythonServerEntryPoint(java.lang.Class[] interfacesToImplement)
Gets a reference to the entry point on the Python side. This is often necessary if Java is driving the communication because Java cannot call static methods, initialize Python objects or load Python modules yet.
- Parameters:
interfacesToImplement-- Returns:
-
-