gpt4 book ai didi

org.apache.zookeeper.server.ZooKeeperServer.()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 06:08:40 27 4
gpt4 key购买 nike

本文整理了Java中org.apache.zookeeper.server.ZooKeeperServer.<init>()方法的一些代码示例,展示了ZooKeeperServer.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperServer.<init>()方法的具体详情如下:
包路径:org.apache.zookeeper.server.ZooKeeperServer
类名称:ZooKeeperServer
方法名:<init>

ZooKeeperServer.<init>介绍

[英]Creates a ZooKeeperServer instance. Nothing is setup, use the setX methods to prepare the instance (eg datadir, datalogdir, ticktime, builder, etc...)
[中]

代码示例

代码示例来源:origin: alibaba/jstorm

public static Factory mkInprocessZookeeper(String localDir, int port)
    throws IOException, InterruptedException {
  LOG.info("Starting in-process zookeeper at port " + port + " and dir " + localDir);
  File localFile = new File(localDir);
  ZooKeeperServer zk = new ZooKeeperServer(localFile, localFile, 2000);
  Factory factory = new Factory(new InetSocketAddress(port), 0);
  factory.startup(zk);
  return factory;
}

代码示例来源:origin: alibaba/mdrill

public ServerCnxnFactory mkInprocessZookeeper(String localdir, int port)
    throws IOException, InterruptedException {
  LOG.info("Starting inprocess zookeeper at port " + port + " and dir "
      + localdir);
  File localfile = new File(localdir);
  ZooKeeperServer zk = new ZooKeeperServer(localfile, localfile, 2000);
  ServerCnxnFactory factory =NIOServerCnxnFactory.createFactory( 
      new InetSocketAddress(port),60);
  factory.startup(zk);
  return factory;
}

代码示例来源:origin: apache/ignite

/** */
private void startServerInstance(File dataDir,
  ServerCnxnFactory factory) throws IOException,
  InterruptedException {
  ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
  factory.startup(zks);
}

代码示例来源:origin: prestodb/presto

public EmbeddedZookeeper(int port)
    throws IOException
{
  this.port = port;
  zkDataDir = Files.createTempDir();
  zkServer = new ZooKeeperServer();
  FileTxnSnapLog ftxn = new FileTxnSnapLog(zkDataDir, zkDataDir);
  zkServer.setTxnLogFactory(ftxn);
  cnxnFactory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(port), 0);
}

代码示例来源:origin: apache/zookeeper

@Before
public void setUp() throws Exception {
  if (tmpDir == null) {
    tmpDir = ClientBase.createTmpDir();
  }
  ClientBase.setupTestEnv();
  zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);
  final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
  serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
  serverFactory.startup(zs);
  Assert.assertTrue("waiting for server up",
        ClientBase.waitForServerUp(HOSTPORT,
                     CONNECTION_TIMEOUT));
}

代码示例来源:origin: apache/pulsar

public void startServer() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.debug("Running ZK server");
  // ServerStats.registerAsConcrete();
  ClientBase.setupTestEnv();
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();
  zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
  serverFactory = new NIOServerCnxnFactory();
  serverFactory.configure(zkaddr, 100);
  serverFactory.startup(zks);
  boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
  LOG.debug("Server up: " + b);
  // create a zookeeper client
  LOG.debug("Instantiate ZK Client");
  zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build();
  // initialize the zk client with values
  zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}

代码示例来源:origin: apache/zookeeper

/**
 * Starting the given server instance
 */
public static void startServerInstance(File dataDir,
    ServerCnxnFactory factory, String hostPort, int serverId) throws IOException,
    InterruptedException {
  final int port = getPort(hostPort);
  LOG.info("STARTING server instance 127.0.0.1:{}", port);
  ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
  zks.setCreateSessionTrackerServerId(serverId);
  factory.startup(zks);
  Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
      "127.0.0.1:" + port, CONNECTION_TIMEOUT, factory.isSecure()));
}

代码示例来源:origin: apache/zookeeper

@Before
public void setup() throws Exception {
  File tmpDir = ClientBase.createTmpDir();
  ClientBase.setupTestEnv();
  zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
  SyncRequestProcessor.setSnapCount(100);
  final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
  servcnxnf = ServerCnxnFactory.createFactory(PORT, -1);
  servcnxnf.startup(zks);
  Assert.assertTrue("waiting for server being up ",
      ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
  zks.sessionTracker = new MySessionTracker();
}

代码示例来源:origin: apache/zookeeper

public void testSnapshot() throws Exception {
  File snapDir = new File(testData, "invalidsnap");
  ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000);
  SyncRequestProcessor.setSnapCount(1000);
  final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);

代码示例来源:origin: apache/zookeeper

private ZooKeeperServer setupSessionTracker() throws IOException {
  File tmpDir = ClientBase.createTmpDir();
  ClientBase.setupTestEnv();
  ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
  zks.setupRequestProcessors();
  firstProcessor = new FirstProcessor(zks, null);
  zks.firstProcessor = firstProcessor;
  // setup session tracker
  zks.createSessionTracker();
  zks.startSessionTracker();
  return zks;
}

代码示例来源:origin: apache/zookeeper

private ServerCnxnFactory startServer(File tmpDir) throws IOException,
    InterruptedException {
  final int CLIENT_PORT = PortAssignment.unique();
  ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
  ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
  f.startup(zks);
  Assert.assertNotNull("JMX initialization failed!", zks.jmxServerBean);
  Assert.assertTrue("waiting for server being up",
      ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
          CONNECTION_TIMEOUT));
  return f;
}

代码示例来源:origin: apache/zookeeper

@Test
public void testGetSecureClientAddress() throws IOException {
  ZooKeeperServer zks = new ZooKeeperServer();
  /**
   * case 1: When secure client is not configured getSecureClientAddress
   * should return empty string
   */
  ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
  String result = serverBean.getSecureClientPort();
  assertEquals("", result);
  /**
   * case 2: When secure client is configured getSecureClientAddress
   * should return configured SecureClientAddress
   */
  ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
  int secureClientPort = 8443;
  InetSocketAddress address = new InetSocketAddress(secureClientPort);
  cnxnFactory.configure(address, 5, true);
  zks.setSecureServerCnxnFactory(cnxnFactory);
  result = serverBean.getSecureClientAddress();
  String ipv4 = "0.0.0.0:" + secureClientPort;
  String ipv6 = "0:0:0:0:0:0:0:0:" + secureClientPort;
  assertTrue(result.equals(ipv4) || result.equals(ipv6));
  // cleanup
  cnxnFactory.shutdown();
}

代码示例来源:origin: apache/zookeeper

File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);

代码示例来源:origin: apache/zookeeper

File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
SyncRequestProcessor.setSnapCount(100);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
zks.startdata();
List<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();

代码示例来源:origin: apache/zookeeper

@Test
public void testDisconnectedAddAuth() throws Exception {
  File tmpDir = ClientBase.createTmpDir();
  ClientBase.setupTestEnv();
  ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
  SyncRequestProcessor.setSnapCount(1000);
  final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
  ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
  f.startup(zks);
  try {
    LOG.info("starting up the zookeeper server .. waiting");
    Assert.assertTrue("waiting for server being up",
        ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
      zk.addAuthInfo("digest", "pat:test".getBytes());
      zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
    } finally {
      zk.close();
    }
  } finally {
    f.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
        ClientBase.waitForServerDown(HOSTPORT,
            ClientBase.CONNECTION_TIMEOUT));
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testGetSecureClientPort() throws IOException {
  ZooKeeperServer zks = new ZooKeeperServer();
  /**
   * case 1: When secure client is not configured GetSecureClientPort
   * should return empty string
   */
  ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
  String result = serverBean.getSecureClientPort();
  assertEquals("", result);
  /**
   * case 2: When secure client is configured GetSecureClientPort should
   * return configured port
   */
  ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
  int secureClientPort = 8443;
  InetSocketAddress address = new InetSocketAddress(secureClientPort);
  cnxnFactory.configure(address, 5, true);
  zks.setSecureServerCnxnFactory(cnxnFactory);
  result = serverBean.getSecureClientPort();
  assertEquals(Integer.toString(secureClientPort), result);
  // cleanup
  cnxnFactory.shutdown();
}

代码示例来源:origin: apache/zookeeper

QuorumBase.shutdown(qb.s5);
String hp = qb.hostPort.split(",")[0];
ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(),
    qb.s1.getTxnFactory().getDataDir(), 3000);
final int PORT = Integer.parseInt(hp.split(":")[1]);

代码示例来源:origin: apache/zookeeper

ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);

代码示例来源:origin: apache/zookeeper

stopServer();
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
startServer();

代码示例来源:origin: apache/zookeeper

@Test
public void testTxnLogElapsedSyncTime() throws IOException {
  File tmpDir = ClientBase.createEmptyTestDir();
  FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"),
      new File(tmpDir, "data_txnlog"));
  ZooKeeperServer zks = new ZooKeeperServer();
  zks.setTxnLogFactory(fileTxnSnapLog);
  ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
  long elapsedTime = serverBean.getTxnLogElapsedSyncTime();
  assertEquals(-1, elapsedTime);
  TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData);
  Record txn = new SetDataTxn("/foo", new byte[0], 1);
  Request req = new Request(0, 0, 0, hdr, txn, 0);
  try {
    zks.getTxnLogFactory().append(req);
    zks.getTxnLogFactory().commit();
    elapsedTime = serverBean.getTxnLogElapsedSyncTime();
    assertNotEquals(-1, elapsedTime);
    assertEquals(elapsedTime, serverBean.getTxnLogElapsedSyncTime());
  } finally {
    fileTxnSnapLog.close();
  }
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com