-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from umitkavala/identitlookup-support
Initial port
- Loading branch information
Showing
7 changed files
with
309 additions
and
4,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package identity | ||
|
||
import ( | ||
"github.com/AsynkronIT/protoactor-go/actor" | ||
"github.com/AsynkronIT/protoactor-go/cluster" | ||
) | ||
|
||
// Lookup contains | ||
type Lookup interface { | ||
Get(clusterIdentity *cluster.ClusterIdentity) *actor.PID | ||
|
||
RemovePid(pid *actor.PID) | ||
|
||
Setup(cluster *cluster.Cluster, kinds []string, isClient bool) | ||
|
||
Shutdown() | ||
} | ||
|
||
// StorageLookup contains | ||
type StorageLookup interface { | ||
TryGetExistingActivation(clusterIdentity *cluster.ClusterIdentity) *StoredActivation | ||
|
||
TryAcquireLock(clusterIdentity *cluster.ClusterIdentity) *SpawnLock | ||
|
||
WaitForActivation(clusterIdentity *cluster.ClusterIdentity) *StoredActivation | ||
|
||
RemoveLock(spawnLock SpawnLock) | ||
|
||
StoreActivation(memberID string, spawnLock *SpawnLock, pid *actor.PID) | ||
|
||
RemoveActivation(pid *SpawnLock) | ||
|
||
RemoveMemberId(memberID string) | ||
} | ||
|
||
// SpawnLock contains | ||
type SpawnLock struct { | ||
LockID string | ||
ClusterIdentity *cluster.ClusterIdentity | ||
} | ||
|
||
func newSpawnLock(lockID string, clusterIdentity *cluster.ClusterIdentity) *SpawnLock { | ||
this := &SpawnLock{ | ||
LockID: lockID, | ||
ClusterIdentity: clusterIdentity, | ||
} | ||
|
||
return this | ||
} | ||
|
||
// StoredActivation contains | ||
type StoredActivation struct { | ||
Pid string | ||
MemberID string | ||
} | ||
|
||
func newStoredActivation(pid string, memberID string) *StoredActivation { | ||
this := &StoredActivation{ | ||
Pid: pid, | ||
MemberID: memberID, | ||
} | ||
|
||
return this | ||
} | ||
|
||
// GetPid contains | ||
type GetPid struct { | ||
ClusterIdentity *cluster.ClusterIdentity | ||
} | ||
|
||
func newGetPid(clusterIdentity *cluster.ClusterIdentity) *GetPid { | ||
this := &GetPid{ | ||
ClusterIdentity: clusterIdentity, | ||
} | ||
return this | ||
} | ||
|
||
// PidResult contains | ||
type PidResult struct { | ||
Pid *actor.PID | ||
} | ||
|
||
func newPidResult(p *actor.PID) *PidResult { | ||
this := &PidResult{ | ||
Pid: p, | ||
} | ||
return this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package identity | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/AsynkronIT/protoactor-go/actor" | ||
"github.com/AsynkronIT/protoactor-go/cluster" | ||
) | ||
|
||
const ( | ||
placementActorName = "placement-activator" | ||
pidClusterIdentityStartIndex = len(placementActorName) + 1 | ||
) | ||
|
||
// IdentityStorageLookup contains | ||
type IdentityStorageLookup struct { | ||
Storage StorageLookup | ||
cluster *cluster.Cluster | ||
isClient bool | ||
placementActor *actor.PID | ||
system *actor.ActorSystem | ||
router *actor.PID | ||
memberID string | ||
} | ||
|
||
func newIdentityStorageLookup(storage StorageLookup) *IdentityStorageLookup { | ||
this := &IdentityStorageLookup{ | ||
Storage: storage, | ||
} | ||
return this | ||
} | ||
|
||
// RemoveMember | ||
func (i *IdentityStorageLookup) RemoveMember(memberID string) { | ||
i.Storage.RemoveMemberId(memberID) | ||
} | ||
|
||
// RemotePlacementActor | ||
func RemotePlacementActor(address string) *actor.PID { | ||
return actor.NewPID(address, placementActorName) | ||
} | ||
|
||
// | ||
// Interface: Lookup | ||
// | ||
|
||
// Get | ||
func (id *IdentityStorageLookup) Get(clusterIdentity *cluster.ClusterIdentity) *actor.PID { | ||
msg := newGetPid(clusterIdentity) | ||
timeout := 5 * time.Second | ||
|
||
res, _ := id.system.Root.RequestFuture(id.router, msg, timeout).Result() | ||
response := res.(*actor.Future) | ||
|
||
return response.PID() | ||
} | ||
|
||
func (id *IdentityStorageLookup) Setup(cluster *cluster.Cluster, kinds []string, isClient bool) { | ||
id.cluster = cluster | ||
id.system = cluster.ActorSystem | ||
id.memberID = string(cluster.Id()) | ||
|
||
//workerProps := actor.PropsFromProducer(func() actor.Actor { return newIdentityStorageWorker(id) }) | ||
|
||
//routerProps := id.system.Root.(workerProps, 50); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package identity | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/AsynkronIT/protoactor-go/actor" | ||
"github.com/AsynkronIT/protoactor-go/cluster" | ||
) | ||
|
||
type IdentityStorageWorker struct { | ||
cluster *cluster.Cluster | ||
lookup *IdentityStorageLookup | ||
storage StorageLookup | ||
} | ||
|
||
func newIdentityStorageWorker(storageLookup *IdentityStorageLookup) *IdentityStorageWorker { | ||
this := &IdentityStorageWorker{ | ||
cluster: storageLookup.cluster, | ||
lookup: storageLookup, | ||
storage: storageLookup.Storage, | ||
} | ||
return this | ||
} | ||
|
||
// Receive func | ||
func (ids *IdentityStorageWorker) Receive(c actor.Context) { | ||
m := c.Message() | ||
_, ok := m.(GetPid) | ||
|
||
if !ok { | ||
return | ||
} | ||
|
||
if c.Sender() == nil { | ||
log.Println("No sender in GetPid request") | ||
return | ||
} | ||
|
||
cid := m.(GetPid).ClusterIdentity.Identity + "." + m.(GetPid).ClusterIdentity.Kind | ||
|
||
existing, _ := ids.cluster.PidCache.GetCache(cid) | ||
|
||
if existing != nil { | ||
log.Printf("Found %s in pidcache", m.(GetPid).ClusterIdentity.ToShortString()) | ||
c.Respond(newPidResult(existing)) | ||
} | ||
|
||
return | ||
// continue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.