add subjects
This commit is contained in:
parent
aebc94074f
commit
72505a21c0
32
subjects/selector.go
Normal file
32
subjects/selector.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package subjects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"feudal/message"
|
||||||
|
"feudal/feudal"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Selector interface {
|
||||||
|
Select(path string)
|
||||||
|
Workers() WorkerCollection
|
||||||
|
Send(m message.Envelope)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Selection struct {
|
||||||
|
workers feudal.Subjects
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSelector() Selector {
|
||||||
|
return &Selection{ workers: New() }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Selection) Select(path string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Selection) Send(m message.Envelope) {
|
||||||
|
s.workers.Send(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Selection) Workers() WorkerCollection {
|
||||||
|
return *s.workers.(*WorkerCollection)
|
||||||
|
}
|
15
subjects/selector_test.go
Normal file
15
subjects/selector_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package subjects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupSelector() Selector {
|
||||||
|
s := NewSelector()
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSelectorPath(t *testing.T) {
|
||||||
|
s := setupSelector()
|
||||||
|
s.Select("feudal://")
|
||||||
|
}
|
41
subjects/subjects.go
Normal file
41
subjects/subjects.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package subjects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"feudal/feudal"
|
||||||
|
"feudal/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WorkerCollection map[string]feudal.WorkerRouter
|
||||||
|
|
||||||
|
func New() feudal.Subjects {
|
||||||
|
var c WorkerCollection = make(map[string]feudal.WorkerRouter)
|
||||||
|
return &c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Send(m message.Envelope) {
|
||||||
|
for _, w := range *c {
|
||||||
|
w.Send(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Add(name string, worker feudal.WorkerRouter) {
|
||||||
|
(*c)[name] = worker
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Remove(name string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Disolve() {
|
||||||
|
for _, w := range *c {
|
||||||
|
w.Stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Address() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WorkerCollection) Get(name string) feudal.WorkerRouter {
|
||||||
|
return (*c)[name]
|
||||||
|
}
|
20
subjects/subjects_test.go
Normal file
20
subjects/subjects_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package subjects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
"feudal/feudal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupSubjects() feudal.Subjects {
|
||||||
|
s := New()
|
||||||
|
if s == nil {
|
||||||
|
log.Fatal("Failed creating new Subjects")
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubjectsSend(t *testing.T) {
|
||||||
|
s := setupSubjects()
|
||||||
|
s.Send(nil)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user