WattsonServer#

class wattson.cosimulation.control.interface.wattson_server.WattsonServer(co_simulation_controller: CoSimulationController, query_socket_string: str, publish_socket_string: str, namespace: Namespace | None = None, **kwargs: Any)#

Bases: Thread, WattsonQueryHandler

Handles queries issued by clients for interacting with the co-simulation.

Methods

__init__

This constructor should always be called with keyword arguments.

broadcast

Sends a notification to all connected clients

clear_event

event_is_set

get_clients

handle_simulation_control_query

Handles the given WattsonQuery and provides an optional response.

handles_simulation_query_type

Checks whether the physical simulator handles specific SimulationControlQueries.

has_client

is_ready

multicast

Sends a notification to the clients in the recipients list.

on_client_registration

resolve_async_response

Sends a (delayed) response to a former WattsonQuery.

run

Method representing the thread's activity.

set_event

set_on_client_registration_callback

start

Start the thread's activity.

stop

unicast

Sends a notification to the specified client.

wait_until_ready

Attributes

publish_socket_string

query_socket_string

wattson_time

__init__(co_simulation_controller: CoSimulationController, query_socket_string: str, publish_socket_string: str, namespace: Namespace | None = None, **kwargs: Any)#

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

broadcast(simulation_notification: WattsonNotification)#

Sends a notification to all connected clients

Parameters:

simulation_notification (WattsonNotification) – The notification to send

handle_simulation_control_query(query: WattsonQuery) WattsonResponse | None#

Handles the given WattsonQuery and provides an optional response. If the query type is not supported, this should raise an InvalidSimulationControlQueryException.

Parameters:

query (WattsonQuery) –

handles_simulation_query_type(query: WattsonQuery | Type[WattsonQuery]) bool#

Checks whether the physical simulator handles specific SimulationControlQueries.

Parameters:

query (Union[WattsonQuery, Type[WattsonQuery]]) – The query instance or class to be checked.

Returns:

Whether this simulator can handle this query type

Return type:

bool

multicast(simulation_notification: WattsonNotification, recipients: List[str])#

Sends a notification to the clients in the recipients list.

Parameters:
  • simulation_notification (WattsonNotification) – The notification to send

  • recipients (List[str]) – The list of recipient IDs to send the notification to.

resolve_async_response(async_response: WattsonAsyncResponse, response: WattsonResponse)#

Sends a (delayed) response to a former WattsonQuery.

Parameters:
run() None#

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

start() None#

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

unicast(simulation_notification: WattsonNotification, recipient: str)#

Sends a notification to the specified client.

Parameters:
  • simulation_notification (WattsonNotification) – The notification to send

  • recipient (str) – The ID of the desired recipient