public class CallbackClient
extends java.lang.Object
A CallbackClient is responsible for managing communication channels: channels are created as needed (e.g., one per concurrent thread) and are closed after a certain time.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_ADDRESS |
static long |
DEFAULT_MIN_CONNECTION_TIME |
Constructor and Description |
---|
CallbackClient(int port) |
CallbackClient(int port,
java.net.InetAddress address) |
CallbackClient(int port,
java.net.InetAddress address,
long minConnectionTime,
java.util.concurrent.TimeUnit minConnectionTimeUnit) |
Modifier and Type | Method and Description |
---|---|
java.net.InetAddress |
getAddress() |
int |
getPort() |
void |
periodicCleanup()
Closes communication channels that have not been used for a time
specified at the creation of the callback client.
|
java.lang.String |
sendCommand(java.lang.String command)
Sends a command to the Python side.
|
java.lang.String |
sendCommand(java.lang.String command,
boolean blocking)
Sends a command to the Python side.
|
void |
shutdown()
Closes all active channels, stops the periodic cleanup of channels and
mark the client as shutting down.
|
public static final java.lang.String DEFAULT_ADDRESS
public static final long DEFAULT_MIN_CONNECTION_TIME
public CallbackClient(int port)
public CallbackClient(int port, java.net.InetAddress address)
public CallbackClient(int port, java.net.InetAddress address, long minConnectionTime, java.util.concurrent.TimeUnit minConnectionTimeUnit)
port
- The port used by channels to connect to the Python side.address
- The addressed used by channels to connect to the Python side..minConnectionTime
- The minimum connection time: channels are guaranteed to stay
connected for this time after sending a command.minConnectionTimeUnit
- The minimum coonnection time unit.public java.net.InetAddress getAddress()
public int getPort()
public void periodicCleanup()
Closes communication channels that have not been used for a time specified at the creation of the callback client.
Clients should not directly call this method: it is called by a periodic cleaner thread.
public java.lang.String sendCommand(java.lang.String command)
Sends a command to the Python side. This method is typically used by Python proxies to call Python methods or to request the garbage collection of a proxy.
command
- The command to send.public java.lang.String sendCommand(java.lang.String command, boolean blocking)
Sends a command to the Python side. This method is typically used by Python proxies to call Python methods or to request the garbage collection of a proxy.
command
- The command to send.blocking
- If the CallbackClient should wait for an answer (default
should be True, except for critical cases such as a
finalizer sending a command).public void shutdown()
Closes all active channels, stops the periodic cleanup of channels and mark the client as shutting down. No more commands can be sent after this method has been called, except commands that were initiated before the shutdown method was called..