|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.blocks.VotingAdapter
public class VotingAdapter
Voting adapter provides a voting functionality for an application. There
should be at most one VotingAdapter
listening on one Channel
instance. Each adapter can have zero or more registered VotingListener
instances that will be called during voting process.
Decree is an object that has some semantic meaning within the application.
Each voting listener receives a decree and can respond with either
true
or false. If the decree has no meaning for the voting
listener, it is required to throw VoteException
. In this case
this specific listener will be excluded from the voting on the specified
decree. After performing local voting, this voting adapter sends the request
back to the originator of the voting process. Originator receives results
from each node and decides if all voting process succeeded or not depending
on the consensus type specified during voting.
Nested Class Summary | |
---|---|
static class |
VotingAdapter.FailureVoteResult
Class that represents a result of local voting on the failed node. |
static class |
VotingAdapter.VoteResult
This class represents the result of local voting. |
Field Summary | |
---|---|
protected Log |
log
|
static int |
VOTE_ALL
This consensus type means that at least one positive vote and no negative votes are required for the voting to succeed. |
static int |
VOTE_ANY
This consensus type means that at least one positive vote is required for the voting to succeed. |
static int |
VOTE_MAJORITY
This consensus type means that number of positive votes should be greater than number of negative votes. |
Constructor Summary | |
---|---|
VotingAdapter(Channel channel)
Creates an instance of the VoteChannel that uses JGroups for communication between group members. |
|
VotingAdapter(PullPushAdapter adapter,
java.io.Serializable id)
|
Method Summary | |
---|---|
void |
addMembershipListener(MembershipListener l)
|
void |
addVoteListener(VotingListener listener)
Adds voting listener. |
void |
block()
Blocks the channel until the ViewAccepted is invoked. |
static java.lang.String |
getConsensusStr(int consensusType)
Convert consensus type into string representation. |
java.util.Collection |
getMembers()
|
byte[] |
getState()
Get the channel state. |
VotingAdapter.VoteResult |
localVote(java.lang.Object decree)
This method performs voting on the specific decree between all local voteListeners. |
boolean |
processResponses(RspList responses,
int consensusType,
java.lang.Object decree)
Processes the response list and makes a decision according to the type of the consensus for current voting. |
void |
receive(Message msg)
Receive the message. |
void |
removeMembershipListener(MembershipListener l)
|
void |
removeVoteListener(VotingListener listener)
Removes voting listener. |
void |
setState(byte[] state)
Set the channel state. |
void |
suspect(Address suspected)
Callback for notification that one node is suspected |
void |
viewAccepted(View newView)
Callback for notification about the new view of the group. |
boolean |
vote(java.lang.Object decree,
int consensusType,
long timeout)
Performs actual voting on the VoteChannel using the JGroups facilities for communication. |
boolean |
vote(java.lang.Object decree,
int consensusType,
long timeout,
VoteResponseProcessor voteResponseProcessor)
Performs actual voting on the VoteChannel using the JGroups facilities for communication. |
boolean |
vote(java.lang.Object decree,
long timeout)
Vote on the specified decree requiring all nodes to vote. |
boolean |
vote(java.lang.Object decree,
long timeout,
VoteResponseProcessor voteResponseProcessor)
Vote on the specified decree requiring all nodes to vote. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int VOTE_ANY
public static final int VOTE_ALL
public static final int VOTE_MAJORITY
protected final Log log
Constructor Detail |
---|
public VotingAdapter(Channel channel)
channel
- JGroups channel.public VotingAdapter(PullPushAdapter adapter, java.io.Serializable id)
Method Detail |
---|
public java.util.Collection getMembers()
public void addMembershipListener(MembershipListener l)
public void removeMembershipListener(MembershipListener l)
public boolean vote(java.lang.Object decree, int consensusType, long timeout) throws ChannelException
ChannelException
public boolean vote(java.lang.Object decree, int consensusType, long timeout, VoteResponseProcessor voteResponseProcessor) throws ChannelException
ChannelException
public boolean processResponses(RspList responses, int consensusType, java.lang.Object decree) throws ChannelException
Note: we do not support voting in case of Byzantine failures, i.e. when the node responds with the fault message.
processResponses
in interface VoteResponseProcessor
responses
- The responsesconsensusType
- The consensusType of the votedecree
- The vote decree
ChannelException
public void viewAccepted(View newView)
viewAccepted
in interface MembershipListener
public void suspect(Address suspected)
suspect
in interface MembershipListener
public void block()
block
in interface MembershipListener
public byte[] getState()
getState
in interface MessageListener
null
, we do not have any group-shared
state.public void receive(Message msg)
receive
in interface MessageListener
msg
- message to check.public void setState(byte[] state)
setState
in interface MessageListener
public boolean vote(java.lang.Object decree, long timeout) throws ChannelException
decree
- decree on which nodes should vote.timeout
- time during which nodes can vote.
true
if nodes agreed on a decree, otherwise
false
ChannelException
- if something went wrong.public boolean vote(java.lang.Object decree, long timeout, VoteResponseProcessor voteResponseProcessor) throws ChannelException
decree
- decree on which nodes should vote.timeout
- time during which nodes can vote.voteResponseProcessor
- processor which will be called for every response that is received.
true
if nodes agreed on a decree, otherwise
false
ChannelException
- if something went wrong.public void addVoteListener(VotingListener listener)
public void removeVoteListener(VotingListener listener)
public VotingAdapter.VoteResult localVote(java.lang.Object decree)
public static java.lang.String getConsensusStr(int consensusType)
consensusType
- type of the consensus.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |