GeniusBridge
- class negmas.genius.GeniusBridge[source]
Bases:
object
Attributes Summary
Methods Summary
clean
([port])Removes all agents and runs garbage collection on the bridge
Removes all agents and runs garbage collection on all bridges.
close_gateway
([port])Closes the gateway.
Closes all open gateways.
connect
([port])Connects to a running genius-bridge
gateway
([port, force])Finds and returns a gateway for a genius bridge on the given port
Returns true if a geniusbridge.jar is available
is_running
(port)Returns true if a geniusbridge.jar is running on the given port
kill
([port, wait])Kills the java bridge connected to this port by asking it to exit
kill_forced
([port, wait])Kills the java bridge connected to this port forcibly.
kill_threads
([port, wait_time])kills all threads in the given java bridge
restart
([port])Starts or restarts the genius bridge
shutdown
([port, wait])Attempts to shutdown the bridge on that port.
start
([port, path, debug, timeout, ...])Initializes a genius connection
stop
([port])Stops a running bridge
wait_until_listening
([port, timeout])waits until a genius bridge is listening to the given port
wait_until_not_listening
([port, timeout])waits until the genius bridge is not listening to the given port
Attributes Documentation
Methods Documentation
- classmethod clean(port=25337)[source]
Removes all agents and runs garbage collection on the bridge
- Return type:
- classmethod clean_all()[source]
Removes all agents and runs garbage collection on all bridges.
- Return type:
- classmethod close_gateway(port=25337)[source]
Closes the gateway.
- Parameters:
port – The port the gateway is connected to. If None, DEFAULT_JAVA_PORT is used.
- classmethod connect(port=25337)[source]
Connects to a running genius-bridge
- Parameters:
port (
int
) – The port at which the bridge in listening in Java- Return type:
JavaObject
- Remarks:
The difference between this method and start() is that this one does not attempt to start a java bridge if one does not exist.
- classmethod gateway(port=25337, force=False)[source]
Finds and returns a gateway for a genius bridge on the given port
- Parameters:
port – The port used by the Jave genius bridge.
force – If true, a new gateway is created even if one exists in the list of gateways available in
GeniusBridge
.gateways.
- Return type:
JavaGateway
|None
- Returns:
The gateway if found otherwise an exception will be thrown
- Remarks:
this method does NOT start a bridge. It only connects to a running bridge.
- classmethod is_running(port)[source]
Returns true if a geniusbridge.jar is running on the given port
- Return type:
- classmethod kill(port=25337, wait=True)[source]
Kills the java bridge connected to this port by asking it to exit
- Return type:
- classmethod kill_forced(port=25337, wait=True)[source]
Kills the java bridge connected to this port forcibly.
- Return type:
- Remarks:
The java bridge process must have been started by this process.
- classmethod kill_threads(port=25337, wait_time=0.5)[source]
kills all threads in the given java bridge
- Return type:
- classmethod shutdown(port=25337, wait=True)[source]
Attempts to shutdown the bridge on that port.
- Remarks:
This is the cleanest way to close a java bridge and it simply sends a message to the bridge to shut itself down and cleanly shuts down the py4j bridge.
- classmethod start(port=25337, path=None, debug=False, timeout=0, force_timeout=True, save_logs=False, log_path=None, die_on_exit=False, use_shell=False, verbose=False, allow_agent_print=False)[source]
Initializes a genius connection
- Parameters:
port (
int
) – port number to use. A value <= 0 means get any free tcp port.path (
str
|None
) – The path to a JAR file that runs negloaderdebug (
bool
) – If true, passes –debug to the bridgetimeout (
float
) – If positive and nonzero, passes it as the global timeout for the bridge. Note that currently, the bridge supports only integer timeout values and the fraction will be truncated.force_timeout (
bool
) – if false, no timeout will be forced by the bridgesave_logs (
bool
) – If false, the brige is instructed not to save any logslog_path (
PathLike
|None
) – the path to store logs from the bridge. Onle effective ifsave_logs
If not given, defaults to ~/negmas/geniusbridge/logs/{port}-{datetime}.txtdie_on_exit (
bool
) – If given, the bridge will be closed when this process is endeduse_shell (
bool
) – If given, the bridge will be started in a subshell.
- Return type:
- Returns:
The port number used by the java process. 0 for failure
- Remarks:
if a bridge is running, it will return its port and it does not matter whether or not the bridge is started from this process or any other way.
it is recommended not to change the defaults for this function.
- classmethod stop(port=25337)[source]
Stops a running bridge
- Remarks:
You should use this method to stop bridges.
- It tries the following in order:
shutdown the java bridge by calling its shutdown() method.
killing the java bridge by calling its kill() method.
killing the java bridge forcibly by killing the process
This method always waits for a short time to allow each process to complete. If it returns True then the bridge is no longer listening on the given port.
- classmethod wait_until_listening(port=25337, timeout=0.5)[source]
waits until a genius bridge is listening to the given port