GeniusBridge
- class negmas.genius.GeniusBridge[source]
Bases:
objectAttributes 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) bool[source]
Removes all agents and runs garbage collection on the bridge
- classmethod clean_all() bool[source]
Removes all agents and runs garbage collection on all bridges.
- 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: int = 25337) JavaObject[source]
Connects to a running genius-bridge
- Parameters:
port – The port at which the bridge in listening in Java
- 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) JavaGateway | None[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.
- 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: int) bool[source]
Returns true if a geniusbridge.jar is running on the given port
- classmethod kill(port: int = 25337, wait: bool = True) bool[source]
Kills the java bridge connected to this port by asking it to exit
- classmethod kill_forced(port: int = 25337, wait: bool = True) bool[source]
Kills the java bridge connected to this port forcibly.
- Remarks:
The java bridge process must have been started by this process.
- classmethod kill_threads(port: int = 25337, wait_time: float = 0.5) bool[source]
kills all threads in the given java bridge
- classmethod restart(port: int = 25337, *args, **kwargs) bool[source]
Starts or restarts the genius bridge
- Parameters:
port – port number to use
- Returns:
True if successful
- classmethod shutdown(port: int = 25337, wait: bool = True) bool[source]
Attempts to shutdown the bridge on that port.
- Parameters:
port – The port to shutdown.
- 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: int = 25337, path: str | None = None, debug: bool = False, timeout: float = 0, force_timeout: bool = True, save_logs: bool = False, log_path: PathLike | None = None, die_on_exit: bool = False, use_shell: bool = False, verbose: bool = False, allow_agent_print: bool = False) int[source]
Initializes a genius connection
- Parameters:
port – port number to use. A value <= 0 means get any free tcp port.
path – The path to a JAR file that runs negloader
debug – If true, passes –debug to the bridge
timeout – 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 – if false, no timeout will be forced by the bridge
save_logs – If false, the brige is instructed not to save any logs
log_path – the path to store logs from the bridge. Onle effective if
save_logsIf not given, defaults to ~/negmas/geniusbridge/logs/{port}-{datetime}.txtdie_on_exit – If given, the bridge will be closed when this process is ended
use_shell – If given, the bridge will be started in a subshell.
- 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: int = 25337) bool[source]
Stops a running bridge
- Parameters:
port – port number to use
- Returns:
True if successful
- 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: int = 25337, timeout: float = 0.5) bool[source]
waits until a genius bridge is listening to the given port
- Parameters:
port – The port to test
timeout – Maximum time to wait before returning (in seconds)
- Returns:
True if the genius bridge is running any more (success).
- classmethod wait_until_not_listening(port: int = 25337, timeout: float = 0.5) bool[source]
waits until the genius bridge is not listening to the given port
- Parameters:
port – The port to test
max_sleep – Maximum time to wait before returning (in seconds)
- Returns:
True if the genius bridge is NOT running any more (success).