Java Code Examples for org.apache.zookeeper.AsyncCallback#DataCallback
The following examples show how to use
org.apache.zookeeper.AsyncCallback#DataCallback .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseClientTest.java From opensharding-spi-impl with Apache License 2.0 | 6 votes |
protected final void asyncGet(final IZookeeperClient client) throws KeeperException, InterruptedException { final CountDownLatch ready = new CountDownLatch(1); String key = "a/b"; String value = "bbb11"; client.createAllNeedPath(key, value, CreateMode.PERSISTENT); AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() { @Override public void processResult(final int rc, final String path, final Object ctx, final byte[] data, final Stat stat) { assertThat(new String(data), is(ctx)); ready.countDown(); } }; client.getData(key, callback, value); ready.await(); client.deleteCurrentBranch("a/b"); }
Example 2
Source File: TestReadOnlyZKClient.java From hbase with Apache License 2.0 | 6 votes |
@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(); }
Example 3
Source File: ContentionStrategy.java From opensharding-spi-impl with Apache License 2.0 | 5 votes |
@Override public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { getProvider().executeContention(new LeaderElection() { @Override public void action() throws KeeperException, InterruptedException { getProvider().getData(getProvider().getRealPath(key), callback, ctx); } }); }
Example 4
Source File: ReconfigBuilderImpl.java From curator with Apache License 2.0 | 5 votes |
@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); } }; ((ZooKeeperAdmin)client.getZooKeeper()).reconfigure(joining, leaving, newMembers, fromConfig, callback, backgrounding.getContext()); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }
Example 5
Source File: GetConfigBuilderImpl.java From curator with Apache License 2.0 | 5 votes |
@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); } }
Example 6
Source File: UsualStrategy.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@Override public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { getProvider().getData(getProvider().getRealPath(key), callback, ctx); }
Example 7
Source File: ZooKeeperImpl.java From hbase-indexer with Apache License 2.0 | 4 votes |
@Override public void getData(String path, boolean watch, AsyncCallback.DataCallback cb, Object ctx) { delegate.getData(path, watch, cb, ctx); }
Example 8
Source File: ZooKeeperImpl.java From hbase-indexer with Apache License 2.0 | 4 votes |
@Override public void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) { delegate.getData(path, watcher, cb, ctx); }
Example 9
Source File: ZooKeeperConnection.java From util with Apache License 2.0 | 4 votes |
public void getData(final String path, final boolean watch, final AsyncCallback.DataCallback cb, final Object ctx) { zooKeeper.getData(path, watch, cb, ctx); }
Example 10
Source File: ZooKeeperConnection.java From util with Apache License 2.0 | 4 votes |
public void getData(final String path, final Watcher watcher, final AsyncCallback.DataCallback cb, final Object ctx) { zooKeeper.getData(path, watcher, cb, ctx); }
Example 11
Source File: ZookeeperClient.java From ignite with Apache License 2.0 | 4 votes |
/** * @param path Path. * @param watcher Watcher. * @param cb Callback. */ GetDataOperation(String path, Watcher watcher, AsyncCallback.DataCallback cb) { this.path = path; this.watcher = watcher; this.cb = cb; }
Example 12
Source File: ZookeeperClient.java From ignite with Apache License 2.0 | 4 votes |
/** * @param path Path. * @param watcher Watcher. * @param cb Callback. */ void getDataAsync(String path, Watcher watcher, AsyncCallback.DataCallback cb) { GetDataOperation op = new GetDataOperation(path, watcher, cb); zk.getData(path, watcher, new DataCallbackWrapper(op), null); }
Example 13
Source File: UsualClient.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@Override public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { execStrategy.getData(key, callback, ctx); }
Example 14
Source File: BaseZookeeperProvider.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
@Override public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) { holder.getZooKeeper().getData(key, watched, callback, ctx); }
Example 15
Source File: IZookeeperProvider.java From opensharding-spi-impl with Apache License 2.0 | 2 votes |
/** * Get string type data. * * @param key key * @param callback callback * @param ctx ctx * @throws KeeperException zookeeper exception * @throws InterruptedException interrupted exception */ void getData(String key, AsyncCallback.DataCallback callback, Object ctx) throws KeeperException, InterruptedException;
Example 16
Source File: IZookeeperAction.java From opensharding-spi-impl with Apache License 2.0 | 2 votes |
/** * Get string type data. * * @param key key * @param callback callback * @param ctx context * @throws KeeperException zookeeper exception * @throws InterruptedException interrupted exception */ void getData(String key, AsyncCallback.DataCallback callback, Object ctx) throws KeeperException, InterruptedException;
Example 17
Source File: ZooKeeperItf.java From hbase-indexer with Apache License 2.0 | votes |
void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx);
Example 18
Source File: ZooKeeperItf.java From hbase-indexer with Apache License 2.0 | votes |
void getData(String path, boolean watch, AsyncCallback.DataCallback cb, Object ctx);