当前位置: 首页>>代码示例>>Java>>正文


Java Vote类代码示例

本文整理汇总了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;

}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:22,代码来源:AuthFastLeaderElection.java

示例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");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:26,代码来源:FLETestUtils.java

示例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");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:24,代码来源:LENonTerminateTest.java

示例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);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:29,代码来源:LENonTerminateTest.java

示例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;

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:22,代码来源:AuthFastLeaderElection.java

示例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");
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:26,代码来源:FLETestUtils.java

示例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");
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:FLELostMessageTest.java

示例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");
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:24,代码来源:LENonTerminateTest.java

示例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);
    }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:29,代码来源:LENonTerminateTest.java

示例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)));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:FLEDontCareTest.java

示例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)));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:FLEDontCareTest.java

示例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)));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:FLEDontCareTest.java

示例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)));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:FLEDontCareTest.java

示例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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:41,代码来源:FLEDontCareTest.java


注:本文中的org.apache.zookeeper.server.quorum.Vote类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。