Class GatewayConnection
- All Implemented Interfaces:
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.
- Author:
- Barthelemy Dagenais
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AuthCommand
protected final String
protected final List<GatewayServerListener>
protected final Logger
protected final BufferedReader
protected final Socket
protected final BufferedWriter
-
Constructor Summary
ConstructorsConstructorDescriptionGatewayConnection
(Gateway gateway, Socket socket) GatewayConnection
(Gateway gateway, Socket socket, String authToken, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) GatewayConnection
(Gateway gateway, Socket socket, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
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
Wraps the GatewayConnection in a thread and start the thread.
-
Field Details
-
socket
-
authToken
-
authCommand
-
writer
-
reader
-
commands
-
logger
-
listeners
-
-
Constructor Details
-
GatewayConnection
- Throws:
IOException
-
GatewayConnection
public GatewayConnection(Gateway gateway, Socket socket, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) throws IOException - Throws:
IOException
-
GatewayConnection
public GatewayConnection(Gateway gateway, Socket socket, String authToken, List<Class<? extends Command>> customCommands, List<GatewayServerListener> listeners) throws IOException - Throws:
IOException
-
-
Method Details
-
getBaseCommands
- Returns:
- The list of base commands that are provided by default. Can be
hidden by custom commands with the same command id by passing a
list of custom commands to the
GatewayServer
.
-
startConnection
public void startConnection()Wraps the GatewayConnection in a thread and start the thread.
-
fireConnectionStopped
protected void fireConnectionStopped() -
getSocket
- Specified by:
getSocket
in interfacePy4JServerConnection
- Returns:
- The socket used by this gateway connection.
-
initCommands
Override this method to initialize custom commands.
- Parameters:
gateway
-
-
quietSendFatalError
-
run
public void run() -
shutdown
public void shutdown()- Specified by:
shutdown
in interfacePy4JServerConnection
-
shutdown
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).
- Specified by:
shutdown
in interfacePy4JServerConnection
-