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


Java AsyncCallback.DataCallback方法代码示例

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


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

示例1: testNotCloseZkWhenPending

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
@Test
public void testNotCloseZkWhenPending() throws Exception {
  ZooKeeper mockedZK = mock(ZooKeeper.class);
  Exchanger<AsyncCallback.DataCallback> exchanger = new Exchanger<>();
  doAnswer(i -> {
    exchanger.exchange(i.getArgument(2));
    return null;
  }).when(mockedZK).getData(anyString(), anyBoolean(),
    any(AsyncCallback.DataCallback.class), any());
  doAnswer(i -> null).when(mockedZK).close();
  when(mockedZK.getState()).thenReturn(ZooKeeper.States.CONNECTED);
  RO_ZK.zookeeper = mockedZK;
  CompletableFuture<byte[]> future = RO_ZK.get(PATH);
  AsyncCallback.DataCallback callback = exchanger.exchange(null);
  // 2 * keep alive time to ensure that we will not close the zk when there are pending requests
  Thread.sleep(6000);
  assertNotNull(RO_ZK.zookeeper);
  verify(mockedZK, never()).close();
  callback.processResult(Code.OK.intValue(), PATH, null, DATA, null);
  assertArrayEquals(DATA, future.get());
  // now we will close the idle connection.
  waitForIdleConnectionClosed();
  verify(mockedZK, times(1)).close();
}
 
开发者ID:apache,项目名称:hbase,代码行数:25,代码来源:TestReadOnlyZKClient.java

示例2: performBackgroundOperation

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<Void> operationAndData) throws Exception
{
    try
    {
        final TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat)
            {
                watching.commitWatcher(rc, false);
                trace.commit();
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG, rc, path, null, ctx, stat, data, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        if ( watching.isWatched() )
        {
            client.getZooKeeper().getConfig(true, callback, backgrounding.getContext());
        }
        else
        {
            client.getZooKeeper().getConfig(watching.getWatcher(ZooDefs.CONFIG_NODE), callback, backgrounding.getContext());
        }
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, watching);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:32,代码来源:GetConfigBuilderImpl.java

示例3: performBackgroundOperation

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<Void> data) throws Exception
{
    try
    {
        final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background");
        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, byte[] bytes, Stat stat)
            {
                trace.commit();
                if ( (responseStat != null) && (stat != null) )
                {
                    DataTree.copyStat(stat, responseStat);
                }
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, bytes, null, null, null, null);
                client.processBackgroundOperation(data, event);
            }
        };
        client.getZooKeeper().reconfig(joining, leaving, newMembers, fromConfig, callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:28,代码来源:ReconfigBuilderImpl.java

示例4: testSession

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
/**
 * This test verifies that when the session id is reused, and the original
 * client is disconnected, but not session closed, that the server
 * will remove ephemeral nodes created by the original session.
 */
@Test
public void testSession()
    throws IOException, InterruptedException, KeeperException
{
    DisconnectableZooKeeper zk = createClient();
    zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.EPHEMERAL);
    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
            + " was destroyed!");

    // disconnect the client by killing the socket, not sending the
    // session disconnect to the server as usual. This allows the test
    // to verify disconnect handling
    zk.disconnect();

    Stat stat = new Stat();
    startSignal = new CountDownLatch(1);
    zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT,
            new MyWatcher("testSession"), zk.getSessionId(),
            zk.getSessionPasswd());
    startSignal.await();

    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
             + " was created!");
    zk.getData("/e", false, stat);
    LOG.info("After get data /e");
    zk.close();

    zk = createClient();
    Assert.assertEquals(null, zk.exists("/e", false));
    LOG.info("before close zk with session id 0x"
            + Long.toHexString(zk.getSessionId()) + "!");
    zk.close();
    try {
        zk.getData("/e", false, stat);
        Assert.fail("Should have received a SessionExpiredException");
    } catch(KeeperException.SessionExpiredException e) {}
    
    AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() {
        String status = "not done";
        public void processResult(int rc, String p, Object c, byte[] b, Stat s) {
            synchronized(this) { status = KeeperException.Code.get(rc).toString(); this.notify(); }
        }
       public String toString() { return status; }
    };
    zk.getData("/e", false, cb, null);
    synchronized(cb) {
        if (cb.toString().equals("not done")) {
            cb.wait(1000);
        }
    }
    Assert.assertEquals(KeeperException.Code.SESSIONEXPIRED.toString(), cb.toString());        
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:59,代码来源:SessionTest.java

示例5: testSession

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
/**
 * This test verifies that when the session id is reused, and the original
 * client is disconnected, but not session closed, that the server
 * will remove ephemeral nodes created by the original session.
 */
@Test
public void testSession()
    throws IOException, InterruptedException, KeeperException
{
    DisconnectableZooKeeper zk = createClient();
    zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.EPHEMERAL);
    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
            + " was destroyed!");

    // disconnect the client by killing the socket, not sending the
    // session disconnect to the server as usual. This allows the test
    // to verify disconnect handling
    zk.disconnect();

    Stat stat = new Stat();
    startSignal = new CountDownLatch(1);
    zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT,
            new MyWatcher("testSession"), zk.getSessionId(),
            zk.getSessionPasswd());
    startSignal.await();

    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
             + " was created!");
    zk.getData("/e", false, stat);
    LOG.info("After get data /e");
    zk.close();

    zk = createClient();
    Assert.assertEquals(null, zk.exists("/e", false));
    LOG.info("before close zk with session id 0x"
            + Long.toHexString(zk.getSessionId()) + "!");
    zk.close();
    try {
        zk.getData("/e", false, stat);
        Assert.fail("Should have received a SessionExpiredException");
    } catch(KeeperException.SessionExpiredException e) {}

    AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() {
        String status = "not done";
        public void processResult(int rc, String p, Object c, byte[] b, Stat s) {
            synchronized(this) { status = KeeperException.Code.get(rc).toString(); this.notify(); }
        }
       public String toString() { return status; }
    };
    zk.getData("/e", false, cb, null);
    synchronized(cb) {
        if (cb.toString().equals("not done")) {
            cb.wait(1000);
        }
    }
    Assert.assertEquals(KeeperException.Code.SESSIONEXPIRED.toString(), cb.toString());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:59,代码来源:SessionTest.java

示例6: testSession

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
/**
 * This test verifies that when the session id is reused, and the original
 * client is disconnected, but not session closed, that the server
 * will remove ephemeral nodes created by the original session.
 */
@Test
public void testSession()
    throws IOException, InterruptedException, KeeperException
{
    DisconnectableZooKeeper zk = createClient();
    zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.EPHEMERAL);
    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
            + " was destroyed!");

    // disconnect the client by killing the socket, not sending the
    // session disconnect to the server as usual. This allows the test
    // to verify disconnect handling
    zk.disconnect();

    Stat stat = new Stat();
    startSignal = new CountDownLatch(1);
    zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this,
                           zk.getSessionId(),
                           zk.getSessionPasswd());
    startSignal.await();

    LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
             + " was created!");
    zk.getData("/e", false, stat);
    LOG.info("After get data /e");
    zk.close();

    zk = createClient();
    assertEquals(null, zk.exists("/e", false));
    LOG.info("before close zk with session id 0x"
            + Long.toHexString(zk.getSessionId()) + "!");
    zk.close();
    try {
        zk.getData("/e", false, stat);
        Assert.fail("Should have received a SessionExpiredException");
    } catch(KeeperException.SessionExpiredException e) {}
    
    AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() {
        String status = "not done";
        public void processResult(int rc, String p, Object c, byte[] b, Stat s) {
            synchronized(this) { status = KeeperException.Code.get(rc).toString(); this.notify(); }
        }
       public String toString() { return status; }
    };
    zk.getData("/e", false, cb, null);
    synchronized(cb) {
        if (cb.toString().equals("not done")) {
            cb.wait(1000);
        }
    }
    Assert.assertEquals(KeeperException.Code.SESSIONEXPIRED.toString(), cb.toString());        
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:59,代码来源:SessionTest.java

示例7: getData

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
@Override
public void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) {
    delegate.getData(path, watcher, cb, ctx);
}
 
开发者ID:NGDATA,项目名称:hbase-indexer,代码行数:5,代码来源:ZooKeeperImpl.java

示例8: getData

import org.apache.zookeeper.AsyncCallback; //导入方法依赖的package包/类
void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx); 
开发者ID:NGDATA,项目名称:hbase-indexer,代码行数:2,代码来源:ZooKeeperItf.java


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