Skip to content

Commit

Permalink
feat: add cluster singleton (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tochemey authored Feb 21, 2025
1 parent 75891ff commit db15608
Show file tree
Hide file tree
Showing 41 changed files with 1,514 additions and 512 deletions.
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

0 comments on commit db15608

Please sign in to comment.