콘텐츠로 이동
한국어

ClusterSingleton

이 콘텐츠는 아직 번역되지 않았습니다.

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

Extension that manages every cluster singleton declared in this process.

Reach it through Cluster.singleton; start hands back the location-transparent ActorRef directly, so a singleton is addressed exactly like any other actor:

class JobSchedulerActor extends Actor<SchedulerCommand> {
static readonly singleton = SingletonKey.of<SchedulerCommand>('job-scheduler');
onReceive(command: SchedulerCommand): void { … }
}
const scheduler = cluster.singleton.start(JobSchedulerActor);
scheduler.tell({ kind: 'schedule', jobId: '42' });

start is get-or-create per typeName on this node, so calling it from several modules is safe and no getOrCreate wrapper is needed. Nodes that only need to talk to the singleton call ref instead and never host a manager.

new ClusterSingleton(system): ClusterSingleton

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

ActorSystem

ClusterSingleton

isStarted(reference): boolean

Defined in: src/cluster/singleton/ClusterSingleton.ts:178

True if this node runs a manager for reference — i.e. it can become the host.

SingletonReference

boolean


managerFor(reference): Option<ActorRef<unknown>>

Defined in: src/cluster/singleton/ClusterSingleton.ts:173

This node’s manager, if it called start. Diagnostics and tests — application code addresses the singleton through the ref, not the manager.

SingletonReference

Option<ActorRef<unknown>>


ref<TCommand>(key): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:147

A ref to the singleton without hosting it — the counterpart to ClusterSharding.startProxy.

Works on a node that never calls start: messages route to whichever node currently hosts the singleton. If that node later calls start, the same ref begins delivering through the local mailbox instead of over the wire — the manager is resolved per delivery, not captured.

TCommand

SingletonKey<TCommand> | SingletonKeyedClass<TCommand>

ActorRef<TCommand>

ref<TCommand>(typeName): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:148

A ref to the singleton without hosting it — the counterpart to ClusterSharding.startProxy.

Works on a node that never calls start: messages route to whichever node currently hosts the singleton. If that node later calls start, the same ref begins delivering through the local mailbox instead of over the wire — the manager is resolved per delivery, not captured.

TCommand

string

ActorRef<TCommand>


start<TCommand>(actorClass, options?): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:109

Start (or look up) the singleton and return the ref to address it with.

// The class declares its own key and takes no constructor arguments.
const scheduler = cluster.singleton.start(JobSchedulerActor);
// Same, but the actor needs dependencies.
const users = cluster.singleton.start(UserRepositoryActor, () => new UserRepositoryActor(shard));
// A bare key, for an actor that does not declare one.
const cron = cluster.singleton.start(SingletonKey.of<CronCommand>('cron'), CronActor);
// Full form — needed for `role` / `lease`, and combinable with the above.
const ingress = cluster.singleton.start(
StartSingletonOptions.create<IngressCommand>()
.withTypeName('http-ingress')
.withActor(() => new HttpIngressActor(port)),
);

Idempotent per typeName on this node: a repeat call returns the same ref and ignores the new options. Every node that may host the singleton has to call this — ref alone never hosts.

TCommand

SingletonActorClass<TCommand>

StartSingletonOptions<TCommand>

ActorRef<TCommand>

start<TCommand>(actorClass, factory, options?): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:113

Start (or look up) the singleton and return the ref to address it with.

// The class declares its own key and takes no constructor arguments.
const scheduler = cluster.singleton.start(JobSchedulerActor);
// Same, but the actor needs dependencies.
const users = cluster.singleton.start(UserRepositoryActor, () => new UserRepositoryActor(shard));
// A bare key, for an actor that does not declare one.
const cron = cluster.singleton.start(SingletonKey.of<CronCommand>('cron'), CronActor);
// Full form — needed for `role` / `lease`, and combinable with the above.
const ingress = cluster.singleton.start(
StartSingletonOptions.create<IngressCommand>()
.withTypeName('http-ingress')
.withActor(() => new HttpIngressActor(port)),
);

Idempotent per typeName on this node: a repeat call returns the same ref and ignores the new options. Every node that may host the singleton has to call this — ref alone never hosts.

TCommand

SingletonKeyedClass<TCommand>

() => Actor<TCommand>

StartSingletonOptions<TCommand>

ActorRef<TCommand>

start<TCommand>(key, actor, options?): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:118

Start (or look up) the singleton and return the ref to address it with.

// The class declares its own key and takes no constructor arguments.
const scheduler = cluster.singleton.start(JobSchedulerActor);
// Same, but the actor needs dependencies.
const users = cluster.singleton.start(UserRepositoryActor, () => new UserRepositoryActor(shard));
// A bare key, for an actor that does not declare one.
const cron = cluster.singleton.start(SingletonKey.of<CronCommand>('cron'), CronActor);
// Full form — needed for `role` / `lease`, and combinable with the above.
const ingress = cluster.singleton.start(
StartSingletonOptions.create<IngressCommand>()
.withTypeName('http-ingress')
.withActor(() => new HttpIngressActor(port)),
);

Idempotent per typeName on this node: a repeat call returns the same ref and ignores the new options. Every node that may host the singleton has to call this — ref alone never hosts.

TCommand

SingletonKey<TCommand>

ActorClassOrFactory<TCommand>

StartSingletonOptions<TCommand>

ActorRef<TCommand>

start<TCommand>(options): ActorRef<TCommand>

Defined in: src/cluster/singleton/ClusterSingleton.ts:123

Start (or look up) the singleton and return the ref to address it with.

// The class declares its own key and takes no constructor arguments.
const scheduler = cluster.singleton.start(JobSchedulerActor);
// Same, but the actor needs dependencies.
const users = cluster.singleton.start(UserRepositoryActor, () => new UserRepositoryActor(shard));
// A bare key, for an actor that does not declare one.
const cron = cluster.singleton.start(SingletonKey.of<CronCommand>('cron'), CronActor);
// Full form — needed for `role` / `lease`, and combinable with the above.
const ingress = cluster.singleton.start(
StartSingletonOptions.create<IngressCommand>()
.withTypeName('http-ingress')
.withActor(() => new HttpIngressActor(port)),
);

Idempotent per typeName on this node: a repeat call returns the same ref and ignores the new options. Every node that may host the singleton has to call this — ref alone never hosts.

TCommand

StartSingletonOptions<TCommand>

ActorRef<TCommand>


stop(reference): void

Defined in: src/cluster/singleton/ClusterSingleton.ts:161

Take this node out of rotation: stop the local manager (and with it the singleton, if this node was hosting) and drop the local proxy.

Stopping is asynchronous — the manager releases its lease and its envelope path in postStop. Starting the same singleton again on this node has to wait for that to settle.

SingletonReference

void


static get(system, cluster): ClusterSingleton

Defined in: src/cluster/singleton/ClusterSingleton.ts:66

Explicit counterpart to cluster.singleton, mirroring ClusterSharding.get(system, cluster) — for callers that hold the system and the cluster separately.

ActorSystem

Cluster

ClusterSingleton