Skip to content

Commit

Permalink
wip kinds and topology
Browse files Browse the repository at this point in the history
  • Loading branch information
anthdm committed Dec 7, 2023
1 parent bc4a3a4 commit 0d90e94
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (c *Cluster) Start() error {
return nil
}

func (c *Cluster) RegisterKind(name string, producer actor.Producer, opts KindOpts) {
c.kinds[name] = NewKind(name, producer, opts)
}

// PID returns the reachable actor process id.
func (c *Cluster) PID() *actor.PID {
return nil
Expand Down
15 changes: 15 additions & 0 deletions cluster/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@ package cluster

import "github.com/anthdm/hollywood/actor"

type KindOpts struct {
activateOnClusterStart bool
id string
local bool
}

type Kind struct {
opts KindOpts
name string
producer actor.Producer
}

func NewKind(name string, p actor.Producer, opts KindOpts) *Kind {
return &Kind{
name: name,
opts: opts,
producer: p,
}
}
18 changes: 18 additions & 0 deletions examples/cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,26 @@ func makeCluster(addr string, id string, members ...*cluster.Member) *cluster.Cl
return c
}

type Inventory struct{}

func NewInventory() actor.Receiver {
return &Inventory{}
}

func (i *Inventory) Receive(c *actor.Context) {}

type Player struct{}

func NewPlayer() actor.Receiver {
return &Player{}
}

func (p *Player) Receive(c *actor.Context) {}

func main() {
c1 := makeCluster("localhost:3001", "A")
c1.RegisterKind("inventory", NewInventory, cluster.KindOpts{})
c1.RegisterKind("player", NewPlayer, cluster.KindOpts{})
c1.Start()
time.Sleep(time.Second)

Expand Down

0 comments on commit 0d90e94

Please sign in to comment.