Package 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 Description static intDEFAULT_NONBLOCKING_SO_TIMEOUT
-
Constructor Summary
Constructors Constructor 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringreadBlockingResponse(java.io.BufferedReader reader)protected java.lang.StringreadNonBlockingResponse(java.net.Socket socket, java.io.BufferedReader reader)java.lang.StringsendCommand(java.lang.String command)java.lang.StringsendCommand(java.lang.String command, boolean blocking)voidsetUsed(boolean used)voidshutdown()voidshutdown(boolean reset)Shuts down the connection by closing the socket, the writer, and the reader.voidstart()booleanwasUsed()
-
-
-
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.
-
CallbackConnection
public CallbackConnection(int port, java.net.InetAddress address, javax.net.SocketFactory socketFactory, int readTimeout, java.lang.String authToken)- 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.authToken- Token for authenticating with the callback server.
-
-
Method Detail
-
sendCommand
public java.lang.String sendCommand(java.lang.String command)
- Specified by:
sendCommandin interfacePy4JClientConnection
-
sendCommand
public java.lang.String sendCommand(java.lang.String command, boolean blocking)- Specified by:
sendCommandin interfacePy4JClientConnection
-
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:
setUsedin interfacePy4JClientConnection
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfacePy4JClientConnection
-
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:
shutdownin interfacePy4JClientConnection
-
start
public void start() throws java.io.IOException- Specified by:
startin interfacePy4JClientConnection- Throws:
java.io.IOException
-
wasUsed
public boolean wasUsed()
- Specified by:
wasUsedin interfacePy4JClientConnection
-
-