Skip to content

Commit

Permalink
changed stuf up. SPICEY
Browse files Browse the repository at this point in the history
  • Loading branch information
anthdm committed Dec 8, 2023
1 parent 0d90e94 commit 8dd8906
Show file tree
Hide file tree
Showing 15 changed files with 1,156 additions and 154 deletions.
153 changes: 138 additions & 15 deletions actor/actor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions actor/actor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ message PID {
string address = 1;
string ID = 2;
}

message Ping {
PID from = 1;
}

message Pong {
PID from = 1;
}
14 changes: 9 additions & 5 deletions cluster/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ import (

type Agent struct {
members *Map[string, *Member]
cluster *Cluster
}

func NewAgent() actor.Receiver {
return &Agent{
members: NewMap[string, *Member](),
func NewAgent(c *Cluster) actor.Producer {
return func() actor.Receiver {
return &Agent{
members: NewMap[string, *Member](),
cluster: c,
}
}
}

func (a *Agent) Receive(c *actor.Context) {
switch msg := c.Message().(type) {
case actor.Started:
slog.Info("cluster agent started", "pid", c.PID())
case *MembersJoin:
case *Members:
a.handleMembersJoin(msg.Members)
}
}
Expand All @@ -33,6 +37,6 @@ func (a *Agent) handleMembersJoin(members []*Member) {
}

func (a *Agent) memberJoin(member *Member) {
slog.Info("member joined", "id", member.ID, "host", member.Host, "kinds", member.Kinds)
slog.Info("member joined", "we", a.cluster.id, "id", member.ID, "host", member.Host, "kinds", member.Kinds)
a.members.Add(member.ID, member)
}
29 changes: 18 additions & 11 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import (
"github.com/anthdm/hollywood/actor"
)

const ClusterAgentID = "agent"
const (
ClusterAgentID = "agent"
ProviderID = "provider"
)

// Producer is a function that can produce an actor.Producer.
// Pretty simple, but yet powerfull tool to construct receivers
// depending on Cluster.
type Producer func(c *Cluster) actor.Producer

type Provider interface {
Expand All @@ -14,19 +20,20 @@ type Provider interface {
}

type Config struct {
ClusterName string
ID string
Engine *actor.Engine
Provider Provider
ClusterName string
ID string
Engine *actor.Engine
ClusterProvider Producer
}

type Cluster struct {
name string
id string

provider Provider
engine *actor.Engine
agentPID *actor.PID
provider Producer
engine *actor.Engine
agentPID *actor.PID
providerPID *actor.PID

kinds map[string]*Kind
}
Expand All @@ -41,15 +48,15 @@ func New(cfg Config) (*Cluster, error) {
return &Cluster{
id: cfg.ID,
name: cfg.ClusterName,
provider: cfg.Provider,
provider: cfg.ClusterProvider,
engine: cfg.Engine,
kinds: make(map[string]*Kind),
}, nil
}

func (c *Cluster) Start() error {
c.agentPID = c.engine.Spawn(NewAgent, "cluster/"+c.id)
c.provider.Start(c)
c.agentPID = c.engine.Spawn(NewAgent(c), "cluster/"+c.id)
c.providerPID = c.engine.Spawn(c.provider(c), "cluster/"+c.id+"/provider")
return nil
}

Expand Down
Loading

0 comments on commit 8dd8906

Please sign in to comment.