Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cluster singleton #628

Merged
merged 24 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions actor/actor_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ import (
//
// - Address: The actor address. One can use the address with Remoting to
// interact with the actor by sending messages.
//
// - IsSingleton: The actor is a singleton
// if the actor is a singleton then the actor is created once in the cluster
type ActorRef struct {
// name defines the actor Name
name string
// kind defines the actor kind
kind string
// address defines the actor address
address *address.Address
// isSingleton defines if the actor is a singleton
isSingleton bool
}

// Name represents the actor given name
Expand All @@ -66,23 +71,31 @@ func (x ActorRef) Address() *address.Address {
return x.address
}

// IsSingleton returns true if the actor is a singleton
// otherwise it returns false when the actor is not a singleton or cluster is not enabled
func (x ActorRef) IsSingleton() bool {
return x.isSingleton
}

// Equals is a convenient method to compare two ActorRef
func (x ActorRef) Equals(actor ActorRef) bool {
return x.address.Equals(actor.address)
}

func fromActorRef(actorRef *internalpb.ActorRef) ActorRef {
return ActorRef{
name: actorRef.GetActorAddress().GetName(),
kind: actorRef.GetActorType(),
address: address.From(actorRef.GetActorAddress()),
name: actorRef.GetActorAddress().GetName(),
kind: actorRef.GetActorType(),
address: address.From(actorRef.GetActorAddress()),
isSingleton: actorRef.GetIsSingleton(),
}
}

func fromPID(pid *PID) ActorRef {
return ActorRef{
name: pid.Name(),
kind: types.TypeName(pid.Actor()),
address: pid.Address(),
name: pid.Name(),
kind: types.Name(pid.Actor()),
address: pid.Address(),
isSingleton: pid.IsSingleton(),
}
}
2 changes: 1 addition & 1 deletion actor/actor_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func TestActorRef(t *testing.T) {
}
actorRef := fromPID(pid)
require.Equal(t, "name", actorRef.Name())
require.Equal(t, types.TypeName(actor), actorRef.Kind())
require.Equal(t, types.Name(actor), actorRef.Kind())
})
}
Loading
Loading