cluster

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cluster defines and implements types related to service discovery clustering.

Index

Constants

View Source
const (
	DefaultBackendType   = FilesystemBackend
	DefaultDirectory     = "/tmp/sd-cluster"
	DefaultTTL           = time.Duration(30) * time.Second
	DefaultRenewInterval = time.Duration(7) * time.Second
	DefaultScanInterval  = time.Duration(5) * time.Second
	DefaultSize          = 0
)

Default values

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendType

type BackendType int

BackendType defines the type of backend used for the cluster

const (
	UnspecifiedBackend BackendType = iota // Zero-value
	FilesystemBackend
	MemoryBackend
)

Available backend types

type Cluster

type Cluster interface {
	Registrator(m Member) Registrator
	Membership() Membership
}

Cluster represents a collection of service discovery servers ("members").

func New

func New(conf *Config) (Cluster, error)

New creates and initializes a new cluster with the given configuration. Nil argument results with default values for the configuration.

type Config

type Config struct {
	BackendType   BackendType
	Directory     string
	TTL           time.Duration
	RenewInterval time.Duration
	ScanInterval  time.Duration
	Size          int
}

Config encapsulates cluster configuration parameters

type Listener

type Listener interface {

	// Invoked when a member joins a cluster.
	OnJoin(m Member)

	// Invoked when a member leaves a cluster.
	OnLeave(m Member)
}

Listener receives callbacks upon cluster membership changes.

type Member

type Member interface {

	// ID returns The ID of the member node
	ID() MemberID

	// IP returns the IP address of the member node
	IP() net.IP

	// Port returns the replication port number of the member node
	Port() uint16
}

Member represents a member node in a cluster

func NewMember

func NewMember(ip net.IP, port uint16) Member

NewMember creates a member with the specified IP and port number

type MemberID

type MemberID string

MemberID represents the ID of a member node in a cluster

type Membership

type Membership interface {

	// Returns the current set of member nodes of the cluster.
	Members() map[Member]struct{}

	// Registers a listener to receive continuous callbacks upon cluster membership changes.
	RegisterListener(l Listener)

	// Unregisters a listener from receiving further callbacks upon cluster membership changes.
	DeregisterListener(l Listener)
}

Membership provides access to the current set of members of the cluster.

type Registrator

type Registrator interface {

	// Self returns the associated member node.
	Self() Member

	// Join adds the associated member node to the cluster.
	// Returns a non-nil error if and only if the member node could not be added to the cluster.
	Join() error

	// Leave removes the associated member node from the cluster.
	// Returns a non-nil error if and only if the member node could not be removed from the cluster.
	Leave() error
}

Registrator enables a member node to join and leave the cluster

Jump to

Keyboard shortcuts

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