當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。