bus

package
v0.0.0-...-2987df4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l *logrus.Logger)

SetLogger set log output

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus provides a mechanism for the send messages to a collection of channels in unicast/broadcast way

func NewBus

func NewBus() *Bus

NewBus creates a new broadcast bus.

func (*Bus) Broadcast

func (b *Bus) Broadcast(m *Message)

Broadcast send message to all nodes attached to the bus

func (*Bus) Destroy

func (b *Bus) Destroy()

Destroy returns the number of nodes in the Broadcast Bus.

func (*Bus) Join

func (b *Bus) Join(n *Node)

Join handles the attachment to the bus

func (*Bus) Leave

func (b *Bus) Leave(leaving *Node) error

Leave removes the provided node from the bus

func (*Bus) NodeCount

func (b *Bus) NodeCount() int

NodeCount returns the number of nodes in the Broadcast Bus.

func (*Bus) Nodes

func (b *Bus) Nodes() []*Node

Nodes returns a slice of Nodes that are currently in the Bus.

func (*Bus) Send

func (b *Bus) Send(id string, m *Message)

Send send message to one receiver to the Bus

func (*Bus) Start

func (b *Bus) Start()

Start checks for some message in the broadcast queue pending to send

func (*Bus) Stop

func (b *Bus) Stop()

Stop terminates the bus process immediately.

type Message

type Message struct {
	Type string
	Data interface{}
}

Message a basic message type

type MsgCtrl

type MsgCtrl struct {
	// contains filtered or unexported fields
}

MsgCtrl is an internal structure to pack messages together with info about sender and receivers

type Node

type Node struct {
	ID string

	Read chan *Message
	// contains filtered or unexported fields
}

Node represents node of a Broadcast bus.

func NewNode

func NewNode(id string) *Node

NewNode create a newNode unattached struc

func (*Node) AttachToBus

func (n *Node) AttachToBus(b *Bus)

AttachToBus set the bus to work

func (*Node) Broadcast

func (n *Node) Broadcast(m *Message)

Broadcast a message to all other nodes of the bus.

func (*Node) Close

func (n *Node) Close()

Close removes the node it is called on from its broadcast bus.

func (*Node) RecvMsg

func (n *Node) RecvMsg() *Message

RecvMsg reads one value from the node's Read channel

func (*Node) SendMsg

func (n *Node) SendMsg(m *Message)

SendMsg a message to itself one Node to the channels of all the other nodes in its bus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL