py4j

## Class CallbackConnection

- java.lang.Object
- - py4j.CallbackConnection

- All Implemented Interfaces:
    Py4JClientConnection

      public class CallbackConnection
      extends java.lang.Object
      implements Py4JClientConnection

  Default implementation of the CommunicationChannel interface using TCP sockets.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_NONBLOCKING_SO_TIMEOUT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CallbackConnection(int port, java.net.InetAddress address)`
    `CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory)`
    `CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory, int readTimeout)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.lang.String` | `readBlockingResponse(java.io.BufferedReader reader)`
    `protected java.lang.String` | `readNonBlockingResponse(java.net.Socket socket, java.io.BufferedReader reader)`
    `java.lang.String` | `sendCommand(java.lang.String command)`
    `java.lang.String` | `sendCommand(java.lang.String command, boolean blocking)`
    `void` | `setUsed(boolean used)`
    `void` | `shutdown()`
    `void` | `shutdown(boolean reset)` Shuts down the connection by closing the socket, the writer, and the reader.
    `void` | `start()`
    `boolean` | `wasUsed()`

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

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

- - ### Field Detail

    - #### DEFAULT_NONBLOCKING_SO_TIMEOUT

          public static final int DEFAULT_NONBLOCKING_SO_TIMEOUT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CallbackConnection

          public CallbackConnection(int port,
                                    java.net.InetAddress address)

    - #### CallbackConnection

          public CallbackConnection(int port,
                                    java.net.InetAddress address,
                                    javax.net.SocketFactory socketFactory)

    - #### CallbackConnection

          public CallbackConnection(int port,
                                    java.net.InetAddress address,
                                    javax.net.SocketFactory socketFactory,
                                    int readTimeout)

      Parameters:
        `port` - The port used to connect to the Python side.
        `address` - The address used to connect to the Java side.
        `socketFactory` - The socket factory used to create a socket (connection) to the Python side.
        `readTimeout` - Time in milliseconds (0 = infinite). Once connected to the Python side, if the Java side does not receive a response after this time, the connection with the Python program is closed. If readTimeout = 0, a default readTimeout of 1000 is used for operations that must absolutely be non-blocking.

  - ### Method Detail

    - #### 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`

    - #### 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`

    - #### setUsed

          public void setUsed(boolean used)

      Specified by:
        `setUsed` in interface `Py4JClientConnection`

    - #### shutdown

          public void shutdown()

      Specified by:
        `shutdown` in interface `Py4JClientConnection`

    - #### shutdown

          public void shutdown(boolean reset)

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

      Internal: at this point, the connection has not been given back to the connections deque, or the deque is about to be cleared.

      Specified by:
        `shutdown` in interface `Py4JClientConnection`

    - #### start

          public void start()
                     throws java.io.IOException

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

    - #### wasUsed

          public boolean wasUsed()

      Specified by:
        `wasUsed` in interface `Py4JClientConnection`