Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Candidate ¶
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 ¶
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 ¶
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) IsLeader ¶
IsLeader returns true if the provided id is the leader, false otherwise. Parameters:
id - The ID of the candidate to be tested for leadership.