当前位置: 首页>>代码示例>>Java>>正文


Java NIOServerCnxn类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.NIOServerCnxn的典型用法代码示例。如果您正苦于以下问题:Java NIOServerCnxn类的具体用法?Java NIOServerCnxn怎么用?Java NIOServerCnxn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NIOServerCnxn类属于org.apache.zookeeper.server包,在下文中一共展示了NIOServerCnxn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runZookeeper

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
/**
 * @param args
 */

private void runZookeeper() throws IOException{
	// create a ZooKeeper server(dataDir, dataLogDir, port)
	LOG.info("Starting ZK server");
	//ServerStats.registerAsConcrete();
	//ClientBase.setupTestEnv();
	ZkTmpDir = File.createTempFile("zookeeper", "test");
       ZkTmpDir.delete();
       ZkTmpDir.mkdir();
	    
	try {
		zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
		serverFactory =  new NIOServerCnxn.Factory(new InetSocketAddress(ZooKeeperDefaultPort));
		serverFactory.startup(zks);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		LOG.fatal("Exception while instantiating ZooKeeper", e);
	} 

       boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
       LOG.debug("ZooKeeper server up: " + b);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:26,代码来源:LocalBookKeeper.java

示例2: createAndStartZooKeeper

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public static void createAndStartZooKeeper() 
  throws IOException, ConfigException, InterruptedException {
  ServerConfig zkConf = createZooKeeperConf();

  zooKeeper = new ZooKeeperServer();
  FileTxnSnapLog ftxn = new 
    FileTxnSnapLog(new File(zkConf.getDataLogDir()),
                   new File(zkConf.getDataDir()));
  zooKeeper.setTxnLogFactory(ftxn);
  zooKeeper.setTickTime(zkConf.getTickTime());
  zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
  zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());

  cnxnFactory =
    new NIOServerCnxn.Factory(zkConf.getClientPortAddress(),
                              zkConf.getMaxClientCnxns());
  cnxnFactory.startup(zooKeeper);

}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:20,代码来源:MiniAvatarCluster.java

示例3: QuorumPeer

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        NIOServerCnxn.Factory cnxnFactory, 
        QuorumVerifier quorumConfig) throws IOException {
    this();
    this.cnxnFactory = cnxnFactory;
    this.quorumPeers = quorumPeers;
    this.electionType = electionType;
    this.myid = myid;
    this.tickTime = tickTime;
    this.initLimit = initLimit;
    this.syncLimit = syncLimit;        
    this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
    this.zkDb = new ZKDatabase(this.logFactory);
    if(quorumConfig == null)
        this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
    else this.quorumConfig = quorumConfig;
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:20,代码来源:QuorumPeer.java

示例4: testDisconnectedAddAuth

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
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]);
    NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));
    f.startup(zks);
    LOG.info("starting up the zookeeper server .. waiting");
    assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        zk.addAuthInfo("digest", "pat:test".getBytes());
        zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
    } finally {
        zk.close();
    }

    f.shutdown();

    assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:27,代码来源:ACLTest.java

示例5: setUp

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    LOG.info("STARTING " + getName());

    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT));
    serverFactory.startup(zs);

    assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:20,代码来源:SessionTest.java

示例6: createNewServerInstance

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public static NIOServerCnxn.Factory createNewServerInstance(File dataDir,
        NIOServerCnxn.Factory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT),maxCnxns);
    }
    factory.startup(zks);
    assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:17,代码来源:ClientBase.java

示例7: shutdownServerInstance

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
static void shutdownServerInstance(NIOServerCnxn.Factory factory,
        String hostPort)
{    	
	if (factory != null) {
	    ZKDatabase zkDb = factory.getZooKeeperServer().getZKDatabase();
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
   	 	}
        final int PORT = getPort(hostPort);

        assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:19,代码来源:ClientBase.java

示例8: EmbeddedZookeeper

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
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 = new NIOServerCnxn.Factory(new InetSocketAddress(this.port), 0);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:13,代码来源:EmbeddedZookeeper.java

示例9: EmbeddedZookeeper

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public EmbeddedZookeeper(final int port)
                throws IOException
{
    this.port = port;
    zkDataDir = Files.createTempDir();
    zkServer = new ZooKeeperServer();

    final FileTxnSnapLog ftxn = new FileTxnSnapLog(zkDataDir, zkDataDir);
    zkServer.setTxnLogFactory(ftxn);

    cnxnFactory = new NIOServerCnxn.Factory(new InetSocketAddress(this.port), 0);
}
 
开发者ID:groupon,项目名称:jesos,代码行数:13,代码来源:EmbeddedZookeeper.java

示例10: getMaxClientCnxnsPerHost

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public int getMaxClientCnxnsPerHost() {
    NIOServerCnxn.Factory fac = peer.getCnxnFactory();
    if (fac == null) {
        return -1;
    }
    return fac.getMaxClientCnxns();
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:8,代码来源:LocalPeerBean.java

示例11: MockQuorumPeer

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
public MockQuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
        File logDir, int clientPort, int electionAlg,
        long myid, int tickTime, int initLimit, int syncLimit)
throws IOException
{
    super(quorumPeers, snapDir, logDir, electionAlg,
            myid,tickTime, initLimit,syncLimit,
            new NIOServerCnxn.Factory(new InetSocketAddress(clientPort)),
            new QuorumMaj(countParticipants(quorumPeers)));
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:11,代码来源:LENonTerminateTest.java

示例12: testSnapshot

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
/**
 * test the snapshot
 * @throws Exception an exception could be expected
 */
@Test
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]);
    NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));
    f.startup(zks);
    LOG.info("starting up the zookeeper server .. waiting");
    assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
    try {
        // we know this from the data files
        // this node is the last node in the snapshot

        assertTrue(zk.exists("/9/9/8", false) != null);
    } finally {
        zk.close();
    }
    f.shutdown();
    assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:32,代码来源:InvalidSnapshotTest.java

示例13: testUpgrade

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
/**
 * test the upgrade
 * @throws Exception
 */
public void testUpgrade() throws Exception {
    File upgradeDir = new File(testData, "upgrade");
    UpgradeMain upgrade = new UpgradeMain(upgradeDir, upgradeDir);
    upgrade.runUpgrade();
    ZooKeeperServer zks = new ZooKeeperServer(upgradeDir, upgradeDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));
    f.startup(zks);
    LOG.info("starting up the zookeeper server .. waiting");
    assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    Stat stat = zk.exists("/", false);
    List<String> children = zk.getChildren("/", false);
    Collections.sort(children);
    for (int i = 0; i < 10; i++) {
        assertTrue("data tree sanity check",
                ("test-" + i).equals(children.get(i)));
    }
    //try creating one node
    zk.create("/upgrade", "upgrade".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    // check if its there
    if (zk.exists("/upgrade", false) == null) {
        assertTrue(false);
    }

    zk.close();

    // bring down the server
    f.shutdown();
    assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:43,代码来源:UpgradeTest.java

示例14: testFail

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
/** bring up 5 quorum peers and then shut them down
 * and then bring one of the nodes as server
 *
 * @throws Exception might be thrown here
 */
@Test
public void testFail() throws Exception {
    QuorumBase qb = new QuorumBase();
    qb.setUp();

    System.out.println("Comment: the servers are at " + qb.hostPort);
    ZooKeeper zk = qb.createClient();
    zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
    qb.shutdown(qb.s1);
    qb.shutdown(qb.s2);
    qb.shutdown(qb.s3);
    qb.shutdown(qb.s4);
    qb.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]);
    NIOServerCnxn.Factory factory = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));

    factory.startup(zks);
    System.out.println("Comment: starting factory");
    assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                       QuorumTest.CONNECTION_TIMEOUT));
    factory.shutdown();
    assertTrue("waiting for server down",
               ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                            QuorumTest.CONNECTION_TIMEOUT));
    System.out.println("Comment: shutting down standalone");
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:38,代码来源:RepeatStartupTest.java

示例15: testPurge

import org.apache.zookeeper.server.NIOServerCnxn; //导入依赖的package包/类
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));
    f.startup(zks);
    assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:40,代码来源:PurgeTxnTest.java


注:本文中的org.apache.zookeeper.server.NIOServerCnxn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。