move NodeSet out of cluster.go into broadcast and messenger

HTTP implementation will be split into separate package.
This commit is contained in:
Matt Jaffee 2017-04-18 09:19:34 -05:00 committed by Travis
parent 802fd32988
commit d2621709f1
3 changed files with 49 additions and 59 deletions

View file

@ -8,6 +8,32 @@ import (
"github.com/pilosa/pilosa/internal"
)
// NodeSet represents an interface for Node membership and inter-node communication.
type NodeSet interface {
// Returns a list of all Nodes in the cluster
Nodes() []*Node
// Open starts any network activity implemented by the NodeSet
Open() error
}
// StaticNodeSet represents a basic NodeSet for testing
type StaticNodeSet struct {
nodes []*Node
}
func NewStaticNodeSet() *StaticNodeSet {
return &StaticNodeSet{}
}
func (s *StaticNodeSet) Nodes() []*Node {
return s.nodes
}
func (s *StaticNodeSet) Open() error {
return nil
}
// Broadcaster is an interface for broadcasting messages.
type Broadcaster interface {
SendSync(pb proto.Message) error

View file

@ -3,8 +3,6 @@ package pilosa
import (
"encoding/binary"
"hash/fnv"
"github.com/gogo/protobuf/proto"
)
const (
@ -191,15 +189,6 @@ func (c *Cluster) PartitionNodes(partitionID int) []*Node {
return nodes
}
// NodeSet represents an interface for Node membership and inter-node communication.
type NodeSet interface {
// Returns a list of all Nodes in the cluster
Nodes() []*Node
// Open starts any network activity implemented by the NodeSet
Open() error
}
// Hasher represents an interface to hash integers into buckets.
type Hasher interface {
// Hashes the key into a number between [0,N).
@ -222,51 +211,3 @@ func (h *jmphasher) Hash(key uint64, n int) int {
}
return int(b)
}
// HTTPNodeSet represents a NodeSet that broadcasts messages over HTTP.
type HTTPNodeSet struct {
nodes []*Node
}
// NewHTTPNodeSet returns a new instance of HTTPNodeSet.
func NewHTTPNodeSet() *HTTPNodeSet {
return &HTTPNodeSet{}
}
func (h *HTTPNodeSet) Nodes() []*Node {
return h.nodes
}
func (h *HTTPNodeSet) Open() error {
return nil
}
func (h *HTTPNodeSet) Join(nodes []*Node) error {
h.nodes = nodes
return nil
}
// StaticNodeSet represents a basic NodeSet for testing
type StaticNodeSet struct {
nodes []*Node
}
func NewStaticNodeSet() *StaticNodeSet {
return &StaticNodeSet{}
}
func (s *StaticNodeSet) Nodes() []*Node {
return s.nodes
}
func (s *StaticNodeSet) Open() error {
return nil
}
func (s *StaticNodeSet) SendSync(pb proto.Message) error {
return nil
}
func (s *StaticNodeSet) SendAsync(pb proto.Message) error {
return nil
}

View file

@ -161,3 +161,26 @@ func (rec *HTTPBroadcastReceiver) ServeHTTP(w http.ResponseWriter, r *http.Reque
return
}
}
// HTTPNodeSet represents a NodeSet that broadcasts messages over HTTP.
type HTTPNodeSet struct {
nodes []*Node
}
// NewHTTPNodeSet returns a new instance of HTTPNodeSet.
func NewHTTPNodeSet() *HTTPNodeSet {
return &HTTPNodeSet{}
}
func (h *HTTPNodeSet) Nodes() []*Node {
return h.nodes
}
func (h *HTTPNodeSet) Open() error {
return nil
}
func (h *HTTPNodeSet) Join(nodes []*Node) error {
h.nodes = nodes
return nil
}