public class CallbackConnection extends java.lang.Object implements Py4JClientConnection
Default implementation of the CommunicationChannel interface using TCP sockets.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_NONBLOCKING_SO_TIMEOUT |
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) |
CallbackConnection(int port,
java.net.InetAddress address,
javax.net.SocketFactory socketFactory,
int readTimeout,
java.lang.String authToken) |
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() |
public static final int DEFAULT_NONBLOCKING_SO_TIMEOUT
public CallbackConnection(int port, java.net.InetAddress address)
public CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory)
public CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory, int readTimeout)
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.public CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory, int readTimeout, java.lang.String authToken)
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.authToken
- Token for authenticating with the callback server.public java.lang.String sendCommand(java.lang.String command)
sendCommand
in interface Py4JClientConnection
public java.lang.String sendCommand(java.lang.String command, boolean blocking)
sendCommand
in interface Py4JClientConnection
protected java.lang.String readBlockingResponse(java.io.BufferedReader reader) throws java.io.IOException
java.io.IOException
protected java.lang.String readNonBlockingResponse(java.net.Socket socket, java.io.BufferedReader reader) throws java.io.IOException
java.io.IOException
public void setUsed(boolean used)
setUsed
in interface Py4JClientConnection
public void shutdown()
shutdown
in interface Py4JClientConnection
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.
shutdown
in interface Py4JClientConnection
public void start() throws java.io.IOException
start
in interface Py4JClientConnection
java.io.IOException
public boolean wasUsed()
wasUsed
in interface Py4JClientConnection