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


Java LearnerType类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType的典型用法代码示例。如果您正苦于以下问题:Java LearnerType类的具体用法?Java LearnerType怎么用?Java LearnerType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LearnerType类属于org.apache.zookeeper.server.quorum.QuorumPeer包,在下文中一共展示了LearnerType类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: QuorumMaj

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
public QuorumMaj(Properties props) throws ConfigException {
    for (Entry<Object, Object> entry : props.entrySet()) {
        String key = entry.getKey().toString();
        String value = entry.getValue().toString();

        if (key.startsWith("server.")) {
            int dot = key.indexOf('.');
            long sid = Long.parseLong(key.substring(dot + 1));
            QuorumServer qs = new QuorumServer(sid, value);
            allMembers.put(Long.valueOf(sid), qs);
            if (qs.type == LearnerType.PARTICIPANT)
                votingMembers.put(Long.valueOf(sid), qs);
            else {
                observingMembers.put(Long.valueOf(sid), qs);
            }
        } else if (key.equals("version")) {
            version = Long.parseLong(value, 16);
        }
    }
    half = votingMembers.size() / 2;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:22,代码来源:QuorumMaj.java

示例2: verifyElectionTimeTakenJMXAttribute

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的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);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:27,代码来源:HierarchicalQuorumTest.java

示例3: startForwarding

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * lets the leader know that a follower is capable of following and is done
 * syncing
 * 
 * @param handler handler of the follower
 * @return last proposed zxid
 */
synchronized public long startForwarding(LearnerHandler handler,
        long lastSeenZxid) {
    // Queue up any outstanding requests enabling the receipt of
    // new requests
    if (lastProposed > lastSeenZxid) {
        for (Proposal p : toBeApplied) {
            if (p.packet.getZxid() <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(p.packet);
            // Since the proposal has been committed we need to send the
            // commit message also
            QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet
                    .getZxid(), null, null);
            handler.queuePacket(qp);
        }
        // Only participant need to get outstanding proposals
        if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
            List<Long>zxids = new ArrayList<Long>(outstandingProposals.keySet());
            Collections.sort(zxids);
            for (Long zxid: zxids) {
                if (zxid <= lastSeenZxid) {
                    continue;
                }
                handler.queuePacket(outstandingProposals.get(zxid).packet);
            }
        }
    }
    if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
        addForwardingFollower(handler);
    } else {
        addObserverLearnerHandler(handler);
    }
            
    return lastProposed;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:44,代码来源:Leader.java

示例4: learningState

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * A learning state can be either FOLLOWING or OBSERVING. This method simply
 * decides which one depending on the role of the server.
 *
 * @return ServerState
 */
private ServerState learningState() {
	if (self.getLearnerType() == LearnerType.PARTICIPANT) {
		LOG.debug("I'm a participant: " + self.getId());
		return ServerState.FOLLOWING;
	} else {
		LOG.debug("I'm an observer: " + self.getId());
		return ServerState.OBSERVING;
	}
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:16,代码来源:FastLeaderElection.java

示例5: getInitId

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * Returns the initial vote value of server identifier.
 *
 * @return long
 */
private long getInitId() {
	if (self.getLearnerType() == LearnerType.PARTICIPANT)
		return self.getId();
	else
		return Long.MIN_VALUE;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:FastLeaderElection.java

示例6: getInitLastLoggedZxid

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * Returns initial last logged zxid.
 *
 * @return long
 */
private long getInitLastLoggedZxid() {
	if (self.getLearnerType() == LearnerType.PARTICIPANT)
		return self.getLastLoggedZxid();
	else
		return Long.MIN_VALUE;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:FastLeaderElection.java

示例7: getPeerEpoch

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * Returns the initial vote value of the peer epoch.
 *
 * @return long
 */
private long getPeerEpoch() {
	if (self.getLearnerType() == LearnerType.PARTICIPANT)
		try {
			return self.getCurrentEpoch();
		} catch (IOException e) {
			RuntimeException re = new RuntimeException(e.getMessage());
			re.setStackTrace(e.getStackTrace());
			throw re;
		}
	else
		return Long.MIN_VALUE;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:18,代码来源:FastLeaderElection.java

示例8: startForwarding

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * lets the leader know that a follower is capable of following and is done
 * syncing
 *
 * @param handler handler of the follower
 * @return last proposed zxid
 * @throws InterruptedException 
 */
synchronized public long startForwarding(LearnerHandler handler,
        long lastSeenZxid) {
    // Queue up any outstanding requests enabling the receipt of
    // new requests
    if (lastProposed > lastSeenZxid) {
        for (Proposal p : toBeApplied) {
            if (p.packet.getZxid() <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(p.packet);
            // Since the proposal has been committed we need to send the
            // commit message also
            QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet
                    .getZxid(), null, null);
            handler.queuePacket(qp);
        }
        // Only participant need to get outstanding proposals
        if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
            List<Long>zxids = new ArrayList<Long>(outstandingProposals.keySet());
            Collections.sort(zxids);
            for (Long zxid: zxids) {
                if (zxid <= lastSeenZxid) {
                    continue;
                }
                handler.queuePacket(outstandingProposals.get(zxid).packet);
            }
        }
    }
    if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
        addForwardingFollower(handler);
    } else {
        addObserverLearnerHandler(handler);
    }

    return lastProposed;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:45,代码来源:Leader.java

示例9: learningState

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * A learning state can be either FOLLOWING or OBSERVING.
 * This method simply decides which one depending on the
 * role of the server.
 *
 * @return ServerState
 */
private ServerState learningState(){
    if(self.getLearnerType() == LearnerType.PARTICIPANT){
        LOG.debug("I'm a participant: " + self.getId());
        return ServerState.FOLLOWING;
    }
    else{
        LOG.debug("I'm an observer: " + self.getId());
        return ServerState.OBSERVING;
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:18,代码来源:FastLeaderElection.java

示例10: getPeerEpoch

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * Returns the initial vote value of the peer epoch.
 *
 * @return long
 */
private long getPeerEpoch(){
    if(self.getLearnerType() == LearnerType.PARTICIPANT)
    	try {
    		return self.getCurrentEpoch();
    	} catch(IOException e) {
    		RuntimeException re = new RuntimeException(e.getMessage());
    		re.setStackTrace(e.getStackTrace());
    		throw re;
    	}
    else return Long.MIN_VALUE;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:FastLeaderElection.java

示例11: setupPeerType

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
private void setupPeerType() {
    // Warn about inconsistent peer type
    LearnerType roleByServersList = quorumVerifier.getObservingMembers().containsKey(serverId) ? LearnerType.OBSERVER
            : LearnerType.PARTICIPANT;
    if (roleByServersList != peerType) {
        LOG.warn("Peer type from servers list (" + roleByServersList
                + ") doesn't match peerType (" + peerType
                + "). Defaulting to servers list.");

        peerType = roleByServersList;
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:13,代码来源:QuorumPeerConfig.java

示例12: startForwarding

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * lets the leader know that a follower is capable of following and is done
 * syncing
 * 
 * @param handler handler of the follower
 * @return last proposed zxid
 */
synchronized public long startForwarding(LearnerHandler handler,
        long lastSeenZxid) {
    // Queue up any outstanding requests enabling the receipt of
    // new requests
    if (lastProposed > lastSeenZxid) {
        for (Proposal p : toBeApplied) {
            if (p.packet.getZxid() <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(p.packet);
            // Since the proposal has been committed we need to send the
            // commit message also
            QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet
                    .getZxid(), null, null);
            handler.queuePacket(qp);
        }
        List<Long>zxids = new ArrayList<Long>(outstandingProposals.keySet());
        Collections.sort(zxids);
        for (Long zxid: zxids) {
            if (zxid <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(outstandingProposals.get(zxid).packet);
        }
    }
    if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
        addForwardingFollower(handler);
    } else {
        addObserverLearnerHandler(handler);
    }
            
    return lastProposed;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:41,代码来源:Leader.java

示例13: startForwarding

import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; //导入依赖的package包/类
/**
 * lets the leader know that a follower is capable of following and is done
 * syncing
 * 
 * @param handler handler of the follower
 * @return last proposed zxid
 */
synchronized public long startForwarding(LearnerHandler handler,
        long lastSeenZxid) {
    // Queue up any outstanding requests enabling the receipt of
    // new requests
    if (lastProposed > lastSeenZxid) {
        for (Proposal p : toBeApplied) {
            if (p.packet.getZxid() <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(p.packet);
            // Since the proposal has been committed we need to send the
            // commit message also
            QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet
                    .getZxid(), null, null);
            handler.queuePacket(qp);
        }
        List<Long>zxids = new ArrayList<Long>(outstandingProposals.keySet());
        Collections.sort(zxids);
        for (Long zxid: zxids) {
            if (zxid <= lastSeenZxid) {
                continue;
            }
            handler.queuePacket(outstandingProposals.get(zxid).packet);
        }
    }
    if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
        synchronized (forwardingFollowers) {
            forwardingFollowers.add(handler);
        }
    } else {
        synchronized (observingLearners) {
            observingLearners.add(handler);
        }
    }
            
    return lastProposed;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:45,代码来源:Leader.java


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