CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
psyclone_client.remote_module.RemoteModule Class Reference

Public Member Functions

 __init__ (self, client, name, auth, timeout)
 attach (cls, client, name, auth=None, timeout=5.0)
 on_trigger (self, trigger, handler)
 on_any_trigger (self, handler)
 on_stop (self, handler)
 on_start (self, handler)
 on_detached (self, handler)
 on_dropped (self, handler)
 on_parameter (self, handler)
 wait_for_new_message (self, timeout)
 post (self, post, msg=None)
 post_confirmed (self, post, msg=None, timeout=None)
 retrieve (self, retrieve, max_count=0, max_age_ms=0, timeout=None)
 query (self, query, msg=None, timeout=None)
 describe (self)
 subscribe (self, *triggers)
 unsubscribe (self, *names)
 declare_post (self, name, type, to=None, ttl_ms=0, guaranteed=True)
 declare_retrieve (self, name, source, type=None, max_count=0, max_age_ms=0)
 declare_query (self, name, source)
 declare_parameter (self, name, value)
 undeclare (self, *names)
 set_parameter (self, name, value)
 retrieve_from (self, source, type=None, max_count=0, max_age_ms=0, from_=None, to=None, key=None, key_type=None, start=None, end=None, timeout=None)
 query_catalog (self, source, msg=None, timeout=None)
 ack (self)
 detach (self)
 close (self)
 __enter__ (self)
 __exit__ (self, *exc)

Public Attributes

 client = client
 name = name
 timeout = timeout
str state = DETACHED
 session = None
 posts
 triggers
 retrieves
list queries = [], {}, [], []
str contract_xml = ""
int lease_ms = 0
int last_seq = 0
bool auto_reattach = True
int attaches = 0
int resumes = 0
int dropped_reported = 0
bool dynamic = False
bool changeable = False
dict parameters = {}
 current_trigger_name = None

Protected Member Functions

 _do_attach (self, resume)
 _converge (self)
 _contract (self, r)
 _params (self, s)
 _state_changed (self, up, error)
 _reattach_later (self, why)
 _declare (self, name, entry, xml)
 _control (self, op)
 _request_op (self, post, msg, timeout=None)
 _request (self, post, msg, timeout=None)
 _receive (self, msg)

Static Protected Member Functions

 _results (op, what)

Protected Attributes

 _auth = auth
dict _desired_triggers = {}
dict _desired_decl = {}
 _dropped_h
list _param_h = [], []
dict _handlers = {}
list _any = []
 _stop
 _start
list _detached = [], [], []
 _pull = deque(maxlen=1024)
 _pull_ready = threading.Condition()
dict _pending = {}
 _lock = threading.Lock()
 _attach_lock = threading.Lock()
 _seq = itertools.count(1)
str _prefix = "m%x-" % int.from_bytes(os.urandom(6), "little")
bool _closed = False
bool _reattaching = False
 _receive

Detailed Description

One declared remote module, attached through ``client`` (one connection may carry several modules).

After a reconnect, or when the host reports that the lease ran out, the module attaches again with its
old session as ``Resume`` and ``last_seq`` as ``LastSeq`` (``auto_reattach``); the host replays what it kept.

Definition at line 181 of file remote_module.py.

Constructor & Destructor Documentation

◆ __init__()

psyclone_client.remote_module.RemoteModule.__init__ ( self,
client,
name,
auth,
timeout )

Definition at line 188 of file remote_module.py.

Member Function Documentation

◆ __enter__()

psyclone_client.remote_module.RemoteModule.__enter__ ( self)

Definition at line 547 of file remote_module.py.

◆ __exit__()

psyclone_client.remote_module.RemoteModule.__exit__ ( self,
* exc )

Definition at line 550 of file remote_module.py.

References psyclone_client.client.PsycloneClient.close(), and close().

◆ _contract()

psyclone_client.remote_module.RemoteModule._contract ( self,
r )
protected

◆ _control()

◆ _converge()

psyclone_client.remote_module.RemoteModule._converge ( self)
protected

Definition at line 269 of file remote_module.py.

References _contract(), _control(), _desired_decl, _desired_triggers, and _request().

Referenced by _do_attach().

◆ _declare()

psyclone_client.remote_module.RemoteModule._declare ( self,
name,
entry,
xml )
protected

◆ _do_attach()

psyclone_client.remote_module.RemoteModule._do_attach ( self,
resume )
protected

Definition at line 241 of file remote_module.py.

References _attach_lock, _auth, _contract(), _converge(), _params(), psyclone_client.remote_module._proof(), _request(), attaches, changeable, client, contract_xml, last_seq, lease_ms, cmlabs::Box.name, cmlabs::COMPONENTDATAHEADER.name, cmlabs::ComponentInfoStruct.name, cmlabs::ComponentMapEntry.name, cmlabs::ComponentSetup.name, cmlabs::ContextMapEntry.name, cmlabs::CrankMapEntry.name, cmlabs::CustomView.name, cmlabs::GroupMemberSpec.name, cmlabs::HTTPPostEntry.name, cmlabs::JSONMEntry.name, cmlabs::LLMConnection.name, cmlabs::LLMHeader.name, cmlabs::MessageQueueHeader.name, cmlabs::ObsEntry.name, cmlabs::ObsHeader.name, cmlabs::ParamInfo.name, cmlabs::PostSpec.name, cmlabs::ProcessInfoStruct.name, cmlabs::ProcessMapEntry.name, cmlabs::PsySpace.name, cmlabs::QuerySpec.name, cmlabs::QueueMapEntry.name, cmlabs::RequestMapEntry.name, cmlabs::RequestServerHeader.name, cmlabs::RESTHTTPCall.name, cmlabs::RESTParam.name, cmlabs::RetrieveSpec.name, cmlabs::SignalSpec.name, cmlabs::TagMapEntry.name, cmlabs::TopicMapEntry.name, cmlabs::TriggerGroupSpec.name, cmlabs::TriggerSpec.name, cmlabs::TypeMapEntry.name, cmlabs::UnitTestMetric.name, cmlabs::UnitTestRecord.name, cmlabs::utils::Event.name, cmlabs::utils::Mutex.name, cmlabs::utils::NetworkInterfaces.name, cmlabs::utils::Semaphore.name, Fixture.name, name, psyclone_client.remote_module.Trigger.name, resumes, session, cmlabs::PerchPoint.state, cmlabs::VantagePoints.state, cmsdk::HTTPChunkedDecoder.state, and state.

Referenced by _reattach_later().

◆ _params()

psyclone_client.remote_module.RemoteModule._params ( self,
s )
protected

Definition at line 296 of file remote_module.py.

References parameters.

Referenced by _do_attach(), and set_parameter().

◆ _reattach_later()

psyclone_client.remote_module.RemoteModule._reattach_later ( self,
why )
protected

◆ _receive()

psyclone_client.remote_module.RemoteModule._receive ( self,
msg )
protected
On the client's reader thread: this module's frames (replies in order; handlers via the callback).

Definition at line 584 of file remote_module.py.

References psyclone_client.client.PsycloneClient._any, _any, psyclone_client.client.PsycloneClient._closed, _closed, _detached, _dropped_h, psyclone_client.client.PsycloneClient._handlers, _handlers, psyclone_client.client.PsycloneClient._lock, _lock, _param_h, psyclone_client.client.PsycloneClient._pending, _pending, _pull, _pull_ready, _reattach_later(), _start, _stop, auto_reattach, client, dropped_reported, last_seq, cmlabs::Box.name, cmlabs::COMPONENTDATAHEADER.name, cmlabs::ComponentInfoStruct.name, cmlabs::ComponentMapEntry.name, cmlabs::ComponentSetup.name, cmlabs::ContextMapEntry.name, cmlabs::CrankMapEntry.name, cmlabs::CustomView.name, cmlabs::GroupMemberSpec.name, cmlabs::HTTPPostEntry.name, cmlabs::JSONMEntry.name, cmlabs::LLMConnection.name, cmlabs::LLMHeader.name, cmlabs::MessageQueueHeader.name, cmlabs::ObsEntry.name, cmlabs::ObsHeader.name, cmlabs::ParamInfo.name, cmlabs::PostSpec.name, cmlabs::ProcessInfoStruct.name, cmlabs::ProcessMapEntry.name, cmlabs::PsySpace.name, cmlabs::QuerySpec.name, cmlabs::QueueMapEntry.name, cmlabs::RequestMapEntry.name, cmlabs::RequestServerHeader.name, cmlabs::RESTHTTPCall.name, cmlabs::RESTParam.name, cmlabs::RetrieveSpec.name, cmlabs::SignalSpec.name, cmlabs::TagMapEntry.name, cmlabs::TopicMapEntry.name, cmlabs::TriggerGroupSpec.name, cmlabs::TriggerSpec.name, cmlabs::TypeMapEntry.name, cmlabs::UnitTestMetric.name, cmlabs::UnitTestRecord.name, cmlabs::utils::Event.name, cmlabs::utils::Mutex.name, cmlabs::utils::NetworkInterfaces.name, cmlabs::utils::Semaphore.name, Fixture.name, name, psyclone_client.remote_module.Trigger.name, parameters, session, cmlabs::PerchPoint.state, cmlabs::VantagePoints.state, cmsdk::HTTPChunkedDecoder.state, and state.

◆ _request()

psyclone_client.remote_module.RemoteModule._request ( self,
post,
msg,
timeout = None )
protected

◆ _request_op()

◆ _results()

psyclone_client.remote_module.RemoteModule._results ( op,
what )
staticprotected

Definition at line 410 of file remote_module.py.

Referenced by retrieve(), and retrieve_from().

◆ _state_changed()

psyclone_client.remote_module.RemoteModule._state_changed ( self,
up,
error )
protected

◆ ack()

psyclone_client.remote_module.RemoteModule.ack ( self)
Tell the host this process has every trigger up to last_seq (it may trim its resume buffer); optional.

Definition at line 519 of file remote_module.py.

References _control(), client, last_seq, post(), and session.

◆ attach()

psyclone_client.remote_module.RemoteModule.attach ( cls,
client,
name,
auth = None,
timeout = 5.0 )
Attach this process to the declared module ``name`` over ``client`` (waits for it to connect).
Raises RemoteModuleError when the host refuses or does not answer (an older Psyclone, or a
service without ``<modules>``).

Definition at line 225 of file remote_module.py.

◆ close()

psyclone_client.remote_module.RemoteModule.close ( self)
detach() and stop listening (the client stays open: close it separately).

Definition at line 534 of file remote_module.py.

References psyclone_client.client.PsycloneClient._closed, _closed, _receive, client, and detach().

Referenced by __exit__().

◆ declare_parameter()

psyclone_client.remote_module.RemoteModule.declare_parameter ( self,
name,
value )
Create (or set) a text parameter of the module: PsyProbe shows and edits it (on_parameter).

Definition at line 475 of file remote_module.py.

References _declare(), and psyclone_client.remote_module._xa().

◆ declare_post()

psyclone_client.remote_module.RemoteModule.declare_post ( self,
name,
type,
to = None,
ttl_ms = 0,
guaranteed = True )
Declare a post: post(name, ...) then sends messages of ``type`` (which <allow post> must cover).

Definition at line 449 of file remote_module.py.

References _declare(), and psyclone_client.remote_module._xa().

◆ declare_query()

psyclone_client.remote_module.RemoteModule.declare_query ( self,
name,
source )
Declare a named query of catalog ``source`` (in <allow query>); use it with query().

Definition at line 471 of file remote_module.py.

References _declare(), and psyclone_client.remote_module._xa().

◆ declare_retrieve()

psyclone_client.remote_module.RemoteModule.declare_retrieve ( self,
name,
source,
type = None,
max_count = 0,
max_age_ms = 0 )
Declare a named whiteboard retrieve on ``source`` (in <allow retrieve>); use it with retrieve().

Definition at line 460 of file remote_module.py.

References _declare(), and psyclone_client.remote_module._xa().

◆ describe()

psyclone_client.remote_module.RemoteModule.describe ( self)
What the host has for this module now (Posts, Triggers, PsyState, Contract; TriggerSpecs when changeable).

Definition at line 426 of file remote_module.py.

References _control(), and _request().

◆ detach()

psyclone_client.remote_module.RemoteModule.detach ( self)
Leave cleanly: the host marks the module offline (Psyclone.RemoteModule.Offline, Reason=detach).

Definition at line 524 of file remote_module.py.

References _control(), _request(), auto_reattach, session, cmlabs::PerchPoint.state, cmlabs::VantagePoints.state, cmsdk::HTTPChunkedDecoder.state, and state.

Referenced by close().

◆ on_any_trigger()

psyclone_client.remote_module.RemoteModule.on_any_trigger ( self,
handler )
Call handler(msg) for every trigger message of this module (after the named handlers).

Definition at line 335 of file remote_module.py.

References psyclone_client.client.PsycloneClient._any, and _any.

◆ on_detached()

psyclone_client.remote_module.RemoteModule.on_detached ( self,
handler )
handler(reason): the host ended the session (takeover, lease, shutdown).

Definition at line 349 of file remote_module.py.

References _detached.

◆ on_dropped()

psyclone_client.remote_module.RemoteModule.on_dropped ( self,
handler )
handler(count, from_seq, reason): the host dropped trigger messages (queue: this process read too
slowly; buffer: more was missed during an outage than the resume buffer keeps; size: too big for UDP).

Definition at line 354 of file remote_module.py.

References _dropped_h.

◆ on_parameter()

psyclone_client.remote_module.RemoteModule.on_parameter ( self,
handler )
handler(name, value): a parameter of the module was changed in PsyProbe.

Definition at line 360 of file remote_module.py.

References _param_h.

◆ on_start()

psyclone_client.remote_module.RemoteModule.on_start ( self,
handler )

Definition at line 345 of file remote_module.py.

References _start.

◆ on_stop()

psyclone_client.remote_module.RemoteModule.on_stop ( self,
handler )
handler(reason): PsyProbe stopped the module (or the node shuts down); no triggers until on_start.

Definition at line 340 of file remote_module.py.

References _stop.

◆ on_trigger()

psyclone_client.remote_module.RemoteModule.on_trigger ( self,
trigger,
handler )
Call handler(msg) for every message the module's trigger ``trigger`` delivers.

Definition at line 330 of file remote_module.py.

References psyclone_client.client.PsycloneClient._handlers, and _handlers.

◆ post()

psyclone_client.remote_module.RemoteModule.post ( self,
post,
msg = None )

◆ post_confirmed()

◆ query()

psyclone_client.remote_module.RemoteModule.query ( self,
query,
msg = None,
timeout = None )

◆ query_catalog()

◆ retrieve()

psyclone_client.remote_module.RemoteModule.retrieve ( self,
retrieve,
max_count = 0,
max_age_ms = 0,
timeout = None )
The module's named whiteboard retrieve (its ``<retrieve name=...>``), optionally with a smaller
``max_count`` or ``max_age_ms``; the host caps a remote retrieve (``<modules maxretrieve>``, 100).

Definition at line 399 of file remote_module.py.

References _control(), _request_op(), and _results().

◆ retrieve_from()

psyclone_client.remote_module.RemoteModule.retrieve_from ( self,
source,
type = None,
max_count = 0,
max_age_ms = 0,
from_ = None,
to = None,
key = None,
key_type = None,
start = None,
end = None,
timeout = None )
An ad-hoc whiteboard retrieve (dynamic modules, or a host with <modules adhoc="yes">): ``source`` must be
in <allow retrieve>; ``key``/``key_type`` (time, string, integer, float) with ``start``/``end`` select a range.

Definition at line 497 of file remote_module.py.

References _control(), _request_op(), and _results().

◆ set_parameter()

psyclone_client.remote_module.RemoteModule.set_parameter ( self,
name,
value )
Set one of the module's parameters (declared in the spec or with declare_parameter).

Definition at line 492 of file remote_module.py.

References _control(), _params(), and _request().

◆ subscribe()

psyclone_client.remote_module.RemoteModule.subscribe ( self,
* triggers )
Add or replace (by name) these Trigger()s; re-sending the same trigger changes nothing.

Definition at line 431 of file remote_module.py.

References _contract(), _control(), _desired_triggers, and _request().

◆ undeclare()

psyclone_client.remote_module.RemoteModule.undeclare ( self,
* names )
Remove declared posts, retrieves or queries by name.

Definition at line 479 of file remote_module.py.

References _contract(), _control(), _desired_decl, and _request().

◆ unsubscribe()

psyclone_client.remote_module.RemoteModule.unsubscribe ( self,
* names )
Remove triggers by name (no names: all of them).

Definition at line 439 of file remote_module.py.

References _contract(), _control(), _desired_triggers, and _request().

◆ wait_for_new_message()

psyclone_client.remote_module.RemoteModule.wait_for_new_message ( self,
timeout )
Crank-style pull: the next trigger message no handler took, or None after ``timeout`` seconds;
``current_trigger_name`` names its trigger.

Definition at line 365 of file remote_module.py.

References _pull, _pull_ready, and current_trigger_name.

Member Data Documentation

◆ _any

list psyclone_client.remote_module.RemoteModule._any = []
protected

Definition at line 211 of file remote_module.py.

Referenced by _receive(), and on_any_trigger().

◆ _attach_lock

psyclone_client.remote_module.RemoteModule._attach_lock = threading.Lock()
protected

Definition at line 217 of file remote_module.py.

Referenced by _do_attach().

◆ _auth

psyclone_client.remote_module.RemoteModule._auth = auth
protected

Definition at line 191 of file remote_module.py.

Referenced by _do_attach().

◆ _closed

bool psyclone_client.remote_module.RemoteModule._closed = False
protected

Definition at line 220 of file remote_module.py.

Referenced by _reattach_later(), _receive(), _state_changed(), and close().

◆ _desired_decl

dict psyclone_client.remote_module.RemoteModule._desired_decl = {}
protected

Definition at line 207 of file remote_module.py.

Referenced by _converge(), _declare(), and undeclare().

◆ _desired_triggers

dict psyclone_client.remote_module.RemoteModule._desired_triggers = {}
protected

Definition at line 206 of file remote_module.py.

Referenced by _converge(), subscribe(), and unsubscribe().

◆ _detached

list psyclone_client.remote_module.RemoteModule._detached = [], [], []
protected

Definition at line 212 of file remote_module.py.

Referenced by _receive(), and on_detached().

◆ _dropped_h

psyclone_client.remote_module.RemoteModule._dropped_h
protected

Definition at line 208 of file remote_module.py.

Referenced by _receive(), and on_dropped().

◆ _handlers

dict psyclone_client.remote_module.RemoteModule._handlers = {}
protected

Definition at line 210 of file remote_module.py.

Referenced by _receive(), and on_trigger().

◆ _lock

psyclone_client.remote_module.RemoteModule._lock = threading.Lock()
protected

Definition at line 216 of file remote_module.py.

Referenced by _receive(), and _request_op().

◆ _param_h

list psyclone_client.remote_module.RemoteModule._param_h = [], []
protected

Definition at line 208 of file remote_module.py.

Referenced by _receive(), and on_parameter().

◆ _pending

dict psyclone_client.remote_module.RemoteModule._pending = {}
protected

Definition at line 215 of file remote_module.py.

Referenced by _receive(), and _request_op().

◆ _prefix

str psyclone_client.remote_module.RemoteModule._prefix = "m%x-" % int.from_bytes(os.urandom(6), "little")
protected

Definition at line 219 of file remote_module.py.

Referenced by _request_op().

◆ _pull

psyclone_client.remote_module.RemoteModule._pull = deque(maxlen=1024)
protected

Definition at line 213 of file remote_module.py.

Referenced by _receive(), and wait_for_new_message().

◆ _pull_ready

psyclone_client.remote_module.RemoteModule._pull_ready = threading.Condition()
protected

Definition at line 214 of file remote_module.py.

Referenced by _receive(), and wait_for_new_message().

◆ _reattaching

bool psyclone_client.remote_module.RemoteModule._reattaching = False
protected

Definition at line 221 of file remote_module.py.

Referenced by _reattach_later().

◆ _receive

psyclone_client.remote_module.RemoteModule._receive
protected

◆ _seq

psyclone_client.remote_module.RemoteModule._seq = itertools.count(1)
protected

Definition at line 218 of file remote_module.py.

Referenced by _request_op().

◆ _start

psyclone_client.remote_module.RemoteModule._start
protected

Definition at line 212 of file remote_module.py.

Referenced by _receive(), and on_start().

◆ _stop

psyclone_client.remote_module.RemoteModule._stop
protected

Definition at line 212 of file remote_module.py.

Referenced by _receive(), and on_stop().

◆ attaches

int psyclone_client.remote_module.RemoteModule.attaches = 0

Definition at line 200 of file remote_module.py.

Referenced by _do_attach().

◆ auto_reattach

bool psyclone_client.remote_module.RemoteModule.auto_reattach = True

Definition at line 199 of file remote_module.py.

Referenced by _reattach_later(), _receive(), _state_changed(), and detach().

◆ changeable

bool psyclone_client.remote_module.RemoteModule.changeable = False

Definition at line 204 of file remote_module.py.

Referenced by _contract(), and _do_attach().

◆ client

psyclone_client.remote_module.RemoteModule.client = client

Definition at line 189 of file remote_module.py.

Referenced by _do_attach(), _receive(), _request_op(), ack(), close(), and post().

◆ contract_xml

str psyclone_client.remote_module.RemoteModule.contract_xml = ""

Definition at line 196 of file remote_module.py.

Referenced by _do_attach().

◆ current_trigger_name

psyclone_client.remote_module.RemoteModule.current_trigger_name = None

Definition at line 209 of file remote_module.py.

Referenced by wait_for_new_message().

◆ dropped_reported

int psyclone_client.remote_module.RemoteModule.dropped_reported = 0

Definition at line 202 of file remote_module.py.

Referenced by _receive().

◆ dynamic

bool psyclone_client.remote_module.RemoteModule.dynamic = False

Definition at line 203 of file remote_module.py.

Referenced by _contract().

◆ last_seq

psyclone_client.remote_module.RemoteModule.last_seq = 0

Definition at line 198 of file remote_module.py.

Referenced by _do_attach(), _receive(), and ack().

◆ lease_ms

int psyclone_client.remote_module.RemoteModule.lease_ms = 0

Definition at line 197 of file remote_module.py.

Referenced by _do_attach().

◆ name

psyclone_client.remote_module.RemoteModule.name = name

◆ parameters

dict psyclone_client.remote_module.RemoteModule.parameters = {}

Definition at line 205 of file remote_module.py.

Referenced by _params(), and _receive().

◆ posts

psyclone_client.remote_module.RemoteModule.posts

Definition at line 195 of file remote_module.py.

Referenced by _contract().

◆ queries

list psyclone_client.remote_module.RemoteModule.queries = [], {}, [], []

Definition at line 195 of file remote_module.py.

Referenced by _contract().

◆ resumes

int psyclone_client.remote_module.RemoteModule.resumes = 0

Definition at line 201 of file remote_module.py.

Referenced by _do_attach().

◆ retrieves

psyclone_client.remote_module.RemoteModule.retrieves

Definition at line 195 of file remote_module.py.

Referenced by _contract().

◆ session

psyclone_client.remote_module.RemoteModule.session = None

◆ state

psyclone_client.remote_module.RemoteModule.state = DETACHED

Definition at line 193 of file remote_module.py.

Referenced by _do_attach(), _reattach_later(), _receive(), and detach().

◆ timeout

psyclone_client.remote_module.RemoteModule.timeout = timeout

Definition at line 192 of file remote_module.py.

Referenced by _request_op().

◆ triggers

psyclone_client.remote_module.RemoteModule.triggers

Definition at line 195 of file remote_module.py.

Referenced by _contract().


The documentation for this class was generated from the following file: