py4j

## Class GatewayConnection

- java.lang.Object
- - py4j.GatewayConnection

- All Implemented Interfaces:
    Runnable

      public class GatewayConnection
      extends Object
      implements Runnable

  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.

  Author:
    Barthelemy Dagenais

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static List<Class<? extends Command>>` | `baseCommands`
    `protected Map<String,Command>` | `commands`
    `protected List<GatewayServerListener>` | `listeners`
    `protected Logger` | `logger`
    `protected BufferedReader` | `reader`
    `protected Socket` | `socket`
    `protected BufferedWriter` | `writer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GatewayConnection(Gateway gateway, Socket socket)`
    `GatewayConnection(Gateway gateway, Socket socket, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `fireConnectionStopped()`
    `static List<Class<? extends Command>>` | `getBaseCommands()`
    `Socket` | `getSocket()`
    `protected void` | `initCommands(Gateway gateway, List<Class<? extends Command>> commandsClazz)` Override this method to initialize custom commands.
    `protected void` | `quietSendError(BufferedWriter writer, Throwable exception)`
    `void` | `run()`

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

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

- - ### Field Detail

    - #### baseCommands

          protected static final List<Class<? extends Command>> baseCommands

    - #### socket

          protected final Socket socket

    - #### writer

          protected final BufferedWriter writer

    - #### reader

          protected final BufferedReader reader

    - #### commands

          protected final Map<String,Command> commands

    - #### logger

          protected final Logger logger

    - #### listeners

          protected final List<GatewayServerListener> listeners

  - ### Constructor Detail

    - #### GatewayConnection

          public GatewayConnection(Gateway gateway,
                                   Socket socket)
                            throws IOException

      Throws:
        `IOException`

    - #### GatewayConnection

          public GatewayConnection(Gateway gateway,
                                   Socket socket,
                                   List<Class<? extends Command>> customCommands,
                                   List<GatewayServerListener> listeners)
                            throws IOException

      Throws:
        `IOException`

  - ### Method Detail

    - #### getBaseCommands

          public static List<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`.

    - #### fireConnectionStopped

          protected void fireConnectionStopped()

    - #### getSocket

          public Socket getSocket()

      Returns:
        The socket used by this gateway connection.

    - #### initCommands

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

      Override this method to initialize custom commands.

      Parameters:
        `gateway` -

    - #### quietSendError

          protected void quietSendError(BufferedWriter writer,
                                        Throwable exception)

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`