本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer类的典型用法代码示例。如果您正苦于以下问题:Java QuorumServer类的具体用法?Java QuorumServer怎么用?Java QuorumServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuorumServer类属于org.apache.zookeeper.server.quorum.QuorumPeer包,在下文中一共展示了QuorumServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: findLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
/**
* Returns the address of the node we think is the leader.
*/
protected InetSocketAddress findLeader() {
InetSocketAddress addr = null;
// Find the leader by id
Vote current = self.getCurrentVote();
for (QuorumServer s : self.getView().values()) {
if (s.id == current.getId()) {
// Ensure we have the leader's correct IP address before
// attempting to connect.
s.recreateSocketAddresses();
addr = s.addr;
break;
}
}
if (addr == null) {
LOG.warn("Couldn't find the leader with id = "
+ current.getId());
}
return addr;
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:Learner.java
示例2: fakeConfigureServers
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
private void fakeConfigureServers(int count) throws IOException {
peers = new HashMap<Long,QuorumServer>();
qps = new QuorumPeer[count];
qpsDirs = new File[count];
for(int i = 1; i <= count; i++) {
peers.put(Long.valueOf(i), new QuorumServer(
i, "127.0.0.1", fakeBasePort + i, serverCount + fakeBasePort + i, null));
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < count; i++) {
//make that testData exists otherwise it fails on windows
testData.mkdirs();
qpsDirs[i] = File.createTempFile("sysTest", ".tmp", testData);
qpsDirs[i].delete();
qpsDirs[i].mkdir();
int port = fakeBasePort+10+i;
if (sb.length() > 0) {
sb.append(',');
}
sb.append("localhost:");
sb.append(port);
}
serverHostPort = sb.toString();
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:25,代码来源:BaseSysTest.java
示例3: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0",
peerQuorumPort[i],
PortAssignment.unique(), null));
peerTmpdir[i] = ClientBase.createTmpDir();
}
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:CnxManagerTest.java
示例4: mockServer
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的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: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
count = 3;
peers = new HashMap<Long,QuorumServer>(count);
threads = new ArrayList<LEThread>(count);
tmpdir = new File[count];
port = new int[count];
round = new int[3];
round[0] = 0;
round[1] = 0;
round[2] = 0;
start0 = new Semaphore(0);
finish0 = new Semaphore(0);
finish3 = new Semaphore(0);
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:FLENewEpochTest.java
示例6: equals
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
public boolean equals(Object o) {
if (!(o instanceof QuorumMaj)) {
return false;
}
QuorumMaj qm = (QuorumMaj) o;
if (qm.getVersion() == version)
return true;
if (allMembers.size() != qm.getAllMembers().size())
return false;
for (QuorumServer qs : allMembers.values()) {
QuorumServer qso = qm.getAllMembers().get(qs.id);
if (qso == null || !qs.equals(qso))
return false;
}
return true;
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:QuorumMaj.java
示例7: QuorumMaj
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的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
示例8: toString
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
public String toString() {
StringBuilder sw = new StringBuilder();
for (QuorumServer member : getAllMembers().values()) {
String key = "server." + member.id;
String value = member.toString();
sw.append(key);
sw.append('=');
sw.append(value);
sw.append('\n');
}
String hexVersion = Long.toHexString(version);
sw.append("version=");
sw.append(hexVersion);
return sw.toString();
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:QuorumMaj.java
示例9: findLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
/**
* Returns the address of the node we think is the leader.
*/
protected InetSocketAddress findLeader() {
InetSocketAddress addr = null;
// Find the leader by id
Vote current = self.getCurrentVote();
for (QuorumServer s : self.getView().values()) {
if (s.id == current.getId()) {
addr = s.addr;
break;
}
}
if (addr == null) {
LOG.warn("Couldn't find the leader with id = "
+ current.getId());
}
return addr;
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:20,代码来源:Learner.java
示例10: setupClientPort
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
private void setupClientPort() throws ConfigException {
if (serverId == UNSET_SERVERID) {
return;
}
QuorumServer qs = quorumVerifier.getAllMembers().get(serverId);
if (clientPortAddress != null && qs != null && qs.clientAddr != null) {
if ((!clientPortAddress.getAddress().isAnyLocalAddress()
&& !clientPortAddress.equals(qs.clientAddr)) ||
(clientPortAddress.getAddress().isAnyLocalAddress()
&& clientPortAddress.getPort() != qs.clientAddr.getPort()))
throw new ConfigException("client address for this server (id = " + serverId +
") in static config file is " + clientPortAddress +
" is different from client address found in dynamic file: " + qs.clientAddr);
}
if (qs != null && qs.clientAddr != null) clientPortAddress = qs.clientAddr;
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:QuorumPeerConfig.java
示例11: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
/**
* Send notifications to all peers upon a change in our vote
*/
private void sendNotifications() {
for (QuorumServer server : self.getVotingView().values()) {
long sid = server.id;
ToSend notmsg = new ToSend(ToSend.mType.notification,
proposedLeader,
proposedZxid,
logicalclock,
QuorumPeer.ServerState.LOOKING,
sid,
proposedEpoch);
if(LOG.isDebugEnabled()){
LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), 0x" +
Long.toHexString(proposedZxid) + " (n.zxid), 0x" + Long.toHexString(logicalclock) +
" (n.round), " + sid + " (recipient), " + self.getId() +
" (myid), 0x" + Long.toHexString(proposedEpoch) + " (n.peerEpoch)");
}
sendqueue.offer(notmsg);
}
}
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:24,代码来源:FastLeaderElection.java
示例12: findLeader
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
/**
* Returns the address of the node we think is the leader.
*/
protected QuorumServer findLeader() {
QuorumServer leaderServer = null;
// Find the leader by id
Vote current = self.getCurrentVote();
for (QuorumServer s : self.getView().values()) {
if (s.id == current.getId()) {
// Ensure we have the leader's correct IP address before
// attempting to connect.
s.recreateSocketAddresses();
leaderServer = s;
break;
}
}
if (leaderServer == null) {
LOG.warn("Couldn't find the leader with id = "
+ current.getId());
}
return leaderServer;
}
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:Learner.java
示例13: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerQuorumPort = new int[count];
peerClientPort = new int[count];
authzHosts = new HashSet<String>();
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
QuorumServer qs = new QuorumServer(i, "0.0.0.0",
peerQuorumPort[i], PortAssignment.unique(), null);
peers.put(Long.valueOf(i), qs);
authzHosts.add(qs.hostname);
}
executor = new ThreadPoolExecutor(3, 10,
60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:19,代码来源:QuorumCnxManagerTest.java
示例14: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
private void sendNotifications() {
for (QuorumServer server : self.getView().values()) {
ToSend notmsg = new ToSend(ToSend.mType.notification,
AuthFastLeaderElection.sequencer++, proposedLeader,
proposedZxid, logicalclock, QuorumPeer.ServerState.LOOKING,
self.getView().get(server.id).electionAddr);
sendqueue.offer(notmsg);
}
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:AuthFastLeaderElection.java
示例15: sendNotifications
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
/**
* Send notifications to all peers upon a change in our vote
*/
private void sendNotifications() {
for (QuorumServer server : self.getVotingView().values()) {
long sid = server.id;
ToSend notmsg = new ToSend(ToSend.mType.notification, proposedLeader, proposedZxid, logicalclock,
QuorumPeer.ServerState.LOOKING, sid, proposedEpoch);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), 0x" + Long.toHexString(proposedZxid)
+ " (n.zxid), 0x" + Long.toHexString(logicalclock) + " (n.round), " + sid + " (recipient), "
+ self.getId() + " (myid), 0x" + Long.toHexString(proposedEpoch) + " (n.peerEpoch)");
}
sendqueue.offer(notmsg);
}
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:18,代码来源:FastLeaderElection.java
示例16: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp()
throws Exception {
tmpdir = ClientBase.createTmpDir();
peers = new HashMap<Long,QuorumServer>();
for(int i = 0; i < 5; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(Long.valueOf(i), "127.0.0.1", PortAssignment.unique(), 0, null));
}
peer = new QuorumPeer(peers,
tmpdir,
tmpdir,
PortAssignment.unique(),
3, 3, 1000, 2, 2);
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:16,代码来源:FLEDontCareTest.java
示例17: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
count = 3;
peers = new HashMap<Long,QuorumServer>(count);
tmpdir = new File[count];
port = new int[count];
cnxManagers = new QuorumCnxManager[count - 1];
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:10,代码来源:FLEBackwardElectionRoundTest.java
示例18: testCnxManagerTimeout
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Test
public void testCnxManagerTimeout() throws Exception {
Random rand = new Random();
byte b = (byte) rand.nextInt();
int finalOctet = b & 0xFF;
int deadPort = PortAssignment.unique();
String deadAddress = new String("192.0.2." + finalOctet);
LOG.info("This is the dead address I'm trying: " + deadAddress);
peers.put(Long.valueOf(2),
new QuorumServer(2, deadAddress, deadPort, PortAssignment.unique(), null));
peerTmpdir[2] = ClientBase.createTmpDir();
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");
}
long begin = System.currentTimeMillis();
cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
long end = System.currentTimeMillis();
if((end - begin) > 6000) Assert.fail("Waited more than necessary");
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:CnxManagerTest.java
示例19: setUp
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
count = 3;
peers = new HashMap<Long,QuorumServer>(count);
tmpdir = new File[count];
port = new int[count];
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:8,代码来源:FLECompatibilityTest.java
示例20: populate
import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; //导入依赖的package包/类
void populate()
throws Exception {
for (int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0",
PortAssignment.unique(),
PortAssignment.unique(), null));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
}
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:FLECompatibilityTest.java
注:本文中的org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论