github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/cluster/identity_storage_lookup.go (about) 1 package cluster 2 3 import ( 4 "time" 5 6 "github.com/asynkron/protoactor-go/actor" 7 ) 8 9 const ( 10 placementActorName = "placement-activator" 11 pidClusterIdentityStartIndex = len(placementActorName) + 1 12 ) 13 14 // IdentityStorageLookup contains 15 type IdentityStorageLookup struct { 16 Storage StorageLookup 17 cluster *Cluster 18 isClient bool 19 placementActor *actor.PID 20 system *actor.ActorSystem 21 router *actor.PID 22 memberID string 23 } 24 25 func newIdentityStorageLookup(storage StorageLookup) *IdentityStorageLookup { 26 this := &IdentityStorageLookup{ 27 Storage: storage, 28 } 29 return this 30 } 31 32 // RemoveMember from identity storage 33 func (i *IdentityStorageLookup) RemoveMember(memberID string) { 34 i.Storage.RemoveMemberId(memberID) 35 } 36 37 // RemotePlacementActor returns the PID of the remote placement actor 38 func RemotePlacementActor(address string) *actor.PID { 39 return actor.NewPID(address, placementActorName) 40 } 41 42 // 43 // Interface: IdentityLookup 44 // 45 46 // Get returns a PID for a given ClusterIdentity 47 func (id *IdentityStorageLookup) Get(clusterIdentity *ClusterIdentity) *actor.PID { 48 msg := newGetPid(clusterIdentity) 49 timeout := 5 * time.Second 50 51 res, _ := id.system.Root.RequestFuture(id.router, msg, timeout).Result() 52 response := res.(*actor.Future) 53 54 return response.PID() 55 } 56 57 func (id *IdentityStorageLookup) Setup(cluster *Cluster, kinds []string, isClient bool) { 58 id.cluster = cluster 59 id.system = cluster.ActorSystem 60 id.memberID = cluster.ActorSystem.ID 61 62 // workerProps := actor.PropsFromProducer(func() actor.Actor { return newIdentityStorageWorker(identity) }) 63 64 // routerProps := identity.system.Root.(workerProps, 50); 65 }