Package py4j

Class JavaServer

All Implemented Interfaces:
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.

  • Constructor Details

    • JavaServer

      public JavaServer(Object entryPoint, int port, int connectTimeout, int readTimeout, List<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(Object entryPoint, int port, int connectTimeout, int readTimeout, List<Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, 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 Details