class RemoteLock(RemoteUaObject[
Constructor: RemoteLock(parent, server, ua_node, max_inactive_lock_time, ...)
The remote interface for a server-side Lock.
State model
The state properties (locked, locked_since, locking_user, locking_client, locked_by_us,
remaining_lock_time_ms) are a local cache fed by an OPC UA data-change subscription. They are only
eventually consistent with the server:
- They can lag by up to one publishing interval, including right after
init_lock,break_lock,exit_lockorrenew_lockreturns. - Nodes are notified separately, so values may briefly disagree with each other.
- A notification queued before a
read_statecall can arrive after it and briefly revert a field. remaining_lock_time_msis the last reported value and is not counted down locally.
Intended use
Use the cache for displaying status and reacting to changes made by others. A successful init_lock or
break_lock means we hold the lock; there is no need to wait for locked_by_us. The server enforces
lock ownership, so a stale cache can at worst cause a rejected call, never an unauthorized one.
Use read_state when the exact state is needed. It reads all nodes in one request, returns an immutable
consistent snapshot and by default updates the cache.
Signals
locked_changed and locking_user_changed fire only when the cached value changes, from any source,
and can occasionally flicker. renew_due fires while we hold the lock and the remaining time is below
renew_threshold (a fraction of the maximum), at most every renew_retry_seconds. A spurious
renew_due is harmless.
| Method | __init__ |
Create a new instance. Must be asynchronously initialized with init() before use. |
| Async Method | break |
Take over the lock from its current holder. |
| Async Method | exit |
Release the lock. |
| Async Method | init |
Acquire the lock. |
| Method | max |
Undocumented |
| Async Method | read |
Read the current lock state from the server in a single request. |
| Async Method | renew |
Reset the lock's inactivity timer. |
| Method | renew |
Undocumented |
| Method | renew |
Undocumented |
| Async Method | ua |
Undocumented |
| Instance Variable | locked |
Callback when the locked status changed. Payload is locked status. |
| Instance Variable | locking |
Callback when a lock user changed. Payload is the new user name. |
| Instance Variable | max |
Maximum inactive lock time in ms. |
| Instance Variable | renew |
Callback when a lock renew is due. Payload contains the remaining lock time in milliseconds. |
| Property | locked |
Whether the corresponding machine/component is locked. Cached, see the class docstring. |
| Property | locked |
Whether locked and locking_user equals the server username. Derived from cached values. |
| Property | locked |
When the lock was acquired, None when unlocked. Cached, see the class docstring. |
| Property | locking |
Hostname of the locking client, empty when unlocked. Cached, see the class docstring. |
| Property | locking |
Name of the locking user, empty when unlocked. Cached, see the class docstring. |
| Property | remaining |
Remaining lock time in ms as last reported by the server, None when unlocked. |
| Property | renew |
Minimum seconds between two renew_due events while still below the threshold (> 0). |
| Property | renew |
Fraction of MaxInactiveLockTime below which a renewal is requested (0 < x < 1). |
| Property | ua |
Return all raw OPC UA nodes related to this RemoteLock. |
| Async Method | _apply |
Undocumented |
| Async Method | _browse |
Undocumented |
| Async Method | _check |
Undocumented |
| Async Method | _init |
Undocumented |
| Async Method | _ua |
Undocumented |
| Instance Variable | _last |
Undocumented |
| Instance Variable | _locked |
Undocumented |
| Instance Variable | _locked |
Undocumented |
| Instance Variable | _locking |
Undocumented |
| Instance Variable | _locking |
Undocumented |
| Instance Variable | _max |
Undocumented |
| Instance Variable | _remaining |
Undocumented |
| Instance Variable | _renew |
Undocumented |
| Instance Variable | _renew |
Undocumented |
| Instance Variable | _ua |
Undocumented |
BaseRemoteComponent, server: RemoteServer, ua_node: Node | None = None, max_inactive_lock_time: int = 60000, renew_threshold: float = 0.5, renew_retry_seconds: float = 1.0):
¶
Create a new instance. Must be asynchronously initialized with init() before use.
| Parameters | |
parent:BaseRemoteComponent | Undocumented |
server:RemoteServer | Undocumented |
uaNode | None | Undocumented |
maxint | Default MaxInactiveLockTime in milliseconds. Will be overridden if the server provides this information. |
renewfloat | Fraction of MaxInactiveLockTime below which a renewal is requested (0 < x < 1). |
renewfloat | Minimum seconds between two renew_due events while still below the
threshold (> 0). |
Take over the lock from its current holder.
On success, we hold the lock; there is no need to wait for locked_by_us. The cache is updated
by the subscription and may show the previous owner for up to one publishing interval.
| Raises | |
UaError | If the server rejects the call, e.g. the holder has higher priority or the user is not permitted to break locks. |
Release the lock.
On success, the lock is released, even if locked and locked_by_us still read True until the
subscription catches up.
| Raises | |
UaError | If the server rejects the call, e.g. we are not the locking user. |
Acquire the lock.
On success, we hold the lock; there is no need to wait for locked_by_us. The cache is updated
by the subscription and may show the old state for up to one publishing interval.
| Raises | |
UaError | If the server rejects the call, e.g. the lock is already held or the user is not permitted. |
Read the current lock state from the server in a single request.
Bypasses the cache and returns a consistent snapshot.
| Parameters | |
updatebool | Also apply the snapshot to the cache, emitting signals for changes. |
| Returns | |
RemoteLockState | Undocumented |
| Raises | |
OpenSmiRuntimeError | If a node could not be read or returned no value. |
Reset the lock's inactivity timer.
On success, we still hold the lock and the timer is reset. remaining_lock_time_ms stays low until
the next notification, so another renew_due may fire meanwhile (throttled); renewing again is harmless.
| Raises | |
UaError | If the server rejects the call, e.g. we are not the locking user. |
Maximum inactive lock time in ms.
Read once from the server during initialization (assumed constant), otherwise the default from
__init__. Raised automatically if the server reports a larger remaining time.
Callback when a lock renew is due. Payload contains the remaining lock time in milliseconds.
Whether locked and locking_user equals the server username. Derived from cached values.
Can lag behind the server, e.g. right after init_lock. Use read_state for an exact answer.
When the lock was acquired, None when unlocked. Cached, see the class docstring.
Taken from the server timestamp of the notification or read; falls back to local time if the server provides none, so treat it as approximate.
Remaining lock time in ms as last reported by the server, None when unlocked.
Cached and not counted down locally. Renewal is normally driven by renew_due, not by polling this.
bool | None = None, locked_since: datetime | None = None, locking_user: str | None = None, locking_client: str | None = None, remaining_ms: int | None = None):
¶
Undocumented