leader

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckLeaderFunc

type CheckLeaderFunc func() (bool, error)

CheckLeaderFunc is all that a special backend needs to implement. It can be used with the NewPoller function to return a polling implementation of the Detector interface. This function returns true or false for leadership when there are no errors. Returned error is reported and the status of the event will be set to `Unknown`.

func Always

func Always(leader bool) CheckLeaderFunc

Always is a trivial implementation that asserts the current instance to always be the leader (or not)

type Detector

type Detector interface {

	// Start starts leadership detection
	Start() (<-chan Leadership, error)

	// Stop stops
	Stop()
}

Detector is the interface for determining whether this instance is a leader

func NewPoller

func NewPoller(pollInterval time.Duration, f CheckLeaderFunc) Detector

NewPoller returns a detector implementation given the poll interval and function that polls

type Leadership

type Leadership struct {
	Status Status
	Error  error
}

Leadership is a struct that captures the leadership state, possibly error if exception occurs

type Status

type Status int

Status indicates leadership status

const (
	// NotLeader means the current node is not a leader
	NotLeader Status = iota

	// Leader means the current node / instance is a leader
	Leader

	// Unknown indicates some exception happened while determining leadership.  Consumer will interpret accordingly.
	Unknown
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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