data ClusterApi
The cluster as seen from a program that did not import std.cluster (cluster.self(), cluster.leader(…) { … });
use std.cluster brings the same functions as a module.
Example:
fn main() io {
print("{cluster.nodes().len() >= 1}")
}Вывод
true
@derive(Copy)
pub(api) data ClusterApiПотокобезопасность. safe from any task; the object has no state of its own.
С версии. 1.0.0-beta
Поля
pub(api) ids: ClusterIds |
|
Методы
self | () -> NodeIdThe id of this node. |
node | (name: str) -> NodeIdThe id of the node called name; on a single node every other id is unreachable. |
selfInfo | () -> ClusterMemberThis node as the registry sees it |
nodes | () -> List<ClusterMember>All nodes the membership knows, this one included (§12.3); dead and departed ones stay listed for a while with their state. |
members | () -> List<ClusterMember>The members that are alive or merely suspected (§12.3 cluster.members()). |
leader | (name: str, body: fn() F)Registers the leader task name (§12.6) and returns at once. |
now | () -> Hlccluster.now() (§12.6, §17.3) |
observe | (h: Hlc) -> boolMerges a stamp received through application data. |
shards | () -> List<ShardInfo>The shard groups of the cluster |
lock | (key: str, ttl: Duration, wait: Duration, body: fn() -> T F) -> T | LockTimeout | NetError net, time, Fcluster.lock(key, ttl |
lockFenced | (key: str, ttl: Duration, wait: Duration, body: fn(Fence) -> T F) -> T | LockTimeout | NetError net, time, FLike lock; the body receives the fencing token of this holding |
isLeader | (name: str) -> boolWhether this node currently holds the leadership of the task name (always true outside a cluster). |
hasRole | (role: str) -> boolWhether this node has the role role (§12.6 cluster.self.hasRole; all matches every role). |
find | (name: str) -> List<ClusterMember>The live nodes that serve the service name (fully qualified pkg.Service or the type name), §12.3. |
findRole | (role: str) -> List<ClusterMember>The live nodes that have the role role. |
pick | (name: str, by: PickBy, prefer: Prefer) -> ClusterMember?One node that serves name |
on | (event: ClusterEvent, handler: fn(ClusterMember) F)Calls handler(member) when the membership changes in the way event names (polled twice a second; changes that happened before the call are not reported). |
Определено в: std/core/node.oxl:235