GatewayConnection (py4j-java 0.10.9.4 API)
Date: 2022-03-16

py4j

## Class GatewayConnection

- java.lang.Object
- - py4j.GatewayConnection

- All Implemented Interfaces:
    java.lang.Runnable, Py4JServerConnection

      public class GatewayConnection
      extends java.lang.Object
      implements java.lang.Runnable, Py4JServerConnection

  Manage the connection between a Python program and a Gateway. A GatewayConnection lives in its own thread and is created on demand (e.g., one per concurrent thread).

  The request to connect to the JVM goes through the `GatewayServer` first and is then passed to a GatewayConnection.

  This class is not intended to be directly accessed by users.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected AuthCommand` | `authCommand`
    `protected java.lang.String` | `authToken`
    `protected java.util.Map<java.lang.String,Command>` | `commands`
    `protected java.util.List<GatewayServerListener>` | `listeners`
    `protected java.util.logging.Logger` | `logger`
    `protected java.io.BufferedReader` | `reader`
    `protected java.net.Socket` | `socket`
    `protected java.io.BufferedWriter` | `writer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GatewayConnection(Gateway gateway, java.net.Socket socket)`
    `GatewayConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, java.util.List<GatewayServerListener> listeners)`
    `GatewayConnection(Gateway gateway, java.net.Socket socket, java.lang.String authToken, java.util.List<java.lang.Class<? extends Command>> customCommands, java.util.List<GatewayServerListener> listeners)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `fireConnectionStopped()`
    `static java.util.List<java.lang.Class<? extends Command>>` | `getBaseCommands()`
    `java.net.Socket` | `getSocket()`
    `protected void` | `initCommands(Gateway gateway, java.util.List<java.lang.Class<? extends Command>> commandsClazz)` Override this method to initialize custom commands.
    `protected void` | `quietSendFatalError(java.io.BufferedWriter writer, java.lang.Throwable exception)`
    `void` | `run()`
    `void` | `shutdown()`
    `void` | `shutdown(boolean reset)` Shuts down the connection by closing the socket, the writer, and the reader.
    `void` | `startConnection()` Wraps the GatewayConnection in a thread and start the thread.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### socket

          protected final java.net.Socket socket

    - #### authToken

          protected final java.lang.String authToken

    - #### authCommand

          protected final AuthCommand authCommand

    - #### writer

          protected final java.io.BufferedWriter writer

    - #### reader

          protected final java.io.BufferedReader reader

    - #### commands

          protected final java.util.Map<java.lang.String,Command> commands

    - #### logger

          protected final java.util.logging.Logger logger

    - #### listeners

          protected final java.util.List<GatewayServerListener> listeners

  - ### Constructor Detail

    - #### GatewayConnection

          public GatewayConnection(Gateway gateway,
                                   java.net.Socket socket)
                            throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### GatewayConnection

          public GatewayConnection(Gateway gateway,
                                   java.net.Socket socket,
                                   java.util.List<java.lang.Class<? extends Command>> customCommands,
                                   java.util.List<GatewayServerListener> listeners)
                            throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### GatewayConnection

          public GatewayConnection(Gateway gateway,
                                   java.net.Socket socket,
                                   java.lang.String authToken,
                                   java.util.List<java.lang.Class<? extends Command>> customCommands,
                                   java.util.List<GatewayServerListener> listeners)
                            throws java.io.IOException

      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### getBaseCommands

          public static java.util.List<java.lang.Class<? extends Command>> getBaseCommands()

      Returns:
        The list of base commands that are provided by default. Can be hidden by custom commands with the same command id by passing a list of custom commands to the `GatewayServer`.

    - #### startConnection

          public void startConnection()

      Wraps the GatewayConnection in a thread and start the thread.

    - #### fireConnectionStopped

          protected void fireConnectionStopped()

    - #### getSocket

          public java.net.Socket getSocket()

      Specified by:
        `getSocket` in interface `Py4JServerConnection`
      Returns:
        The socket used by this gateway connection.

    - #### initCommands

          protected void initCommands(Gateway gateway,
                                      java.util.List<java.lang.Class<? extends Command>> commandsClazz)

      Override this method to initialize custom commands.

      Parameters:
        `gateway` -

    - #### quietSendFatalError

          protected void quietSendFatalError(java.io.BufferedWriter writer,
                                             java.lang.Throwable exception)

    - #### run

          public void run()

      Specified by:
        `run` in interface `java.lang.Runnable`

    - #### shutdown

          public void shutdown()

      Specified by:
        `shutdown` in interface `Py4JServerConnection`

    - #### shutdown

          public void shutdown(boolean reset)

      Shuts down the connection by closing the socket, the writer, and the reader.

      Internal: emits a connection stopped signal so GatewayServer can remove the connection from the connections list. In rare occasions, the shutdown method may be called twice (when the server shuts down at the same time as the connection fails and shuts down).

      Specified by:
        `shutdown` in interface `Py4JServerConnection`