Package py4j
Class ClientServer
java.lang.Object
py4j.ClientServer
This class creates the JavaServer and the PythonClient necessary to communicate with a Python virtual machine with the new threading model.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Helper class to make it easier and self-documenting how aClientServer
is constructed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String
protected final boolean
protected final int
protected final boolean
protected final Gateway
protected final InetAddress
protected final int
protected final Py4JJavaServer
protected final Logger
protected final InetAddress
protected final Py4JPythonClientPerThread
protected final int
protected final int
protected final SocketFactory
protected final ServerSocketFactory
-
Constructor Summary
ConstructorsConstructorDescriptionClientServer
(int javaPort, InetAddress javaAddress, int pythonPort, InetAddress pythonAddress, int connectTimeout, int readTimeout, ServerSocketFactory sSocketFactory, SocketFactory socketFactory, Object entryPoint) ClientServer
(int javaPort, InetAddress javaAddress, int pythonPort, InetAddress pythonAddress, int connectTimeout, int readTimeout, ServerSocketFactory sSocketFactory, SocketFactory socketFactory, Object entryPoint, boolean autoStartJavaServer, boolean enableMemoryManagement) ClientServer
(Object entryPoint) -
Method Summary
Modifier and TypeMethodDescriptionprotected Py4JJavaServer
createJavaServer
(Object entryPoint, Py4JPythonClientPerThread pythonClient) protected Py4JPythonClientPerThread
getPythonServerEntryPoint
(Class[] interfacesToImplement) Gets a reference to the entry point on the Python side.void
shutdown()
Shuts down the Java Server so that it stops accepting requests and it closes existing connections.void
Starts the JavaServer on its own thread.void
startServer
(boolean fork) Starts the JavaServer, which will handle requests from the Python side.
-
Field Details
-
javaPort
protected final int javaPort -
javaAddress
-
pythonPort
protected final int pythonPort -
pythonAddress
-
connectTimeout
protected final int connectTimeout -
readTimeout
protected final int readTimeout -
sSocketFactory
-
socketFactory
-
gateway
-
javaServer
-
pythonClient
-
autoStartJavaServer
protected final boolean autoStartJavaServer -
enableMemoryManagement
protected final boolean enableMemoryManagement -
authToken
-
logger
-
-
Constructor Details
-
ClientServer
- Parameters:
entryPoint
-
-
ClientServer
public ClientServer(int javaPort, InetAddress javaAddress, int pythonPort, InetAddress pythonAddress, int connectTimeout, int readTimeout, ServerSocketFactory sSocketFactory, SocketFactory socketFactory, Object entryPoint) - Parameters:
javaPort
-javaAddress
-pythonPort
-pythonAddress
-connectTimeout
-readTimeout
-sSocketFactory
-socketFactory
-entryPoint
-
-
ClientServer
public ClientServer(int javaPort, InetAddress javaAddress, int pythonPort, InetAddress pythonAddress, int connectTimeout, int readTimeout, ServerSocketFactory sSocketFactory, SocketFactory socketFactory, Object entryPoint, boolean autoStartJavaServer, boolean enableMemoryManagement) - Parameters:
javaPort
-javaAddress
-pythonPort
-pythonAddress
-connectTimeout
-readTimeout
-sSocketFactory
-socketFactory
-entryPoint
-autoStartJavaServer
-enableMemoryManagement
-
-
-
Method Details
-
createPythonClient
-
createJavaServer
protected Py4JJavaServer createJavaServer(Object entryPoint, Py4JPythonClientPerThread pythonClient) -
getJavaServer
-
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
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:
-