members

package
v0.0.0-...-4aff305 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: GPL-3.0 Imports: 11 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config defines a configuration setup for creating a list to manage the members cluster

func Build

func Build(opts ...Option) (Config, error)

Build ingests configuration options to then yield a Config and return an error if it fails during setup.

type ErrorEvent

type ErrorEvent struct {
	Error error
}

ErrorEvent is an event that represents when an error comes from the cluster

func (ErrorEvent) Type

func (ErrorEvent) Type() EventType

Type returns the EventType of the Event

type Event

type Event interface {
	// Type is one of the EventType
	Type() EventType
}

Event is the member event to be acted upon

func NewErrorEvent

func NewErrorEvent(err error) Event

NewErrorEvent creates a new ErrorEvent with the correct dependencies

func NewMemberEvent

func NewMemberEvent(eventType MemberEventType, members []Member) Event

NewMemberEvent creates a new MemberEvent with the correct dependencies

func NewQueryEvent

func NewQueryEvent(name string, payload []byte, query *serf.Query) Event

NewQueryEvent creates a new QueryEvent with the correct dependencies

func NewUserEvent

func NewUserEvent(name string, payload []byte) Event

NewUserEvent creates a new UserEvent with the correct dependencies

type EventBus

type EventBus interface {

	// RegisterEventHandler attaches a event listener to all the members events
	// and broadcasts the event to the handler.
	RegisterEventHandler(EventHandler) error

	// DeregisterEventHandler removes the event listener.
	DeregisterEventHandler(EventHandler) error

	// DispatchEvent dispatches an event to all the members in the cluster.
	DispatchEvent(Event) error
}

EventBus allows the distributing and receiving of events over the cluster

type EventHandler

type EventHandler interface {
	HandleEvent(Event) error
}

EventHandler is an alias for the event dispatcher

type EventType

type EventType int

EventType is the potential event type for member event

const (
	// EventMember was received from the cluster
	EventMember EventType = iota

	// EventQuery was received from the cluster
	EventQuery

	// EventUser was received from the cluster
	EventUser

	// EventError was received from the cluster
	EventError
)

type Member

type Member interface {

	// Name returns the name of the member
	Name() string

	// Address returns the host:port of the member
	Address() string
}

Member represents a node in the cluster.

type MemberEvent

type MemberEvent struct {
	EventType MemberEventType
	Members   []Member
}

MemberEvent is an event that represents when a member has changed in the cluster

func (MemberEvent) Type

func (MemberEvent) Type() EventType

Type returns the EventType of the Event

type MemberEventType

type MemberEventType int

MemberEventType is the potential event type for member event

const (
	// EventMemberJoined notified from a cluster when a member has joined
	EventMemberJoined MemberEventType = iota

	// EventMemberLeft notified from a cluster when a member has left
	EventMemberLeft

	// EventMemberFailed notified from a cluster when a member has failed
	EventMemberFailed

	// EventMemberUpdated notified from a cluster when a member has updated
	EventMemberUpdated
)

type MemberList

type MemberList interface {

	// NumMembers returns the number of alive nodes currently known. Between
	// the time of calling this and calling Members, the number of alive nodes
	// may have changed, so this shouldn't be used to determine how many
	// members will be returned by Members.
	NumMembers() int

	// LocalNode is used to return the local Member
	LocalNode() Member

	// Members returns a point-in-time snapshot of the members of this cluster.
	Members() []Member
}

MemberList represents a way to manage members with in a cluster

type Members

type Members interface {
	EventBus

	// Join joins an existing members cluster. Returns the number of nodes
	// successfully contacted. The returned error will be non-nil only in the
	// case that no nodes could be contacted.
	Join() (int, error)

	// Leave gracefully exits the cluster. It is safe to call this multiple
	// times.
	Leave() error

	// Memberlist is used to get access to the underlying Memberlist instance
	MemberList() MemberList

	// Walk over a set of alive members
	Walk(func(PeerInfo) error) error

	// Close the current members cluster
	Close() error
}

Members represents a way of joining a members cluster

func NewNopMembers

func NewNopMembers() Members

NewNopMembers creates a new members list to join.

func NewRealMembers

func NewRealMembers(config Config, logger log.Logger) (Members, error)

NewRealMembers creates a new members list to join.

type Option

type Option func(*Config) error

Option defines a option for generating a filesystem Config

func WithAPIAddrPort

func WithAPIAddrPort(addr string, port int) Option

WithAPIAddrPort adds a APIAddr and APIPort to the configuration

func WithAdvertiseAddrPort

func WithAdvertiseAddrPort(addr string, port int) Option

WithAdvertiseAddrPort adds a AdvertiseAddr and AdvertisePort to the configuration

func WithBindAddrPort

func WithBindAddrPort(addr string, port int) Option

WithBindAddrPort adds a BindAddr and BindPort to the configuration

func WithBroadcastTimeout

func WithBroadcastTimeout(d time.Duration) Option

WithBroadcastTimeout adds a BroadcastTimeout to the configuration

func WithClientAddrPort

func WithClientAddrPort(addr string, port int) Option

WithClientAddrPort adds a ClientAddr and ClientPort to the configuration

func WithExisting

func WithExisting(existing []string) Option

WithExisting adds a Existing to the configuration

func WithLogOutput

func WithLogOutput(logOutput io.Writer) Option

WithLogOutput adds a LogOutput to the configuration

func WithNodeName

func WithNodeName(nodeName string) Option

WithNodeName adds a NodeName to the configuration

func WithPeerType

func WithPeerType(peerType PeerType) Option

WithPeerType adds a PeerType to the configuration

type PeerInfo

type PeerInfo struct {
	Name    string
	Type    PeerType
	APIAddr string
	APIPort int
}

PeerInfo describes what each peer is, along with the addr and port of each

type PeerType

type PeerType string

PeerType describes the type of peer with in the cluster.

func (PeerType) String

func (p PeerType) String() string

type QueryEvent

type QueryEvent struct {
	Name    string
	Payload []byte
	// contains filtered or unexported fields
}

QueryEvent is an event that represents when a query from the cluster that needs to be answered.

func (QueryEvent) Type

func (QueryEvent) Type() EventType

Type returns the EventType of the Event

type UserEvent

type UserEvent struct {
	Name    string
	Payload []byte
}

UserEvent is an event that represents when a user sends a message to the cluster

func (UserEvent) Type

func (UserEvent) Type() EventType

Type returns the EventType of the Event

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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