當前位置: 首頁>>代碼示例>>Java>>正文


Java Stat類代碼示例

本文整理匯總了Java中org.apache.zookeeper.data.Stat的典型用法代碼示例。如果您正苦於以下問題:Java Stat類的具體用法?Java Stat怎麽用?Java Stat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Stat類屬於org.apache.zookeeper.data包,在下文中一共展示了Stat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newStat

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
/**
 * Create a new Stat, fill in dummy values trying to catch Assert.failure
 * to copy in client or server code.
 *
 * @return a new stat with dummy values
 */
private Stat newStat() {
    Stat stat = new Stat();

    stat.setAversion(100);
    stat.setCtime(100);
    stat.setCversion(100);
    stat.setCzxid(100);
    stat.setDataLength(100);
    stat.setEphemeralOwner(100);
    stat.setMtime(100);
    stat.setMzxid(100);
    stat.setNumChildren(100);
    stat.setPzxid(100);
    stat.setVersion(100);

    return stat;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:24,代碼來源:StatTest.java

示例2: connect

import org.apache.zookeeper.data.Stat; //導入依賴的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: processResult

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
public void processResult(int rc, String path,
        Object ctx, byte[] data, Stat stat) {
    if (rc == KeeperException.Code.NONODE.intValue()) {
        // we can just ignore because the child watcher takes care of this
        return;
    }
    if (rc != KeeperException.Code.OK.intValue()) {
        zk.getData(myNode, (Watcher)ctx, this, ctx);
    }
    int currVer = stat.getVersion();
    if (currVer != lastVer) {
        String parts[] = new String(data).split(" ", 2);
        myInstance.configure(parts[1]);
        lastVer = currVer;
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:17,代碼來源:InstanceContainer.java

示例4: testCreateEphemeralZNode

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
@Test
public void testCreateEphemeralZNode() 
throws KeeperException, InterruptedException, IOException {
    ZSession session = createSession("30");
    
    WebResource wr = znodesr.path("/")
        .queryParam("op", "create")
        .queryParam("name", "ephemeral-test")
        .queryParam("ephemeral", "true")
        .queryParam("session", session.id)
        .queryParam("null", "true");
    
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    ClientResponse cr = b.post(ClientResponse.class);
    Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
    
    Stat stat = new Stat();
    zk.getData("/ephemeral-test", false, stat);
    
    ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH, session.id);
    Assert.assertEquals(stat.getEphemeralOwner(), sessionZK.getSessionId());
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:23,代碼來源:SessionTest.java

示例5: testRoundTrip

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
public void testRoundTrip() throws IOException {
    MultiResponse response = new MultiResponse();

    response.add(new OpResult.CheckResult());
    response.add(new OpResult.CreateResult("foo-bar"));
    response.add(new OpResult.DeleteResult());

    Stat s = new Stat();
    s.setCzxid(546);
    response.add(new OpResult.SetDataResult(s));

    MultiResponse decodedResponse = codeDecode(response);

    Assert.assertEquals(response, decodedResponse);
    Assert.assertEquals(response.hashCode(), decodedResponse.hashCode());
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:MultiResponseTest.java

示例6: getACL

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
/**
 * The asynchronous version of getACL.
 *
 * @see #getACL(String, Stat)
 */
public void getACL(final String path, Stat stat, ACLCallback cb,
        Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:22,代碼來源:ZooKeeper.java

示例7: main

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
public static void main(String[] args) {
    String connStr = "127.0.0.1:2181";
    try {
        ZooKeeper zookeeper = new ZooKeeper(connStr, 100000,
            new Watcher() {
                public void process(WatchedEvent event) {
                    logger.debug("監控被觸發的事件");
                }
            });
        Stat stat = new Stat();
        byte[] result = zookeeper.getData("/saf_service/com.ipd.testjsf.HelloBaontService/providers", false, stat);
        zookeeper.setData("/saf_service/com.ipd.testjsf.HelloBaontService/providers", result, stat.getVersion());
        System.out.println(result);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:19,代碼來源:ZkHelper.java

示例8: createAndWatch

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
/**
 * Creates the specified node with the specified data and watches it.
 *
 * <p>Throws an exception if the node already exists.
 *
 * <p>The node created is persistent and open access.
 *
 * <p>Returns the version number of the created node if successful.
 *
 * @param zkw zk reference
 * @param znode path of node to create
 * @param data data of node to create
 * @return version of node created
 * @throws KeeperException if unexpected zookeeper exception
 * @throws KeeperException.NodeExistsException if node already exists
 */
public static int createAndWatch(ZooKeeperWatcher zkw,
    String znode, byte [] data)
throws KeeperException, KeeperException.NodeExistsException {
  try {
    zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
        CreateMode.PERSISTENT);
    Stat stat = zkw.getRecoverableZooKeeper().exists(znode, zkw);
    if (stat == null){
      // Likely a race condition. Someone deleted the znode.
      throw KeeperException.create(KeeperException.Code.SYSTEMERROR,
          "ZK.exists returned null (i.e.: znode does not exist) for znode=" + znode);
    }
   return stat.getVersion();
  } catch (InterruptedException e) {
    zkw.interruptedException(e);
    return -1;
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:35,代碼來源:ZKUtil.java

示例9: testRootWatchTriggered

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
@Test(timeout = 60000)
public void testRootWatchTriggered() throws Exception {
    class MyWatcher implements Watcher{
        boolean fired=false;
        public void process(WatchedEvent event) {
            if(event.getPath().equals("/"))
                fired=true;
        }
    }
    MyWatcher watcher=new MyWatcher();
    // set a watch on the root node
    dt.getChildren("/", new Stat(), watcher);
    // add a new node, should trigger a watch
    dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1);
    Assert.assertFalse("Root node watch not triggered",!watcher.fired);
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:DataTreeTest.java

示例10: deleteNode

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
public boolean deleteNode(String nodePath) {
    if (connected) {
        try {
            Stat s = zooKeeper.exists(nodePath, false);
            if (s != null) {
                List<String> children = zooKeeper.getChildren(nodePath,
                        false);
                for (String child : children) {
                    String node = nodePath + "/" + child;
                    deleteNode(node);
                }
                zooKeeper.delete(nodePath, -1);
            }
            return true;
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occurred deleting node: " + nodePath, e);
        }
    }
    return false;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:22,代碼來源:ZooInspectorManagerImpl.java

示例11: testCreateNodeResultRetryNoNode

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
/**
 * verify that if create znode results in nodeexists and that znode is deleted
 * before exists() watch is set then the return of the exists() method results
 * in attempt to re-create the znode and become active
 */
@Test
public void testCreateNodeResultRetryNoNode() {
  elector.joinElection(data);

  elector.processResult(Code.CONNECTIONLOSS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  elector.processResult(Code.CONNECTIONLOSS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  elector.processResult(Code.NODEEXISTS.intValue(), ZK_LOCK_NAME, mockZK,
      ZK_LOCK_NAME);
  verifyExistCall(1);

  elector.processResult(Code.NONODE.intValue(), ZK_LOCK_NAME, mockZK,
      (Stat) null);
  Mockito.verify(mockApp, Mockito.times(1)).enterNeutralMode();
  Mockito.verify(mockZK, Mockito.times(4)).create(ZK_LOCK_NAME, data,
      Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, elector, mockZK);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:24,代碼來源:TestActiveStandbyElector.java

示例12: connect

import org.apache.zookeeper.data.Stat; //導入依賴的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

示例13: testDefaultConnection

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
@Test
public void testDefaultConnection() throws Exception {
  // Default root from sabot-module.conf
  assertNull(zooKeeperServer.getZKClient().exists("/dremio/test-path", false));

  final SabotConfig config = DEFAULT_SABOT_CONFIG
      .withValue(ZK_ROOT, ConfigValueFactory.fromAnyRef("dremio/test-path"))
      .withValue(CLUSTER_ID, ConfigValueFactory.fromAnyRef("test-cluster-id"));

  try(ZKClusterClient client = new ZKClusterClient(config, new Provider<Integer>() {
    @Override
    public Integer get() {
      return zooKeeperServer.getPort();
    }
  })) {
    client.start();
    ZKServiceSet serviceSet = client.newServiceSet("coordinator");
    serviceSet.register(NodeEndpoint.newBuilder().setAddress("foo").build());


    Stat stat = zooKeeperServer.getZKClient().exists("/dremio/test-path/test-cluster-id/coordinator", false);
    assertNotNull(stat);
    assertEquals(1, stat.getNumChildren());
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:26,代碼來源:TestZKClusterClient.java

示例14: getStatus

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
/**
 * Gets the status of a node in ZooKeeper
 *
 * @param p_path
 *     the node path
 * @param p_watcher
 *     the watcher
 * @return true if the node exists, fals eotherwise
 * @throws ZooKeeperException
 *     if ZooKeeper could not accessed
 */
public Stat getStatus(final String p_path, final Watcher p_watcher) throws ZooKeeperException {
    Stat ret;

    assert p_path != null;

    try {
        if (m_zookeeper == null) {
            connect();
        }

        if (!p_path.isEmpty()) {
            ret = m_zookeeper.exists(m_path + '/' + p_path, p_watcher);
        } else {
            ret = m_zookeeper.exists(m_path, p_watcher);
        }
    } catch (final KeeperException | InterruptedException e) {
        throw new ZooKeeperException("Could not access ZooKeeper", e);
    }

    return ret;
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:33,代碼來源:ZooKeeperHandler.java

示例15: testCreateEphemeralZNode

import org.apache.zookeeper.data.Stat; //導入依賴的package包/類
@Test
public void testCreateEphemeralZNode() 
throws KeeperException, InterruptedException, IOException {
    ZSession session = createSession("30");
    
    WebResource wr = znodesr.path("/")
        .queryParam("op", "create")
        .queryParam("name", "ephemeral-test")
        .queryParam("ephemeral", "true")
        .queryParam("session", session.id)
        .queryParam("null", "true");
    
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    ClientResponse cr = b.post(ClientResponse.class);
    assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
    
    Stat stat = new Stat();
    zk.getData("/ephemeral-test", false, stat);
    
    ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH, session.id);
    assertEquals(stat.getEphemeralOwner(), sessionZK.getSessionId());
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:23,代碼來源:SessionTest.java


注:本文中的org.apache.zookeeper.data.Stat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。