public class GatewayConnection extends Object implements 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 String |
authToken |
protected Map<String,Command> |
commands |
protected List<GatewayServerListener> |
listeners |
protected Logger |
logger |
protected BufferedReader |
reader |
protected Socket |
socket |
protected BufferedWriter |
writer |
Constructor and Description |
---|
GatewayConnection(Gateway gateway,
Socket socket) |
GatewayConnection(Gateway gateway,
Socket socket,
List<Class<? extends Command>> customCommands,
List<GatewayServerListener> listeners) |
GatewayConnection(Gateway gateway,
Socket socket,
String authToken,
List<Class<? extends Command>> customCommands,
List<GatewayServerListener> listeners) |
Modifier and Type | Method and Description |
---|---|
protected void |
fireConnectionStopped() |
static List<Class<? extends Command>> |
getBaseCommands() |
Socket |
getSocket() |
protected void |
initCommands(Gateway gateway,
List<Class<? extends Command>> commandsClazz)
Override this method to initialize custom commands.
|
protected void |
quietSendFatalError(BufferedWriter writer,
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 Socket socket
protected final String authToken
protected final AuthCommand authCommand
protected final BufferedWriter writer
protected final BufferedReader reader
protected final Logger logger
protected final List<GatewayServerListener> listeners
public GatewayConnection(Gateway gateway, Socket socket) throws IOException
IOException
public GatewayConnection(Gateway gateway, Socket socket, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) throws IOException
IOException
public GatewayConnection(Gateway gateway, Socket socket, String authToken, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) throws IOException
IOException
public static List<Class<? extends Command>> getBaseCommands()
GatewayServer
.public void startConnection()
Wraps the GatewayConnection in a thread and start the thread.
protected void fireConnectionStopped()
public Socket getSocket()
getSocket
in interface Py4JServerConnection
protected void initCommands(Gateway gateway, List<Class<? extends Command>> commandsClazz)
Override this method to initialize custom commands.
gateway
- protected void quietSendFatalError(BufferedWriter writer, Throwable exception)
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
Copyright © 2025. All rights reserved.