Package 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 Description protected AuthCommandauthCommandprotected java.lang.StringauthTokenprotected intblockingReadTimeoutprotected java.util.Map<java.lang.String,Command>commandsprotected Py4JJavaServerjavaServerprotected java.util.logging.Loggerloggerprotected intnonBlockingReadTimeoutprotected Py4JPythonClientPerThreadpythonClientprotected java.io.BufferedReaderreaderprotected java.net.Socketsocketprotected java.io.BufferedWriterwriter
-
Constructor Summary
Constructors Constructor Description ClientServerConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, Py4JJavaServer javaServer, int readTimeout)ClientServerConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, Py4JJavaServer javaServer, int readTimeout, java.lang.String authToken)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfireConnectionStopped()java.net.SocketgetSocket()protected voidinitCommands(Gateway gateway, java.util.List<java.lang.Class<? extends Command>> commandsClazz)Override this method to initialize custom commands.booleanisInitiatedFromClient()protected voidquietSendFatalError(java.io.BufferedWriter writer, java.lang.Throwable exception)protected java.lang.StringreadBlockingResponse(java.io.BufferedReader reader)protected java.lang.StringreadNonBlockingResponse(java.net.Socket socket, java.io.BufferedReader reader)voidrun()java.lang.StringsendCommand(java.lang.String command)java.lang.StringsendCommand(java.lang.String command, boolean blocking)voidsetInitiatedFromClient(boolean initiatedFromClient)voidsetUsed(boolean used)voidshutdown()voidshutdown(boolean reset)voidstart()voidstartServerConnection()voidwaitForCommands()booleanwasUsed()
-
-
-
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
-
authToken
protected final java.lang.String authToken
-
authCommand
protected final AuthCommand authCommand
-
-
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
-
ClientServerConnection
public ClientServerConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, Py4JPythonClientPerThread pythonClient, Py4JJavaServer javaServer, int readTimeout, java.lang.String authToken) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
startServerConnection
public void startServerConnection() throws java.io.IOException- Throws:
java.io.IOException
-
run
public void run()
- Specified by:
runin interfacejava.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()
-
quietSendFatalError
protected void quietSendFatalError(java.io.BufferedWriter writer, java.lang.Throwable exception)
-
getSocket
public java.net.Socket getSocket()
- Specified by:
getSocketin interfacePy4JServerConnection- Returns:
- The socket used by this gateway connection.
-
waitForCommands
public void waitForCommands()
-
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
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfacePy4JClientConnection- Specified by:
shutdownin interfacePy4JServerConnection
-
shutdown
public void shutdown(boolean reset)
- Specified by:
shutdownin interfacePy4JClientConnection- Specified by:
shutdownin interfacePy4JServerConnection
-
start
public void start() throws java.io.IOException- Specified by:
startin interfacePy4JClientConnection- Throws:
java.io.IOException
-
setUsed
public void setUsed(boolean used)
- Specified by:
setUsedin interfacePy4JClientConnection
-
wasUsed
public boolean wasUsed()
- Specified by:
wasUsedin interfacePy4JClientConnection
-
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
-
-