From d2621709f13a1485c36b2edc752c244ecf9a2c09 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 18 Apr 2017 09:19:34 -0500 Subject: [PATCH] move NodeSet out of cluster.go into broadcast and messenger HTTP implementation will be split into separate package. --- broadcast.go | 26 +++++++++++++++++++++++ cluster.go | 59 ---------------------------------------------------- messenger.go | 23 ++++++++++++++++++++ 3 files changed, 49 insertions(+), 59 deletions(-) diff --git a/broadcast.go b/broadcast.go index d56576b2c..6eaf834cc 100644 --- a/broadcast.go +++ b/broadcast.go @@ -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 diff --git a/cluster.go b/cluster.go index ef67b7a4a..d8f4401e3 100644 --- a/cluster.go +++ b/cluster.go @@ -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 -} diff --git a/messenger.go b/messenger.go index 78a1d1696..37be45c0c 100644 --- a/messenger.go +++ b/messenger.go @@ -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 +}