leader

package
v0.0.0-...-5f24bed Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	CandidateID            string
	LeaderNotificationChnl <-chan string // TODO: DELETE
}

Candidate represents a Election client that has requested leadership. It consists of a CandidateID and a LeaderNotificationChnl. CandidateID uniquely identifies a specific client that has requested leadership for a resource. LeaderNotificationChnl is used by the library to notify a candidate that was not initially elected leader that it has assumed the leadership role for the resource.

type Election

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

Election is a structure that represents a new instance of a Election. This instance can then be used to request leadership for a specific resource.

func NewElection

func NewElection(zkConn *zk.Conn, electionNode string) (Election, error)

NewElection initializes a new instance of a Election that can later be used to request leadership for a specific resource.

It accepts:

zkConn - a connection to a running Zookeeper instance
resource - the resource for which leadership is being requested

It will return either a non-nil Election instance and a nil error, or a nil Election and a non-nil error.

func (*Election) ElectLeader

func (le *Election) ElectLeader(nomineePrefix, resource string) (bool, Candidate, chan bool)

ElectLeader will, for a given nomineePrefix and resource, make the caller a candidate for leadership and determine if the candidate becomes the leader. The parameters are:

nomineePrefix - a generic prefix (e.g., n_) for the election and a resource for which
the election is being held (e.g., president).

It returns true if leader and a string representing the full path to the candidate ID (e.g., /election/president/n_00001). The candidate ID is needed when and if a candidate wants to resign as leader.

func (*Election) ID

func (le *Election) ID() string

func (*Election) IsLeader

func (le *Election) IsLeader() bool

IsLeader returns true if the provided id is the leader, false otherwise. Parameters:

id - The ID of the candidate to be tested for leadership.

func (*Election) Resign

func (le *Election) Resign(candidate Candidate) error

candidate - The candidate who is resigning. The value for candidate is returned from ElectLeader.

func (Election) String

func (le Election) String() string

String is the Stringer implementation for this type.

Jump to

Keyboard shortcuts

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