Package py4j
Class ClientServer
- java.lang.Object
-
- py4j.ClientServer
-
public class ClientServer extends java.lang.Object
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 Classes Modifier and Type Class Description static class
ClientServer.ClientServerBuilder
Helper class to make it easier and self-documenting how aClientServer
is constructed.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
authToken
protected boolean
autoStartJavaServer
protected int
connectTimeout
protected boolean
enableMemoryManagement
protected Gateway
gateway
protected java.net.InetAddress
javaAddress
protected int
javaPort
protected Py4JJavaServer
javaServer
protected java.util.logging.Logger
logger
protected java.net.InetAddress
pythonAddress
protected Py4JPythonClientPerThread
pythonClient
protected int
pythonPort
protected int
readTimeout
protected javax.net.SocketFactory
socketFactory
protected javax.net.ServerSocketFactory
sSocketFactory
-
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 Py4JJavaServer
createJavaServer(java.lang.Object entryPoint, Py4JPythonClientPerThread pythonClient)
protected Py4JPythonClientPerThread
createPythonClient()
Py4JJavaServer
getJavaServer()
Py4JPythonClient
getPythonClient()
java.lang.Object
getPythonServerEntryPoint(java.lang.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
startServer()
Starts the JavaServer on its own thread.void
startServer(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:
-
-