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
This constructor should always be called with keyword arguments.
Sends a notification to all connected clients
clear_event
event_is_set
get_clients
Handles the given WattsonQuery and provides an optional response.
Checks whether the physical simulator handles specific SimulationControlQueries.
has_client
is_ready
Sends a notification to the clients in the recipients list.
on_client_registration
Sends a (delayed) response to a former WattsonQuery.
Method representing the thread's activity.
set_event
set_on_client_registration_callback
Start the thread's activity.
stop
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:
async_response (WattsonAsyncResponse) – The async response object to resolve.
response (WattsonResponse) – The (resolved) response object.
- 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