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


Java ZooDefs类代码示例

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


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

示例1: testCreate

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
@Test
public void testCreate()
        throws IOException, KeeperException, InterruptedException {
    Stat stat = new Stat();
    zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
    Assert.assertEquals(0, stat.getEphemeralOwner());

    final AtomicLong fakeElapsed = new AtomicLong(0);
    ContainerManager containerManager = newContainerManager(fakeElapsed);
    containerManager.checkContainers();
    Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));

    fakeElapsed.set(1000);
    containerManager.checkContainers();
    Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:CreateTTLTest.java

示例2: connect

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private void connect(TxZookeeperConfig config) {
    try {
        zooKeeper = new ZooKeeper(config.getHost(), config.getSessionTimeOut(), watchedEvent -> {
            if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
                // 放开闸门, wait在connect方法上的线程将被唤醒
                COUNT_DOWN_LATCH.countDown();
            }
        });
        COUNT_DOWN_LATCH.await();
        Stat stat = zooKeeper.exists(rootPath, false);
        if (stat == null) {
            zooKeeper.create(rootPath, rootPath.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } catch (Exception e) {
        throw new TransactionIoException(e);
    }


}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:20,代码来源:ZookeeperTransactionRecoverRepository.java

示例3: updateRetry

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * 更改恢复次数
 *
 * @param id              事务id
 * @param retry           恢复次数
 * @param applicationName 应用名称
 * @return true 成功
 */
@Override
public Boolean updateRetry(String id, Integer retry, String applicationName) {
    if (StringUtils.isBlank(id) || StringUtils.isBlank(applicationName) || Objects.isNull(retry)) {
        return Boolean.FALSE;
    }
    final String rootPath = RepositoryPathUtils.buildZookeeperPath(applicationName);
    final String path = buildRootPath(rootPath, id);
    try {
        byte[] content = zooKeeper.getData(path,
                false, new Stat());
        final TransactionRecoverAdapter adapter = objectSerializer.deSerialize(content, TransactionRecoverAdapter.class);
        adapter.setLastTime(DateUtils.getDateYYYY());
        adapter.setRetriedCount(retry);
        zooKeeper.create(path,
                objectSerializer.serialize(adapter),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return Boolean.TRUE;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return Boolean.FALSE;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:32,代码来源:ZookeeperRecoverTransactionServiceImpl.java

示例4: testNodeChildrenChanged

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
@Test
public void testNodeChildrenChanged() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test-children-changed";

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.getChildren(path, watcher);
    qu.shutdown(1);
    zk2.create(path + "/children-1", new byte[2],
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeChildrenChanged);

    qu.shutdownAll();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:24,代码来源:WatchEventWhenAutoReset.java

示例5: getItemPerms

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private int getItemPerms(TableItem item) {
    int perms = 0;
    Button allCheckBox = getItemPermCheckBox(item, ZooDefs.Perms.ALL);
    if (allCheckBox.getSelection()) {
        perms = ZooDefs.Perms.ALL;
    }
    else {
        for (int perm : PERMS) {
            Button permCheckBox = getItemPermCheckBox(item, perm);
            if (permCheckBox.getSelection()) {
                perms |= perm;
            }
        }
    }

    return perms;
}
 
开发者ID:baloise,项目名称:eZooKeeper,代码行数:18,代码来源:ZnodeAclComposite.java

示例6: ZkDistributeLock

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * @param zkServers
 * @param lockName
 * @param sessionTimeout
 */
public ZkDistributeLock(String zkServers, String lockName, int sessionTimeout) {
    if (lockName.contains(LOCK_KEY_SUFFIX)) {
        throw new LockException("lockName 不能包含[" + LOCK_KEY_SUFFIX + "]");
    }
    this.lockName = lockName;
    this.sessionTimeout = sessionTimeout;
    try {
        zk = new ZooKeeper(zkServers, sessionTimeout, this);
        Stat stat = zk.exists(ROOT_PATH, false);
        if (stat == null) {
            // 创建根节点
            zk.create(ROOT_PATH, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } catch (Exception e) {
        throw new LockException(e);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:23,代码来源:ZkDistributeLock.java

示例7: sendSaslPacket

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private void sendSaslPacket(byte[] saslToken, ClientCnxn cnxn)
  throws SaslException{
    if (LOG.isDebugEnabled()) {
        LOG.debug("ClientCnxn:sendSaslPacket:length="+saslToken.length);
    }

    GetSASLRequest request = new GetSASLRequest();
    request.setToken(saslToken);
    SetSASLResponse response = new SetSASLResponse();
    ServerSaslResponseCallback cb = new ServerSaslResponseCallback();

    try {
        cnxn.sendPacket(request,response,cb, ZooDefs.OpCode.sasl);
    } catch (IOException e) {
        throw new SaslException("Failed to send SASL packet to server.",
            e);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:ZooKeeperSaslClient.java

示例8: addRequestToSyncProcessor

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private void addRequestToSyncProcessor() {
    long zxid = ZxidUtils.makeZxid(3, 7);
    TxnHeader hdr = new TxnHeader(1, 1, zxid, 1,
            ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo" + zxid, new byte[0], 1);
    byte[] buf;
    try {
        buf = Util.marshallTxnEntry(hdr, txn);
    } catch (IOException e) {
        LOG.error("IOException while adding request to SyncRequestProcessor", e);
        Assert.fail("IOException while adding request to SyncRequestProcessor!");
        return;
    }
    NettyServerCnxnFactory factory = new NettyServerCnxnFactory();
    final MockNettyServerCnxn nettyCnxn = new MockNettyServerCnxn(null,
            this, factory);
    Request req = new Request(nettyCnxn, 1, 1, ZooDefs.OpCode.setData,
            ByteBuffer.wrap(buf), null);
    req.hdr = hdr;
    req.txn = txn;
    syncProcessor.processRequest(req);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:ZooKeeperServerMainTest.java

示例9: testNodeCreated

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
@Test
public void testNodeCreated() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test1-created";

    zk1.exists(path, watcher);
    qu.shutdown(1);
    zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeCreated);

    qu.shutdownAll();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:22,代码来源:WatchEventWhenAutoReset.java

示例10: resetAcls

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private static void resetAcls(final ZooKeeperWatcher zkw, final String znode,
    final boolean eraseAcls) throws Exception {
  List<String> children = ZKUtil.listChildrenNoWatch(zkw, znode);
  if (children != null) {
    for (String child: children) {
      resetAcls(zkw, ZKUtil.joinZNode(znode, child), eraseAcls);
    }
  }

  ZooKeeper zk = zkw.getRecoverableZooKeeper().getZooKeeper();
  if (eraseAcls) {
    LOG.info(" - erase ACLs for " + znode);
    zk.setACL(znode, ZooDefs.Ids.OPEN_ACL_UNSAFE, -1);
  } else {
    LOG.info(" - set ACLs for " + znode);
    zk.setACL(znode, ZKUtil.createACL(zkw, znode, true), -1);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:ZkAclReset.java

示例11: testSessionEstablishment

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * Tests a situation when client firstly connects to a read-only server and
 * then connects to a majority server. Transition should be transparent for
 * the user.
 */
@Test(timeout = 90000)
public void testSessionEstablishment() throws Exception {
    qu.shutdown(2);

    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
            watcher, true);
    watcher.waitForConnected(CONNECTION_TIMEOUT);
    Assert.assertSame("should be in r/o mode", States.CONNECTEDREADONLY, zk
            .getState());
    long fakeId = zk.getSessionId();

    watcher.reset();
    qu.start(2);
    Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
            "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
    watcher.waitForConnected(CONNECTION_TIMEOUT);
    zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    Assert.assertFalse("fake session and real session have same id", zk
            .getSessionId() == fakeId);

    zk.close();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:30,代码来源:ReadOnlyModeTest.java

示例12: updateParticipant

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * 更新 List<Participant>  只更新这一个字段数据
 *
 * @param tccTransaction 实体对象
 */
@Override
public int updateParticipant(TccTransaction tccTransaction) {

    final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, tccTransaction.getTransId());
    try {
        byte[] content = zooKeeper.getData(path,
                false, new Stat());
        final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class);

        adapter.setContents(objectSerializer.serialize(tccTransaction.getParticipants()));
        zooKeeper.create(path,
                objectSerializer.serialize(adapter),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return 1;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }

}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:26,代码来源:ZookeeperCoordinatorRepository.java

示例13: updateStatus

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * 更新补偿数据状态
 *
 * @param id     事务id
 * @param status 状态
 * @return rows 1 成功 0 失败
 */
@Override
public int updateStatus(String id, Integer status) {
    final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix,id);
    try {
        byte[] content = zooKeeper.getData(path,
                false, new Stat());
        final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class);

        adapter.setStatus(status);
        zooKeeper.create(path,
                objectSerializer.serialize(adapter),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return 1;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }

}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:27,代码来源:ZookeeperCoordinatorRepository.java

示例14: connect

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
private void connect(TccZookeeperConfig config) {
    try {
        zooKeeper = new ZooKeeper(config.getHost(), config.getSessionTimeOut(), watchedEvent -> {
            if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
                // 放开闸门, wait在connect方法上的线程将被唤醒
                LATCH.countDown();
            }
        });
        LATCH.await();
        Stat stat = zooKeeper.exists(rootPathPrefix, false);
        if (stat == null) {
            zooKeeper.create(rootPathPrefix, rootPathPrefix.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } catch (Exception e) {
        throw new TccRuntimeException(e);
    }


}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:20,代码来源:ZookeeperCoordinatorRepository.java

示例15: updateRetry

import org.apache.zookeeper.ZooDefs; //导入依赖的package包/类
/**
 * 更改恢复次数
 *
 * @param id              事务id
 * @param retry           恢复次数
 * @param applicationName 应用名称
 * @return true 成功
 */
@Override
public Boolean updateRetry(String id, Integer retry, String applicationName) {
    if (StringUtils.isBlank(id) || StringUtils.isBlank(applicationName) || Objects.isNull(retry)) {
        return Boolean.FALSE;
    }
    final String rootPathPrefix = RepositoryPathUtils.buildZookeeperPathPrefix(applicationName);
    final String path = RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id);
    try {
        byte[] content = zooKeeper.getData(path,
                false, new Stat());
        final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(content, CoordinatorRepositoryAdapter.class);
        adapter.setLastTime(DateUtils.getDateYYYY());
        adapter.setRetriedCount(retry);
        zooKeeper.create(path,
                objectSerializer.serialize(adapter),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return Boolean.TRUE;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return Boolean.FALSE;
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:32,代码来源:ZookeeperCompensationServiceImpl.java


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