public class GatewayConnection extends java.lang.Object implements java.lang.Runnable, Py4JServerConnection
Manage the connection between a Python program and a Gateway. A GatewayConnection lives in its own thread and is created on demand (e.g., one per concurrent thread).
The request to connect to the JVM goes through the GatewayServer
first and is then passed to a GatewayConnection.
This class is not intended to be directly accessed by users.
Modifier and Type | Field and Description |
---|---|
protected AuthCommand |
authCommand |
protected java.lang.String |
authToken |
protected java.util.Map<java.lang.String,Command> |
commands |
protected java.util.List<GatewayServerListener> |
listeners |
protected java.util.logging.Logger |
logger |
protected java.io.BufferedReader |
reader |
protected java.net.Socket |
socket |
protected java.io.BufferedWriter |
writer |
Constructor and Description |
---|
GatewayConnection(Gateway gateway,
java.net.Socket socket) |
GatewayConnection(Gateway gateway,
java.net.Socket socket,
java.util.List<java.lang.Class<? extends Command>> customCommands,
java.util.List<GatewayServerListener> listeners) |
GatewayConnection(Gateway gateway,
java.net.Socket socket,
java.lang.String authToken,
java.util.List<java.lang.Class<? extends Command>> customCommands,
java.util.List<GatewayServerListener> listeners) |
Modifier and Type | Method and Description |
---|---|
protected void |
fireConnectionStopped() |
static java.util.List<java.lang.Class<? extends Command>> |
getBaseCommands() |
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.
|
protected void |
quietSendFatalError(java.io.BufferedWriter writer,
java.lang.Throwable exception) |
void |
run() |
void |
shutdown() |
void |
shutdown(boolean reset)
Shuts down the connection by closing the socket, the writer, and the reader.
|
void |
startConnection()
Wraps the GatewayConnection in a thread and start the thread.
|
protected final java.net.Socket socket
protected final java.lang.String authToken
protected final AuthCommand authCommand
protected final java.io.BufferedWriter writer
protected final java.io.BufferedReader reader
protected final java.util.Map<java.lang.String,Command> commands
protected final java.util.logging.Logger logger
protected final java.util.List<GatewayServerListener> listeners
public GatewayConnection(Gateway gateway, java.net.Socket socket) throws java.io.IOException
java.io.IOException
public GatewayConnection(Gateway gateway, java.net.Socket socket, java.util.List<java.lang.Class<? extends Command>> customCommands, java.util.List<GatewayServerListener> listeners) throws java.io.IOException
java.io.IOException
public GatewayConnection(Gateway gateway, java.net.Socket socket, java.lang.String authToken, java.util.List<java.lang.Class<? extends Command>> customCommands, java.util.List<GatewayServerListener> listeners) throws java.io.IOException
java.io.IOException
public static java.util.List<java.lang.Class<? extends Command>> getBaseCommands()
GatewayServer
.public void startConnection()
Wraps the GatewayConnection in a thread and start the thread.
protected void fireConnectionStopped()
public java.net.Socket getSocket()
getSocket
in interface Py4JServerConnection
protected void initCommands(Gateway gateway, java.util.List<java.lang.Class<? extends Command>> commandsClazz)
Override this method to initialize custom commands.
gateway
- protected void quietSendFatalError(java.io.BufferedWriter writer, java.lang.Throwable exception)
public void run()
run
in interface java.lang.Runnable
public void shutdown()
shutdown
in interface Py4JServerConnection
public void shutdown(boolean reset)
Shuts down the connection by closing the socket, the writer, and the reader.
Internal: emits a connection stopped signal so GatewayServer can remove the connection from the connections list. In rare occasions, the shutdown method may be called twice (when the server shuts down at the same time as the connection fails and shuts down).
shutdown
in interface Py4JServerConnection