org.apache.sling.discovery.impl.cluster.voting
Class VotingView

java.lang.Object
  extended by org.apache.sling.discovery.impl.common.View
      extended by org.apache.sling.discovery.impl.cluster.voting.VotingView

public class VotingView
extends View

DAO for an ongoing voting, providing a few helper methods


Field Summary
 
Fields inherited from class org.apache.sling.discovery.impl.common.View
VIEW_PROPERTY_CLUSTER_ID, VIEW_PROPERTY_CLUSTER_ID_DEFINED_AT, VIEW_PROPERTY_CLUSTER_ID_DEFINED_BY
 
Constructor Summary
VotingView(org.apache.sling.api.resource.Resource viewResource)
          Construct a voting view based on the given resource
 
Method Summary
 boolean hasNoVotes()
          Checks whether there are any no votes on this voting
 boolean hasVotedOrIsInitiator(String slingId)
          Checks whether the given slingId has voted yes or is the initiator of this voting
 boolean isInitiatedBy(String slingId)
          Checks whether this voting was initiated by the given slingId
 boolean isOngoingVoting(Config config)
          Checks whether this voting is still ongoing - that is, whether a valid votingStart is set and whether that's within the heartbeat timeout configured
 boolean isTimedoutVoting(Config config)
          Checks whether this voting has timed out - that is, whether there is a valid votingStart set and whether that has timed out
 boolean isWinning()
          Checks whether this voting is winning - winning is when it has votes from each of the members and all are yes votes
 boolean matchesLiveView(Config config)
          Checks if this voting matches the current live view
static VotingView newVoting(org.apache.sling.api.resource.ResourceResolver resourceResolver, Config config, String newViewId, String initiatorId, Set<String> liveInstances)
          Create a new voting with the given list of instances, the given voting/view id and the given slingid of the initiator.
 String toString()
           
 void vote(String slingId, Boolean vote)
          add a vote from the given slingId to this voting
 
Methods inherited from class org.apache.sling.discovery.impl.common.View
equals, getResource, getViewId, hashCode, matches, matchesLiveView, remove
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VotingView

public VotingView(org.apache.sling.api.resource.Resource viewResource)
Construct a voting view based on the given resource

Parameters:
viewResource - the resource which is the place the voting is kept
Method Detail

newVoting

public static VotingView newVoting(org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                   Config config,
                                   String newViewId,
                                   String initiatorId,
                                   Set<String> liveInstances)
                            throws org.apache.sling.api.resource.PersistenceException
Create a new voting with the given list of instances, the given voting/view id and the given slingid of the initiator.

Parameters:
newViewId - the new voting/view id
initiatorId - the slingid of the initiator
liveInstances - the list of live instances to add to the voting
Returns:
a DAO object representing the voting
Throws:
org.apache.sling.api.resource.PersistenceException

toString

public String toString()
Overrides:
toString in class Object

isOngoingVoting

public boolean isOngoingVoting(Config config)
Checks whether this voting is still ongoing - that is, whether a valid votingStart is set and whether that's within the heartbeat timeout configured

Parameters:
config -
Returns:

isTimedoutVoting

public boolean isTimedoutVoting(Config config)
Checks whether this voting has timed out - that is, whether there is a valid votingStart set and whether that has timed out


hasNoVotes

public boolean hasNoVotes()
Checks whether there are any no votes on this voting

Returns:
true if there are any no votes on this voting

hasVotedOrIsInitiator

public boolean hasVotedOrIsInitiator(String slingId)
Checks whether the given slingId has voted yes or is the initiator of this voting

Parameters:
slingId - the sling id to check for
Returns:
true if the given slingId has voted yes or is the initiator of this voting

isInitiatedBy

public boolean isInitiatedBy(String slingId)
Checks whether this voting was initiated by the given slingId

Returns:
whether this voting was initiated by the given slingId

vote

public void vote(String slingId,
                 Boolean vote)
add a vote from the given slingId to this voting

Parameters:
slingId - the slingId which is voting
vote - true for a yes-vote, false for a no-vote

isWinning

public boolean isWinning()
Checks whether this voting is winning - winning is when it has votes from each of the members and all are yes votes

Returns:
true if this voting is winning

matchesLiveView

public boolean matchesLiveView(Config config)
Checks if this voting matches the current live view



Copyright © 2007–2014 The Apache Software Foundation. All rights reserved.