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

## Class VotingView

- java.lang.Object
- - org.apache.sling.discovery.impl.common.View
  - - 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

Constructors
Constructor and Description
`VotingView(org.apache.sling.api.resource.Resource viewResource)` Construct a voting view based on the given resource

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Boolean` `getVote(String slingId)` Get the vote of the instance with the given slingId
`String` `getVotingId()`
`boolean` `hasNoVotes()` Checks whether there are any no votes on this voting
`boolean` `hasVotedYes(String slingId)` Checks whether the given slingId has voted yes for 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
`String` `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, String leaderElectionId)` 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`

#### getVotingId

    public String getVotingId()

#### 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

#### hasVotedYes

    public boolean hasVotedYes(String slingId)

Checks whether the given slingId has voted yes for this voting

Parameters:
  `slingId` - the sling id to check for
Returns:
  true if the given slingId has voted yes for this voting

#### getVote

    public Boolean getVote(String slingId)

Get the vote of the instance with the given slingId

Parameters:
  `slingId` -
Returns:
  null if that instance did not vote yet (or the structure is faulty), true if the instance voted yes, false if it voted no

#### 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,
                     String leaderElectionId)

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 String matchesLiveView(Config config)
                           throws Exception

Checks if this voting matches the current live view

Throws:
  `Exception` - when something failed during matching