public class PopularVoteFlowElection extends java.lang.Object implements FlowElection
An implementation of FlowElection
that waits until either a maximum amount of time has elapsed
or a maximum number of Data Flows have entered the running to be elected, and then elects the 'winner'
based on the number of 'votes' that a particular DataFlow has received. This implementation considers
two Flows with the same fingerprint to be the same Flow. If there is a tie in the number of votes for
a particular DataFlow, one will be chosen in a non-deterministic manner. If multiple DataFlows are
presented with the same fingerprint but different Flows (for instance, the position of a component has
changed), one of the Flows with that fingerprint will be chosen in a non-deterministic manner.
Constructor and Description |
---|
PopularVoteFlowElection(long maxWait,
java.util.concurrent.TimeUnit maxWaitPeriod,
java.lang.Integer maxNodes,
FingerprintFactory fingerprintFactory) |
Modifier and Type | Method and Description |
---|---|
DataFlow |
castVote(DataFlow candidate,
NodeIdentifier nodeId)
If the election has not yet completed, adds the given DataFlow to the list of candidates
(if it is not already in the running) and increments the number of votes for this DataFlow by 1.
|
DataFlow |
getElectedDataFlow()
Returns the DataFlow that has been elected as the "correct" version of the flow, or
null
if the election has not yet completed. |
java.lang.String |
getStatusDescription()
Returns a human-readable description of the status of the election
|
boolean |
isElectionComplete()
Checks if the election has completed or not.
|
boolean |
isVoteCounted(NodeIdentifier nodeIdentifier)
Returns
true if a vote has already been counted for the given Node Identifier, false otherwise. |
public PopularVoteFlowElection(long maxWait, java.util.concurrent.TimeUnit maxWaitPeriod, java.lang.Integer maxNodes, FingerprintFactory fingerprintFactory)
public boolean isElectionComplete()
FlowElection
isElectionComplete
in interface FlowElection
true
if the election has completed, false
otherwise.public boolean isVoteCounted(NodeIdentifier nodeIdentifier)
FlowElection
true
if a vote has already been counted for the given Node Identifier, false
otherwise.isVoteCounted
in interface FlowElection
nodeIdentifier
- the identifier of the nodetrue
if a vote has already been counted for the given Node Identifier, false
otherwise.public DataFlow castVote(DataFlow candidate, NodeIdentifier nodeId)
FlowElection
null
will be returned, signifying that no candidate has yet been chosen.castVote
in interface FlowElection
candidate
- the DataFlow to vote for and add to the pool of candidates if not already presentnodeId
- the identifier of the node casting the voteDataFlow
, or null
if no DataFlow has yet been electedpublic DataFlow getElectedDataFlow()
FlowElection
null
if the election has not yet completed.getElectedDataFlow
in interface FlowElection
null
if the election has not yet completed.public java.lang.String getStatusDescription()
FlowElection
getStatusDescription
in interface FlowElection