本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeer.ServerState类的典型用法代码示例。如果您正苦于以下问题:Java ServerState类的具体用法?Java ServerState怎么用?Java ServerState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerState类属于org.apache.zookeeper.server.quorum.QuorumPeer包,在下文中一共展示了ServerState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* In the case there is a leader elected, and a quorum supporting this
* leader, we have to check if the leader has voted and acked that it is
* leading. We need this check to avoid that peers keep electing over and
* over a peer that has crashed and it is no longer leading.
*
* @param votes
* set of votes
* @param leader
* leader id
* @param electionEpoch
* epoch id
*/
protected boolean checkLeader(HashMap<Long, Vote> votes, long leader, long electionEpoch) {
boolean predicate = true;
/*
* If everyone else thinks I'm the leader, I must be the leader. The
* other two checks are just for the case in which I'm not the leader.
* If I'm not the leader and I haven't received a message from leader
* stating that it is leading, then predicate is false.
*/
if (leader != self.getId()) {
if (votes.get(leader) == null)
predicate = false;
else if (votes.get(leader).getState() != ServerState.LEADING)
predicate = false;
} else if (logicalclock != electionEpoch) {
predicate = false;
}
return predicate;
}
示例2: run
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
public void run(){
try{
Vote v = null;
peer.setPeerState(ServerState.LOOKING);
LOG.info("Going to call leader election: " + i);
v = peer.getElectionAlg().lookForLeader();
if (v == null){
Assert.fail("Thread " + i + " got a null vote");
}
/*
* A real zookeeper would take care of setting the current vote. Here
* we do it manually.
*/
peer.setCurrentVote(v);
LOG.info("Finished election: " + i + ", " + v.getId());
Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
} catch (Exception e) {
e.printStackTrace();
}
LOG.info("Joining");
}
示例3: run
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
public void run(){
try{
Vote v = null;
peer.setPeerState(ServerState.LOOKING);
LOG.info("Going to call leader election: " + i);
v = peer.getElectionAlg().lookForLeader();
if (v == null){
Assert.fail("Thread " + i + " got a null vote");
}
/*
* A real zookeeper would take care of setting the current vote. Here
* we do it manually.
*/
peer.setCurrentVote(v);
LOG.info("Finished election: " + i + ", " + v.getId());
} catch (Exception e) {
e.printStackTrace();
}
LOG.info("Joining");
}
示例4: run
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
public void run() {
setName("VerifyState-" + peer.getId());
while (true) {
if(peer.getPeerState() == ServerState.FOLLOWING) {
LOG.info("I am following");
success = true;
break;
} else if (peer.getPeerState() == ServerState.LEADING) {
LOG.info("I am leading");
success = false;
break;
}
try {
Thread.sleep(250);
} catch (Exception e) {
LOG.warn("Sleep failed ", e);
}
}
}
示例5: ToSend
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
ToSend(mType type,
long leader,
long zxid,
long electionEpoch,
ServerState state,
long sid,
long peerEpoch,
byte[] configData) {
this.leader = leader;
this.zxid = zxid;
this.electionEpoch = electionEpoch;
this.state = state;
this.sid = sid;
this.peerEpoch = peerEpoch;
this.configData = configData;
}
示例6: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* Send notifications to all peers upon a change in our vote
*/
private void sendNotifications() {
for (long sid : self.getCurrentAndNextConfigVoters()) {
QuorumVerifier qv = self.getQuorumVerifier();
ToSend notmsg = new ToSend(ToSend.mType.notification,
proposedLeader,
proposedZxid,
logicalclock.get(),
QuorumPeer.ServerState.LOOKING,
sid,
proposedEpoch, qv.toString().getBytes());
if(LOG.isDebugEnabled()){
LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), 0x" +
Long.toHexString(proposedZxid) + " (n.zxid), 0x" + Long.toHexString(logicalclock.get()) +
" (n.round), " + sid + " (recipient), " + self.getId() +
" (myid), 0x" + Long.toHexString(proposedEpoch) + " (n.peerEpoch)");
}
sendqueue.offer(notmsg);
}
}
示例7: checkLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* In the case there is a leader elected, and a quorum supporting
* this leader, we have to check if the leader has voted and acked
* that it is leading. We need this check to avoid that peers keep
* electing over and over a peer that has crashed and it is no
* longer leading.
*
* @param votes set of votes
* @param leader leader id
* @param electionEpoch epoch id
*/
private boolean checkLeader(
Map<Long, Vote> votes,
long leader,
long electionEpoch){
boolean predicate = true;
/*
* If everyone else thinks I'm the leader, I must be the leader.
* The other two checks are just for the case in which I'm not the
* leader. If I'm not the leader and I haven't received a message
* from leader stating that it is leading, then predicate is false.
*/
if(leader != self.getId()){
if(votes.get(leader) == null) predicate = false;
else if(votes.get(leader).getState() != ServerState.LEADING) predicate = false;
} else if(logicalclock.get() != electionEpoch) {
predicate = false;
}
return predicate;
}
示例8: run
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
public void run() {
try {
Vote v = null;
peer.setPeerState(ServerState.LOOKING);
LOG.info("Going to call leader election: {}", i);
v = peer.getElectionAlg().lookForLeader();
if (v == null) {
Assert.fail("Thread " + i + " got a null vote");
}
/*
* A real zookeeper would take care of setting the current vote. Here
* we do it manually.
*/
peer.setCurrentVote(v);
LOG.info("Finished election: {}, {}", i, v.getId());
Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
} catch (Exception e) {
e.printStackTrace();
}
LOG.info("Joining");
}
示例9: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* Send notifications to all peers upon a change in our vote
*/
private void sendNotifications() {
for (QuorumServer server : self.getVotingView().values()) {
long sid = server.id;
ToSend notmsg = new ToSend(ToSend.mType.notification,
proposedLeader,
proposedZxid,
logicalclock,
QuorumPeer.ServerState.LOOKING,
sid,
proposedEpoch);
if(LOG.isDebugEnabled()){
LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), 0x" +
Long.toHexString(proposedZxid) + " (n.zxid), 0x" + Long.toHexString(logicalclock) +
" (n.round), " + sid + " (recipient), " + self.getId() +
" (myid), 0x" + Long.toHexString(proposedEpoch) + " (n.peerEpoch)");
}
sendqueue.offer(notmsg);
}
}
示例10: checkLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* In the case there is a leader elected, and a quorum supporting
* this leader, we have to check if the leader has voted and acked
* that it is leading. We need this check to avoid that peers keep
* electing over and over a peer that has crashed and it is no
* longer leading.
*
* @param votes set of votes
* @param leader leader id
* @param electionEpoch epoch id
*/
protected boolean checkLeader(
HashMap<Long, Vote> votes,
long leader,
long electionEpoch){
boolean predicate = true;
/*
* If everyone else thinks I'm the leader, I must be the leader.
* The other two checks are just for the case in which I'm not the
* leader. If I'm not the leader and I haven't received a message
* from leader stating that it is leading, then predicate is false.
*/
if(leader != self.getId()){
if(votes.get(leader) == null) predicate = false;
else if(votes.get(leader).getState() != ServerState.LEADING) predicate = false;
} else if(logicalclock != electionEpoch) {
predicate = false;
}
return predicate;
}
示例11: shutdownQP
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
private void shutdownQP(QuorumPeer qp) throws InterruptedException {
assertNotNull("QuorumPeer doesn't exist!", qp);
qp.shutdown();
int retryCnt = 30;
while (retryCnt > 0) {
if (qp.getPeerState() == ServerState.LOOKING) {
LOG.info("Number of retries:{} to change the server state to {}",
retryCnt, ServerState.LOOKING);
break;
}
Thread.sleep(500);
retryCnt--;
}
Assert.assertEquals(
"After shutdown, QuorumPeer should change its state to LOOKING",
ServerState.LOOKING, qp.getPeerState());
}
示例12: verifyElectionTimeTakenJMXAttribute
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
private void verifyElectionTimeTakenJMXAttribute(List<QuorumPeer> peers)
throws Exception {
LOG.info("Verify QuorumPeer#electionTimeTaken jmx bean attribute");
for (int i = 1; i <= peers.size(); i++) {
QuorumPeer qp = peers.get(i - 1);
if (qp.getLearnerType() == LearnerType.OBSERVER) {
continue; // Observer don't have electionTimeTaken attribute.
}
Long electionTimeTaken = -1L;
String bean = "";
if (qp.getPeerState() == ServerState.FOLLOWING) {
bean = String.format(
"%s:name0=ReplicatedServer_id%d,name1=replica.%d,name2=Follower",
CommonNames.DOMAIN, i, i);
} else if (qp.getPeerState() == ServerState.LEADING) {
bean = String.format(
"%s:name0=ReplicatedServer_id%d,name1=replica.%d,name2=Leader",
CommonNames.DOMAIN, i, i);
}
electionTimeTaken = (Long) JMXEnv.ensureBeanAttribute(bean,
"ElectionTimeTaken");
Assert.assertTrue("Wrong electionTimeTaken value!",
electionTimeTaken >= 0);
}
}
示例13: checkLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* In the case there is a leader elected, and a quorum supporting
* this leader, we have to check if the leader has voted and acked
* that it is leading. We need this check to avoid that peers keep
* electing over and over a peer that has crashed and it is no
* longer leading.
*
* @param votes set of votes
* @param leader leader id
* @param electionEpoch epoch id
*/
private boolean checkLeader(
HashMap<Long, Vote> votes,
long leader,
long electionEpoch){
boolean predicate = true;
/*
* If everyone else thinks I'm the leader, I must be the leader.
* The other two checks are just for the case in which I'm not the
* leader. If I'm not the leader and I haven't received a message
* from leader stating that it is leading, then predicate is false.
*/
if(leader != self.getId()){
if(votes.get(leader) == null) predicate = false;
else if(votes.get(leader).getState() != ServerState.LEADING) predicate = false;
} else if(logicalclock != electionEpoch) {
predicate = false;
}
return predicate;
}
示例14: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* Send notifications to all peers upon a change in our vote
*/
private void sendNotifications() {
for (QuorumServer server : self.getVotingView().values()) {
long sid = server.id;
ToSend notmsg = new ToSend(ToSend.mType.notification,
proposedLeader,
proposedZxid,
logicalclock,
QuorumPeer.ServerState.LOOKING,
sid,
proposedEpoch);
if(LOG.isDebugEnabled()){
LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), " +
proposedZxid + " (n.zxid), " + logicalclock +
" (n.round), " + sid + " (recipient), " + self.getId() +
" (myid), " + proposedEpoch + " (n.peerEpoch)");
}
sendqueue.offer(notmsg);
}
}
示例15: checkLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; //导入依赖的package包/类
/**
* In the case there is a leader elected, and a quorum supporting
* this leader, we have to check if the leader has voted and acked
* that it is leading. We need this check to avoid that peers keep
* electing over and over a peer that has crashed and it is no
* longer leading.
*
* @param votes set of votes
* @param leader leader id
* @param electionEpoch epoch id
*/
private boolean checkLeader(
HashMap<Long, Vote> votes,
long leader,
long electionEpoch){
boolean predicate = true;
/*
* If everyone else thinks I'm the leader, I must be the leader.
* The other two checks are just for the case in which I'm not the
* leader. If I'm not the leader and I haven't received a message
* from leader stating that it is leading, then predicate is false.
*/
if(leader != self.getId()){
if(votes.get(leader) == null) predicate = false;
else if(votes.get(leader).getState() != ServerState.LEADING) predicate = false;
} else if(logicalclock.get() != electionEpoch) {
predicate = false;
}
return predicate;
}