コンテンツにスキップ
日本語

SingletonKey

このコンテンツはまだ日本語訳がありません。

Defined in: src/cluster/singleton/SingletonKey.ts:29

Named, type-tagged identity for a cluster singleton — the singleton counterpart to ServiceKey. Two keys are equal iff their typeName matches; the type parameter is a compile-time marker that lets start() and ref() hand back a correctly-typed ActorRef without the caller repeating the message type at every site.

The field is typeName, not id, because it is the same string that feeds singletonManagerName and the wire-visible manager path — a second name for it would be drift waiting to happen.

class JobSchedulerActor extends Actor<SchedulerCommand> {
static readonly singleton = SingletonKey.of<SchedulerCommand>('job-scheduler');
}
// Restricted to nodes carrying a role — declared once, read by every node.
class IngressActor extends Actor<IngressCommand> {
static readonly singleton = SingletonKey.of<IngressCommand>('http-ingress', 'edge');
}

The explicit type argument is load-bearing: SingletonKey.of('job-scheduler') infers SingletonKey<unknown>, which degrades every start() / ref() that uses it to ActorRef<unknown>.

TCommand = unknown

new SingletonKey<TCommand>(typeName, role?): SingletonKey<TCommand>

Defined in: src/cluster/singleton/SingletonKey.ts:33

string

string

Restrict hosting to nodes carrying this role.

It rides along on the key — like ShardKey’s extractEntityId — so the declaring class is the single source of truth, and it is NOT part of the identity: equals ignores it. A role in StartSingletonOptions wins over this one.

The key is where it has to live for a proxy to be right. Both the hosting node and a node that only calls ref() have to resolve the same host, and a ref()-only node has no options object to read it from — it has the key, and nothing else. Declared here, both sides agree by construction.

SingletonKey<TCommand>

readonly _command: TCommand

Defined in: src/cluster/singleton/SingletonKey.ts:31

Phantom field — retains TCommand so inference round-trips through the key.


readonly optional role?: string

Defined in: src/cluster/singleton/SingletonKey.ts:49

Restrict hosting to nodes carrying this role.

It rides along on the key — like ShardKey’s extractEntityId — so the declaring class is the single source of truth, and it is NOT part of the identity: equals ignores it. A role in StartSingletonOptions wins over this one.

The key is where it has to live for a proxy to be right. Both the hosting node and a node that only calls ref() have to resolve the same host, and a ref()-only node has no options object to read it from — it has the key, and nothing else. Declared here, both sides agree by construction.


readonly typeName: string

Defined in: src/cluster/singleton/SingletonKey.ts:34

equals(other): boolean

Defined in: src/cluster/singleton/SingletonKey.ts:56

SingletonKey

boolean


toString(): string

Defined in: src/cluster/singleton/SingletonKey.ts:57

string


static of<TCommand>(typeName, role?): SingletonKey<TCommand>

Defined in: src/cluster/singleton/SingletonKey.ts:52

TCommand

string

string

SingletonKey<TCommand>