Documentation ¶
Index ¶
- type ChannelMessenger
- type Client
- func (c *Client) Barrier()
- func (c *Client) Broadcast(stringData []string, floatData []float64)
- func (c *Client) Close()
- func (c *Client) GetAddrId(addr string) (int, error)
- func (c *Client) GetId() int
- func (c *Client) GetNumPendingMembers() int
- func (c *Client) HandleMessage(msg Message)
- func (c *Client) IsActive() bool
- func (c *Client) Join(address string) error
- func (c *Client) JoinAddr() string
- func (c *Client) NotifyJoin(n *memberlist.Node)
- func (c *Client) NotifyLeave(n *memberlist.Node)
- func (c *Client) NotifyUpdate(n *memberlist.Node)
- func (c *Client) NumActiveMembers() int
- func (c *Client) NumMembers() int
- func (c *Client) ResolveId(id int) (string, error)
- func (c *Client) Start() error
- func (c *Client) UpdateActiveMembers() int
- func (c *Client) WaitActive()
- type ClientFactory
- type Listener
- type Message
- type MessageHandler
- type Messenger
- type Node
- type TCPMessenger
- func (messenger *TCPMessenger) Close() error
- func (messenger *TCPMessenger) Decode(b []byte) (Message, error)
- func (messenger *TCPMessenger) Encode(msg Message) (outputMsg string, err error)
- func (messenger *TCPMessenger) Recv(channel chan Message) error
- func (messenger *TCPMessenger) Send(msg Message) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelMessenger ¶
type ChannelMessenger struct { ResolverMap map[string]chan Message // Used by the resolver function to send messages Incoming chan Message }
Implements the messenger interface over channels. Useful for local testing and debugging.
func GetChannelMessenger ¶
func GetChannelMessenger(name string, resolverMap map[string]chan Message) ChannelMessenger
func GetChannelMessengers ¶
func GetChannelMessengers(names []string, resolverMap map[string]chan Message) []ChannelMessenger
Returns the ChannelMessengers and adds them all to the supplied resolver map.
func (ChannelMessenger) Recv ¶
func (messenger ChannelMessenger) Recv(channel chan Message) error
func (ChannelMessenger) Send ¶
func (messenger ChannelMessenger) Send(msg Message) error
type Client ¶
type Client struct { ActiveMembersLock sync.Mutex ActiveMembers map[string]Node // Members that are online and active, mapped by the memberlist.Node.Name Name string // Unique name of the Client // Channel for recieve broadcast messages BroadcastChannel chan Message // contains filtered or unexported fields }
func GetTCPClient ¶
func GetTCPClient(factory ClientFactory) (*Client, error)
func (*Client) Broadcast ¶
Send message to all nodes TODO implement a tree rather than naive send to all
func (*Client) GetNumPendingMembers ¶
func (*Client) HandleMessage ¶
func (*Client) Join ¶
Cause a node to join another memberlist group. This function removes this node from the active list. Further more, this should only be called when a node is alone in it's undelying memberlist. Therefore, a group of nodes cannot merge with another group, but the sub group must all join individually. Should this be blocking until the node is made active?
func (*Client) NotifyJoin ¶
func (c *Client) NotifyJoin(n *memberlist.Node)
func (*Client) NotifyLeave ¶
func (c *Client) NotifyLeave(n *memberlist.Node)
func (*Client) NotifyUpdate ¶
func (c *Client) NotifyUpdate(n *memberlist.Node)
func (*Client) NumActiveMembers ¶
func (*Client) NumMembers ¶
func (*Client) ResolveId ¶
Resolve the id to a client address. The id is currently based on the sorted string order of the nodes address.
func (*Client) UpdateActiveMembers ¶
Allows members currently waiting to become active to become active, this method blocks and requires that all current active members have also called this method.
type ClientFactory ¶
type ClientFactory struct {
// contains filtered or unexported fields
}
func (*ClientFactory) NewClient ¶
func (f *ClientFactory) NewClient() *Client
type Listener ¶
Listener for messengers
func NewListener ¶
func NewListener(msgHandler MessageHandler) *Listener
type Message ¶
type Message struct { Type messageType Target string Origin int // Origin of the message StringData []string FloatData []float64 }
Messages that can be sent by messengers
func CreateBroadcastMsg ¶
type MessageHandler ¶
type MessageHandler interface {
HandleMessage(msg Message)
}
type Messenger ¶
type Messenger interface { // Blocking call to send a message Send(msg Message) error // Blocking call to receive a message Recv(channel chan Message) error // contains filtered or unexported methods }
Interface for sending peer to peer messages
type Node ¶
type Node struct { Name string Addr net.IP // The address this node can be access at Port int // The port this node listens for connections on MemberlistPort int }
func (Node) GetMemberlistStringAddr ¶
func (Node) GetStringAddr ¶
func (Node) GetTCPAddr ¶
Retruns the connection address for this node
type TCPMessenger ¶
type TCPMessenger struct { Name string // contains filtered or unexported fields }
Messenger over TCP http://stackoverflow.com/questions/19167970/mock-functions-in-golang Good thoughts on how to mock out the messageing https://eclipse.org/paho/clients/golang/ http://golang.org/pkg/net/textproto/ Good messaging library
func GetTCPMessenger ¶
func GetTCPMessenger(name string, localAddr string) (*TCPMessenger, error)
func (*TCPMessenger) Close ¶
func (messenger *TCPMessenger) Close() error
func (*TCPMessenger) Encode ¶
func (messenger *TCPMessenger) Encode(msg Message) (outputMsg string, err error)
Encodes a messafe for sending over a tcp connection. Format is: {len in}\n{msgbody}
func (*TCPMessenger) Recv ¶
func (messenger *TCPMessenger) Recv(channel chan Message) error
func (*TCPMessenger) Send ¶
func (messenger *TCPMessenger) Send(msg Message) error