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