public class ElectionService extends Object implements Observable<ElectionListener>, Stoppable, EntryListener<String,Nullable<Host>>, EligibilityListener, ClusterListener
ElectionService
is created 2. a node joins cluster 3. a node leaves
cluster 4. local node becomes eligible and there is no valid leader 5.
local node becomes ineligible and it is the leaderConstructor and Description |
---|
ElectionService(CoordinationService coordinationService,
ElectionListener electionListener,
Namespace namespace,
ElectionStrategy electionStrategy,
ElectionAuthority electionAuthority,
Serializer<Host> hostSerializer,
org.slf4j.Logger logger)
Start election service.
|
Modifier and Type | Method and Description |
---|---|
void |
added(EntryEvent<String,Nullable<Host>> entry)
Method called to notify a new entry has been added.
|
void |
dumpState(Writer writer) |
void |
eligible()
Call back to indicate if the local node is eligible for election
|
Node |
getLeader()
Returns the leaderMap if one has been elected,
null if the
cluster has no leaderMap. |
void |
notEligible()
Call back to indicate if the local node is no longer eligible for election
|
void |
onJoin(Node node)
Method to notify a node has joined the cluster.
|
void |
onLeave(Node node)
Method to notify a node has left the cluster.
|
void |
register(ElectionListener observer)
Registers an observer (listener).
|
void |
removed(EntryEvent<String,Nullable<Host>> entry)
Method called to notify an entry has been deleted.
|
void |
stop()
Stops (shutdowns) operations.
|
void |
unregister(ElectionListener observer)
Unregisters an observer (listener).
|
void |
updated(EntryEvent<String,Nullable<Host>> entry)
Method called to notify an entry has been updated.
|
public ElectionService(CoordinationService coordinationService, ElectionListener electionListener, Namespace namespace, ElectionStrategy electionStrategy, ElectionAuthority electionAuthority, Serializer<Host> hostSerializer, org.slf4j.Logger logger) throws NullPointerException, DuplicateDataException
coordinationService
- handle to coordination serviceelectionListener
- election listenernamespace
- election's namespaceelectionStrategy
- election strategyelectionAuthority
- election authorityhostSerializer
- Serializer for Host. Note: if multiple instances
of ElectionService are used then they all must use the same. If
null is used then default serializer will be used. serializer
for Host.logger
- loggerNullPointerException
- if either namespace
or
strategy
is null
DuplicateDataException
- if election is already strategy is
already registeredpublic Node getLeader()
null
if the
cluster has no leaderMap.public void register(ElectionListener observer)
Observable
register
in interface Observable<ElectionListener>
observer
- observer to registerpublic void unregister(ElectionListener observer)
Observable
unregister
in interface Observable<ElectionListener>
observer
- observer to unregisterpublic void stop()
Stoppable
public void added(EntryEvent<String,Nullable<Host>> entry)
EntryListener
added
in interface EntryListener<String,Nullable<Host>>
entry
- added entrypublic void updated(EntryEvent<String,Nullable<Host>> entry)
EntryListener
updated
in interface EntryListener<String,Nullable<Host>>
entry
- updated entrypublic void removed(EntryEvent<String,Nullable<Host>> entry)
EntryListener
removed
in interface EntryListener<String,Nullable<Host>>
entry
- deleted entrypublic void eligible()
EligibilityListener
eligible
in interface EligibilityListener
public void notEligible()
EligibilityListener
notEligible
in interface EligibilityListener
public void onJoin(Node node)
ClusterListener
onJoin
in interface ClusterListener
node
- node that just joined the clusterpublic void onLeave(Node node)
ClusterListener
onLeave
in interface ClusterListener
node
- node that just left the clusterpublic void dumpState(Writer writer)
Copyright © 2015. All Rights Reserved.