cluster

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServiceIO

func NewServiceIO(addr net.Addr, seeds []net.Addr, lf event.LoggerFactory) *serviceIO

Types

type Config

type Config struct {
	// Role specifies if this node will serve the role of a seed
	// or normal node. Seed is responsible for distributing
	// the data about new nodes in the cluster.
	Role NodeRole
	// Addr specifies the interface on which the service
	// and application listeners will be ran
	Addr string
	// ServicePort defines the port on which the service protocol
	// will send and receive messages
	ServicePort string
	// ApplicationPort defines the port on which the application
	// protocol listener will be ran
	ApplicationPort string
	// SeedsAddr defines a list of seeds addresses with their
	// service ports defined. There should be two or more
	// seed nodes in the cluster.
	SeedsAddr []string
	// LoggerFactory specifies the logger factory used to
	// instantiate loggers in the node and it's internal
	// components
	LogerFactory event.LoggerFactory
}

Config is a single node configuration

type Node

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

Node represents a single node in the event system cluster

func NewNode

func NewNode(config Config, handlers *event.AppHandlers) (*Node, error)

Creates a new node A node represents a single node in the event system cluster. To launch the system you have to activate the node using the Run function.

func (*Node) Connect

func (n *Node) Connect(addr, appPort, servicePort string) error

Connects a peer to the node

func (*Node) Handle

func (n *Node) Handle(e event.Event)

Handle puts the event into the AppHandlers event source. This method blocks the execution but only until there is space in the event buffer. It does not block until the handler is executed.

func (*Node) RegisterSub

func (n *Node) RegisterSub(e event.EventType, from string) error

func (*Node) Run

func (n *Node) Run()

Activates the node and runs the algorithm provided in event handlers It launches goroutines to handle incomming connections and save them in the node data structures After initializing all the necessary components the node starts to connect with the peers.

func (*Node) Stop

func (n *Node) Stop()

type NodeRole

type NodeRole = int

Cluster consists of two types of nodes. SeedNodes listen to connections and spread the information about all cluster nodes' network addresses

const (
	SeedNode NodeRole = iota
	NormalNode
)

Jump to

Keyboard shortcuts

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