本文整理汇总了Java中org.apache.zookeeper.server.quorum.Vote类的典型用法代码示例。如果您正苦于以下问题:Java Vote类的具体用法?Java Vote怎么用?Java Vote使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vote类属于org.apache.zookeeper.server.quorum包,在下文中一共展示了Vote类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: termPredicate
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
long l, long zxid) {
Collection<Vote> votesCast = votes.values();
int count = 0;
/*
* First make the views consistent. Sometimes peers will have different
* zxids for a server depending on timing.
*/
for (Vote v : votesCast) {
if ((v.getId() == l) && (v.getZxid() == zxid))
count++;
}
if (count > (self.getVotingView().size() / 2))
return true;
else
return false;
}
示例2: run
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的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.Vote; //导入依赖的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: mockServer
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
/**
* MockServer plays the role of peer C. Respond to two requests for votes
* with vote for self and then Assert.fail.
*/
void mockServer() throws InterruptedException, IOException {
byte b[] = new byte[36];
ByteBuffer responseBuffer = ByteBuffer.wrap(b);
DatagramPacket packet = new DatagramPacket(b, b.length);
QuorumServer server = peers.get(Long.valueOf(2));
DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
LOG.info("In MockServer");
mockLatch.countDown();
Vote current = new Vote(2, 1);
for (int i=0;i<2;++i) {
udpSocket.receive(packet);
responseBuffer.rewind();
LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
LOG.info("From " + packet.getSocketAddress());
responseBuffer.clear();
responseBuffer.getInt(); // Skip the xid
responseBuffer.putLong(2);
responseBuffer.putLong(current.getId());
responseBuffer.putLong(current.getZxid());
packet.setData(b);
udpSocket.send(packet);
}
}
示例5: termPredicate
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
private boolean termPredicate(Map<InetSocketAddress, Vote> votes,
long l, long zxid) {
Collection<Vote> votesCast = votes.values();
int count = 0;
/*
* First make the views consistent. Sometimes peers will have different
* zxids for a server depending on timing.
*/
for (Vote v : votesCast) {
if ((v.getId() == l) && (v.getZxid() == zxid))
count++;
}
if (count > (self.getVotingView().size() / 2))
return true;
else
return false;
}
示例6: run
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的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");
}
示例7: run
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
public void run(){
boolean flag = true;
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");
}
示例8: run
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的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");
}
示例9: mockServer
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
/**
* MockServer plays the role of peer C. Respond to two requests for votes
* with vote for self and then Assert.fail.
*/
void mockServer() throws InterruptedException, IOException {
byte b[] = new byte[36];
ByteBuffer responseBuffer = ByteBuffer.wrap(b);
DatagramPacket packet = new DatagramPacket(b, b.length);
QuorumServer server = peers.get(Long.valueOf(2));
DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
LOG.info("In MockServer");
mockLatch.countDown();
Vote current = new Vote(2, 1);
for (int i=0;i<2;++i) {
udpSocket.receive(packet);
responseBuffer.rewind();
LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
LOG.info("From " + packet.getSocketAddress());
responseBuffer.clear();
responseBuffer.getInt(); // Skip the xid
responseBuffer.putLong(2);
responseBuffer.putLong(current.getId());
responseBuffer.putLong(current.getZxid());
packet.setData(b);
udpSocket.send(packet);
}
}
示例10: testDontCare
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
@Test
public void testDontCare() {
MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));
HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 2, ServerState.FOLLOWING));
votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 2), 1, 2, ServerState.FOLLOWING));
votes.put(3L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
votes.put(4L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));
Assert.assertTrue(fle.termPredicate(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)));
}
示例11: testDontCareVersion
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
@Test
public void testDontCareVersion() {
MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));
HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));
Assert.assertTrue(fle.termPredicate(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)));
}
示例12: testLookingNormal
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
@Test
public void testLookingNormal() {
MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));
HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LEADING));
Assert.assertTrue(fle.termPredicate(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING)));
}
示例13: testLookingDiffRounds
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
@Test
public void testLookingDiffRounds() {
MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));
HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.LOOKING));
votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING));
votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LOOKING));
votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LEADING));
Assert.assertFalse(fle.termPredicate(votes,
new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING)));
}
示例14: genNotification
import org.apache.zookeeper.server.quorum.Vote; //导入依赖的package包/类
/**
* Helper method to build notifications and populate outofelection.
*
*
* @param version
* @param leader
* @param zxid
* @param electionEpoch
* @param state
* @param sid
* @param peerEpoch
* @param outofelection
* @return
*/
FastLeaderElection.Notification genNotification(int version,
long leader,
long zxid,
long electionEpoch,
ServerState state,
long sid,
long peerEpoch,
HashMap<Long,Vote> outofelection) {
FastLeaderElection.Notification n = new FastLeaderElection.Notification();
n.version = version;
n.leader = leader;
n.zxid = zxid;
n.electionEpoch = electionEpoch;
n.state = state;
n.sid = sid;
n.peerEpoch = peerEpoch;
outofelection.put(n.sid, new Vote(n.version,
n.leader,
n.zxid,
n.electionEpoch,
n.peerEpoch,
n.state));
return n;
}