py4j

## Class ClientServerConnection

- java.lang.Object
- - py4j.ClientServerConnection

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

      public class ClientServerConnection
      extends java.lang.Object
      implements Py4JServerConnection, Py4JClientConnection, java.lang.Runnable

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `blockingReadTimeout`
    `protected java.util.Map<java.lang.String,Command>` | `commands`
    `protected Py4JJavaServer` | `javaServer`
    `protected java.util.logging.Logger` | `logger`
    `protected int` | `nonBlockingReadTimeout`
    `protected Py4JPythonClientPerThread` | `pythonClient`
    `protected java.io.BufferedReader` | `reader`
    `protected java.net.Socket` | `socket`
    `protected java.io.BufferedWriter` | `writer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientServerConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, Py4JJavaServer javaServer, int readTimeout)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `fireConnectionStopped()`
    `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.
    `boolean` | `isInitiatedFromClient()`
    `protected void` | `quietSendError(java.io.BufferedWriter writer, java.lang.Throwable exception)`
    `protected java.lang.String` | `readBlockingResponse(java.io.BufferedReader reader)`
    `protected java.lang.String` | `readNonBlockingResponse(java.net.Socket socket, java.io.BufferedReader reader)`
    `void` | `run()`
    `java.lang.String` | `sendCommand(java.lang.String command)`
    `java.lang.String` | `sendCommand(java.lang.String command, boolean blocking)`
    `void` | `setInitiatedFromClient(boolean initiatedFromClient)`
    `void` | `setUsed(boolean used)`
    `void` | `shutdown()`
    `void` | `shutdown(boolean reset)`
    `void` | `start()`
    `void` | `startServerConnection()`
    `void` | `waitForCommands()`
    `boolean` | `wasUsed()`

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

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

- - ### Field Detail

    - #### socket

          protected java.net.Socket socket

    - #### writer

          protected java.io.BufferedWriter writer

    - #### reader

          protected java.io.BufferedReader reader

    - #### commands

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

    - #### logger

          protected final java.util.logging.Logger logger

    - #### javaServer

          protected final Py4JJavaServer javaServer

    - #### pythonClient

          protected final Py4JPythonClientPerThread pythonClient

    - #### blockingReadTimeout

          protected final int blockingReadTimeout

    - #### nonBlockingReadTimeout

          protected final int nonBlockingReadTimeout

  - ### Constructor Detail

    - #### ClientServerConnection

          public ClientServerConnection(Gateway gateway,
                                        java.net.Socket socket,
                                        java.util.List<java.lang.Class<? extends Command>> customCommands,
                                        Py4JPythonClientPerThread pythonClient,
                                        Py4JJavaServer javaServer,
                                        int readTimeout)
                                 throws java.io.IOException

      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### startServerConnection

          public void startServerConnection()

    - #### run

          public void run()

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

    - #### initCommands

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

      Override this method to initialize custom commands.

      Parameters:
        `gateway` -
        `commandsClazz` -

    - #### fireConnectionStopped

          protected void fireConnectionStopped()

    - #### quietSendError

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

    - #### getSocket

          public java.net.Socket getSocket()

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

    - #### waitForCommands

          public void waitForCommands()

    - #### sendCommand

          public java.lang.String sendCommand(java.lang.String command)

      Specified by:
        `sendCommand` in interface `Py4JClientConnection`

    - #### sendCommand

          public java.lang.String sendCommand(java.lang.String command,
                                              boolean blocking)

      Specified by:
        `sendCommand` in interface `Py4JClientConnection`

    - #### shutdown

          public void shutdown()

      Specified by:
        `shutdown` in interface `Py4JClientConnection`
      Specified by:
        `shutdown` in interface `Py4JServerConnection`

    - #### shutdown

          public void shutdown(boolean reset)

      Specified by:
        `shutdown` in interface `Py4JClientConnection`
      Specified by:
        `shutdown` in interface `Py4JServerConnection`

    - #### start

          public void start()
                     throws java.io.IOException

      Specified by:
        `start` in interface `Py4JClientConnection`
      Throws:
        `java.io.IOException`

    - #### setUsed

          public void setUsed(boolean used)

      Specified by:
        `setUsed` in interface `Py4JClientConnection`

    - #### wasUsed

          public boolean wasUsed()

      Specified by:
        `wasUsed` in interface `Py4JClientConnection`

    - #### isInitiatedFromClient

          public boolean isInitiatedFromClient()

    - #### setInitiatedFromClient

          public void setInitiatedFromClient(boolean initiatedFromClient)

    - #### readBlockingResponse

          protected java.lang.String readBlockingResponse(java.io.BufferedReader reader)
                                                   throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readNonBlockingResponse

          protected java.lang.String readNonBlockingResponse(java.net.Socket socket,
                                                             java.io.BufferedReader reader)
                                                      throws java.io.IOException

      Throws:
        `java.io.IOException`