Package py4j
Class JavaServer
- java.lang.Object
-
- py4j.DefaultGatewayServerListener
-
- py4j.GatewayServer
-
- py4j.JavaServer
-
- All Implemented Interfaces:
java.lang.Runnable
,GatewayServerListener
,Py4JJavaServer
public class JavaServer extends GatewayServer
This class extends GatewayServer by implementing a new threading model: a thread always use the same connection to the other side so callbacks are executed in the calling thread.
For example, if Java thread 1 calls Python, and Python calls Java, the callback (from Python to Java) will be executed in Java thread 1.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class py4j.GatewayServer
GatewayServer.GatewayServerBuilder
-
-
Field Summary
-
Fields inherited from class py4j.GatewayServer
authToken, DEFAULT_ADDRESS, DEFAULT_CONNECT_TIMEOUT, DEFAULT_IPv6_ADDRESS, DEFAULT_PORT, DEFAULT_PYTHON_PORT, DEFAULT_READ_TIMEOUT, GATEWAY_SERVER_ID, PY4J_LOGGER
-
-
Constructor Summary
Constructors Constructor Description JavaServer(java.lang.Object entryPoint, int port, int connectTimeout, int readTimeout, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient)
JavaServer(java.lang.Object entryPoint, int port, int connectTimeout, int readTimeout, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, java.lang.String authToken)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Py4JServerConnection
createConnection(Gateway gateway, java.net.Socket socket)
Creates a server connection from a Python call to the Java side.-
Methods inherited from class py4j.GatewayServer
addListener, connectionStopped, defaultAddress, defaultIPv6Address, fireConnectionError, fireConnectionStarted, fireServerError, fireServerPostShutdown, fireServerPreShutdown, fireServerStarted, fireServerStopped, getAddress, getCallbackClient, getConnectTimeout, getCustomCommands, getGateway, getListeners, getListeningPort, getPort, getPythonAddress, getPythonPort, getPythonServerEntryPoint, getReadTimeout, main, processSocket, removeListener, resetCallbackClient, run, shutdown, shutdown, start, start, startSocket, turnAllLoggingOn, turnLoggingOff, turnLoggingOn
-
Methods inherited from class py4j.DefaultGatewayServerListener
connectionError, connectionStarted, serverError, serverPostShutdown, serverPreShutdown, serverStarted, serverStopped
-
-
-
-
Constructor Detail
-
JavaServer
public JavaServer(java.lang.Object entryPoint, int port, int connectTimeout, int readTimeout, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient)
- Parameters:
entryPoint
- The entry point of this Gateway. Can be null.port
- The port the GatewayServer is listening to.connectTimeout
- Time in milliseconds (0 = infinite). If a GatewayServer does not receive a connection request after this time, it closes the server socket and no other connection is accepted.readTimeout
- Time in milliseconds (0 = infinite). Once a Python program is connected, if a GatewayServer does not receive a request (e.g., a method call) after this time, the connection with the Python program is closed.customCommands
- A list of custom Command classes to augment the Server features. These commands will be accessible from Python programs. Can be null.pythonClient
- The Py4JPythonClientPerThread used to call Python.
-
JavaServer
public JavaServer(java.lang.Object entryPoint, int port, int connectTimeout, int readTimeout, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, java.lang.String authToken)
- Parameters:
entryPoint
- The entry point of this Gateway. Can be null.port
- The port the GatewayServer is listening to.connectTimeout
- Time in milliseconds (0 = infinite). If a GatewayServer does not receive a connection request after this time, it closes the server socket and no other connection is accepted.readTimeout
- Time in milliseconds (0 = infinite). Once a Python program is connected, if a GatewayServer does not receive a request (e.g., a method call) after this time, the connection with the Python program is closed.customCommands
- A list of custom Command classes to augment the Server features. These commands will be accessible from Python programs. Can be null.pythonClient
- The Py4JPythonClientPerThread used to call Python.authToken
- Token for authenticating with the callback server.
-
-
Method Detail
-
createConnection
protected Py4JServerConnection createConnection(Gateway gateway, java.net.Socket socket) throws java.io.IOException
Description copied from class:GatewayServer
Creates a server connection from a Python call to the Java side.
- Overrides:
createConnection
in classGatewayServer
- Returns:
- Throws:
java.io.IOException
-
-