本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType.OBSERVER属性的典型用法代码示例。如果您正苦于以下问题:Java LearnerType.OBSERVER属性的具体用法?Java LearnerType.OBSERVER怎么用?Java LearnerType.OBSERVER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType
的用法示例。
在下文中一共展示了LearnerType.OBSERVER属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyElectionTimeTakenJMXAttribute
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);
}
}
示例2: setupPeerType
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;
}
}
示例3: testCnxManagerNPE
/**
* Tests a bug in QuorumCnxManager that causes a NPE when a 3.4.6
* observer connects to a 3.5.0 server.
* {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1789}
*
* @throws Exception
*/
@Test
public void testCnxManagerNPE() throws Exception {
// the connecting peer (id = 2) is a 3.4.6 observer
peers.get(2L).type = LearnerType.OBSERVER;
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1],
peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
if (listener != null) {
listener.start();
} else {
LOG.error("Null listener when initializing cnx manager");
}
int port = peers.get(peer.getId()).electionAddr.getPort();
LOG.info("Election port: " + port);
Thread.sleep(1000);
SocketChannel sc = SocketChannel.open();
sc.socket().connect(peers.get(1L).electionAddr, 5000);
/*
* Write id (3.4.6 protocol). This previously caused a NPE in
* QuorumCnxManager.
*/
byte[] msgBytes = new byte[8];
ByteBuffer msgBuffer = ByteBuffer.wrap(msgBytes);
msgBuffer.putLong(2L);
msgBuffer.position(0);
sc.write(msgBuffer);
msgBuffer = ByteBuffer.wrap(new byte[8]);
// write length of message
msgBuffer.putInt(4);
// write message
msgBuffer.putInt(5);
msgBuffer.position(0);
sc.write(msgBuffer);
Message m = cnxManager.pollRecvQueue(1000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(m);
peer.shutdown();
cnxManager.halt();
Assert.assertFalse(cnxManager.listener.isAlive());
}