本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumCnxManager.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.apache.zookeeper.server.quorum.QuorumCnxManager包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
public void run(){
try {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 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");
}
long sid = 1;
cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
if(numRetries > THRESHOLD){
failed = true;
return;
}
cnxManager.testInitiateConnection(sid);
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null){
failed = true;
return;
}
} catch (Exception e) {
LOG.error("Exception while running mock thread", e);
Assert.fail("Unexpected exception");
}
}
示例2: testCnxManager
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test
public void testCnxManager() throws Exception {
CnxManagerThread thread = new CnxManagerThread();
thread.start();
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");
}
cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Thread didn't join");
} else {
if(thread.failed)
Assert.fail("Did not receive expected message");
}
}
示例3: testBackwardCompatibility
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test(timeout=20000)
public void testBackwardCompatibility()
throws Exception {
populate();
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.setPeerState(ServerState.LOOKING);
QuorumCnxManager mng = new QuorumCnxManager(peer);
/*
* Check that it generates an internal notification correctly
*/
MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
fle.manager.recvQueue.add(new Message(buffer, 2));
Notification n = fle.recvqueue.take();
Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
Assert.assertTrue("Wrong leader", n.leader == 2);
Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
/*
* Check that it sends a notification back to the sender
*/
peer.setPeerState(ServerState.FOLLOWING);
peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
fle.manager.recvQueue.add(new Message(buffer, 1));
ToSend m = fle.internalqueue.take();
Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
Assert.assertTrue("Wrong sid", m.sid == 1);
Assert.assertTrue("Wrong leader", m.leader == 2);
Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
示例4: testForwardCompatibility
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test(timeout=20000)
public void testForwardCompatibility()
throws Exception {
populate();
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.setPeerState(ServerState.LOOKING);
QuorumCnxManager mng = new QuorumCnxManager(peer);
/*
* Check that it generates an internal notification correctly
*/
MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
notBuffer.flip();
buffer.put(notBuffer);
buffer.putLong( Long.MAX_VALUE );
buffer.flip();
fle.manager.recvQueue.add(new Message(buffer, 2));
Notification n = fle.recvqueue.take();
Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
Assert.assertTrue("Wrong leader", n.leader == 2);
Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
示例5: testCnxManager
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test
public void testCnxManager() throws Exception {
CnxManagerThread thread = new CnxManagerThread();
thread.start();
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");
}
cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Thread didn't join");
} else {
if(thread.failed)
Assert.fail("Did not receive expected message");
}
cnxManager.halt();
Assert.assertFalse(cnxManager.listener.isAlive());
}
示例6: run
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
public void run(){
try {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
QuorumCnxManager cnxManager = peer.createCnxnManager();
QuorumCnxManager.Listener listener = cnxManager.listener;
if(listener != null){
listener.start();
} else {
LOG.error("Null listener when initializing cnx manager");
}
long sid = 1;
cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
if(numRetries > THRESHOLD){
failed = true;
return;
}
cnxManager.testInitiateConnection(sid);
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null){
failed = true;
return;
}
} catch (Exception e) {
LOG.error("Exception while running mock thread", e);
Assert.fail("Unexpected exception");
}
}
示例7: testCnxManager
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test
public void testCnxManager() throws Exception {
CnxManagerThread thread = new CnxManagerThread();
thread.start();
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = peer.createCnxnManager();
QuorumCnxManager.Listener listener = cnxManager.listener;
if(listener != null){
listener.start();
} else {
LOG.error("Null listener when initializing cnx manager");
}
cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Thread didn't join");
} else {
if(thread.failed)
Assert.fail("Did not receive expected message");
}
}
示例8: testBackwardCompatibility
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test(timeout=20000)
public void testBackwardCompatibility()
throws Exception {
populate();
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.setPeerState(ServerState.LOOKING);
QuorumCnxManager mng = peer.createCnxnManager();
/*
* Check that it generates an internal notification correctly
*/
MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
fle.manager.recvQueue.add(new Message(buffer, 2));
Notification n = fle.recvqueue.take();
Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
Assert.assertTrue("Wrong leader", n.leader == 2);
Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
/*
* Check that it sends a notification back to the sender
*/
peer.setPeerState(ServerState.FOLLOWING);
peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
fle.manager.recvQueue.add(new Message(buffer, 1));
ToSend m = fle.internalqueue.take();
Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
Assert.assertTrue("Wrong sid", m.sid == 1);
Assert.assertTrue("Wrong leader", m.leader == 2);
Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
示例9: testForwardCompatibility
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test(timeout=20000)
public void testForwardCompatibility()
throws Exception {
populate();
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.setPeerState(ServerState.LOOKING);
QuorumCnxManager mng = peer.createCnxnManager();
/*
* Check that it generates an internal notification correctly
*/
MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
notBuffer.flip();
buffer.put(notBuffer);
buffer.putLong( Long.MAX_VALUE );
buffer.flip();
fle.manager.recvQueue.add(new Message(buffer, 2));
Notification n = fle.recvqueue.take();
Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
Assert.assertTrue("Wrong leader", n.leader == 2);
Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
示例10: run
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
public void run(){
try {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 2, 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");
}
long sid = 1;
cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
if(numRetries > THRESHOLD){
failed = true;
return;
}
cnxManager.testInitiateConnection(sid);
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null){
failed = true;
return;
}
} catch (Exception e) {
LOG.error("Exception while running mock thread", e);
Assert.fail("Unexpected exception");
}
}
示例11: testCnxManager
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test
public void testCnxManager() throws Exception {
CnxManagerThread thread = new CnxManagerThread();
thread.start();
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2, 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");
}
cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Thread didn't join");
} else {
if(thread.failed)
Assert.fail("Did not receive expected message");
}
}
示例12: run
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
public void run(){
try {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 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");
}
long sid = 1;
cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
if(numRetries > THRESHOLD){
failed = true;
return;
}
cnxManager.testInitiateConnection(sid);
m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
if(m == null){
failed = true;
return;
}
} catch (Exception e) {
LOG.error("Exception while running mock thread", e);
fail("Unexpected exception");
}
}
示例13: testCnxManager
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
@Test
public void testCnxManager() throws Exception {
CnxManagerThread thread = new CnxManagerThread();
thread.start();
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");
}
cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
while((m == null) && (numRetries++ <= THRESHOLD)){
m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
if (thread.isAlive()) {
fail("Thread didn't join");
} else {
if(thread.failed)
fail("Did not receive expected message");
}
}
示例14: getSid
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
long getSid(Message m){
return m.sid;
}
示例15: getMsgString
import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; //导入依赖的package包/类
String getMsgString(Message m){
return new String(m.buffer.array());
}