Skip navigation links
py4j

Class GatewayServer

    • Constructor Detail

      • GatewayServer

        public GatewayServer(Object entryPoint)

        Creates a GatewayServer instance with default port (25333), default address (127.0.0.1), and default timeout value (no timeout).

        Parameters:
        entryPoint - The entry point of this Gateway. Can be null.
      • GatewayServer

        public GatewayServer(Object entryPoint,
                             int port)
        Parameters:
        entryPoint - The entry point of this Gateway. Can be null.
        port - The port the GatewayServer is listening to.
      • GatewayServer

        public GatewayServer(Object entryPoint,
                             int port,
                             int pythonPort,
                             InetAddress address,
                             InetAddress pythonAddress,
                             int connectTimeout,
                             int readTimeout,
                             List<Class<? extends py4j.commands.Command>> customCommands)
        Parameters:
        entryPoint - The entry point of this Gateway. Can be null.
        port - The port the GatewayServer is listening to.
        pythonPort - The port used by a PythonProxyHandler to connect to a Python gateway. Essentially the port used for Python callbacks.
        address - The address the GatewayServer is listening to.
        pythonAddress - The address used by a PythonProxyHandler to connect to a Python gateway.
        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.
      • GatewayServer

        public GatewayServer(Object entryPoint,
                             int port,
                             int connectTimeout,
                             int readTimeout)
        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.
      • GatewayServer

        public GatewayServer(Object entryPoint,
                             int port,
                             int pythonPort,
                             int connectTimeout,
                             int readTimeout,
                             List<Class<? extends py4j.commands.Command>> customCommands)
        Parameters:
        entryPoint - The entry point of this Gateway. Can be null.
        port - The port the GatewayServer is listening to.
        pythonPort - The port used by a PythonProxyHandler to connect to a Python gateway. Essentially the port used for Python callbacks.
        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.
      • GatewayServer

        public GatewayServer(Object entryPoint,
                             int port,
                             int connectTimeout,
                             int readTimeout,
                             List<Class<? extends py4j.commands.Command>> customCommands,
                             CallbackClient cbClient)
    • Method Detail

      • turnAllLoggingOn

        public static void turnAllLoggingOn()

        Utility method to turn logging on. Logging is turned off by default. All log messages will be logged.

      • turnLoggingOff

        public static void turnLoggingOff()

        Utility method to turn logging off. Logging is turned off by default.

      • turnLoggingOn

        public static void turnLoggingOn()

        Utility method to turn logging on. Logging is turned off by default. Log messages up to INFO level will be logged.

      • fireConnectionError

        protected void fireConnectionError(Exception e)
      • fireConnectionStarted

        protected void fireConnectionStarted(GatewayConnection gatewayConnection)
      • fireServerError

        protected void fireServerError(Exception e)
      • fireServerPostShutdown

        protected void fireServerPostShutdown()
      • fireServerPreShutdown

        protected void fireServerPreShutdown()
      • fireServerStarted

        protected void fireServerStarted()
      • fireServerStopped

        protected void fireServerStopped()
      • getConnectTimeout

        public int getConnectTimeout()
      • getListeningPort

        public int getListeningPort()
        Returns:
        The port the server socket is listening on. It will be different than the specified port if the socket is listening on an ephemeral port (specified port = 0). Returns -1 if the server socket is not listening on anything.
      • getPort

        public int getPort()
        Returns:
        The port specified when the gateway server is initialized. This is the port that is passed to the server socket.
      • getPythonAddress

        public InetAddress getPythonAddress()
      • getPythonPort

        public int getPythonPort()
      • getReadTimeout

        public int getReadTimeout()
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • shutdown

        public void shutdown()

        Stops accepting connections, closes all current connections, and calls Gateway.shutdown()

      • start

        public void start()

        Starts to accept connections in a second thread (non-blocking call).

      • start

        public void start(boolean fork)

        Starts to accept connections.

        Parameters:
        fork - If true, the GatewayServer accepts connection in another thread and this call is non-blocking. If False, the GatewayServer accepts connection in this thread and the call is blocking (until the Gateway is shutdown by another thread).
        Throws:
        Py4JNetworkException - If the server socket cannot start.
      • main

        public static void main(String[] args)

        Main method to start a local GatewayServer on a given port. The listening port is printed to stdout so that clients can start servers on ephemeral ports.

      • getCustomCommands

        public List<Class<? extends py4j.commands.Command>> getCustomCommands()
        Returns:
        An unmodifiable list of custom commands