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


Java AsyncCallback类代码示例

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


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

示例1: testCreateAsync

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
@Test
public void testCreateAsync()
        throws IOException, KeeperException, InterruptedException {
    AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() {
        @Override
        public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
            // NOP
        }
    };
    zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, callback, null, 100);

    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,代码行数:21,代码来源:CreateTTLTest.java

示例2: asyncSetOfflineInZooKeeper

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * Set region as OFFLINED up in zookeeper asynchronously.
 * @param state
 * @return True if we succeeded, false otherwise (State was incorrect or failed
 * updating zk).
 */
private boolean asyncSetOfflineInZooKeeper(final RegionState state,
    final AsyncCallback.StringCallback cb, final ServerName destination) {
  if (!state.isClosed() && !state.isOffline()) {
    this.server.abort("Unexpected state trying to OFFLINE; " + state,
      new IllegalStateException());
    return false;
  }
  regionStates.updateRegionState(state.getRegion(), State.OFFLINE);
  try {
    ZKAssign.asyncCreateNodeOffline(watcher, state.getRegion(),
      destination, cb, state);
  } catch (KeeperException e) {
    if (e instanceof NodeExistsException) {
      LOG.warn("Node for " + state.getRegion() + " already exists");
    } else {
      server.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
    }
    return false;
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:AssignmentManager.java

示例3: getLastCommitPositions

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
@Override
public Future<Map<String, DLSN>> getLastCommitPositions() {
    final Promise<Map<String, DLSN>> result = new Promise<Map<String, DLSN>>();
    try {
        this.zkc.get().getChildren(this.zkPath, false, new AsyncCallback.Children2Callback() {
            @Override
            public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
                if (KeeperException.Code.NONODE.intValue() == rc) {
                    result.setValue(new HashMap<String, DLSN>());
                } else if (KeeperException.Code.OK.intValue() != rc) {
                    result.setException(KeeperException.create(KeeperException.Code.get(rc), path));
                } else {
                    getLastCommitPositions(result, children);
                }
            }
        }, null);
    } catch (ZooKeeperClient.ZooKeeperConnectionException zkce) {
        result.setException(zkce);
    } catch (InterruptedException ie) {
        result.setException(new DLInterruptedException("getLastCommitPositions was interrupted", ie));
    }
    return result;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:24,代码来源:ZKSubscriptionsStore.java

示例4: zkAsyncCreateFullPathOptimistic

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * Asynchronously create zookeeper path recursively and optimistically
 *
 * @param zkc Zookeeper client
 * @param pathToCreate  Zookeeper full path
 * @param parentPathShouldNotCreate zookeeper parent path should not be created
 * @param data Zookeeper data
 * @param acl Acl of the zk path
 * @param createMode Create mode of zk path
 */
public static Future<BoxedUnit> zkAsyncCreateFullPathOptimistic(
    final ZooKeeperClient zkc,
    final String pathToCreate,
    final Optional<String> parentPathShouldNotCreate,
    final byte[] data,
    final List<ACL> acl,
    final CreateMode createMode) {
    final Promise<BoxedUnit> result = new Promise<BoxedUnit>();

    zkAsyncCreateFullPathOptimisticRecursive(zkc, pathToCreate, parentPathShouldNotCreate,
            data, acl, createMode, new AsyncCallback.StringCallback() {
        @Override
        public void processResult(int rc, String path, Object ctx, String name) {
            handleKeeperExceptionCode(rc, path, result);
        }
    }, result);

    return result;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:30,代码来源:Utils.java

示例5: asyncSetOfflineInZooKeeper

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * Set region as OFFLINED up in zookeeper asynchronously.
 * @param state
 * @return True if we succeeded, false otherwise (State was incorrect or failed
 * updating zk).
 */
boolean asyncSetOfflineInZooKeeper(final RegionState state,
    final AsyncCallback.StringCallback cb, final Object ctx) {
  if (!state.isClosed() && !state.isOffline()) {
      new RuntimeException("Unexpected state trying to OFFLINE; " + state);
    this.master.abort("Unexpected state trying to OFFLINE; " + state,
      new IllegalStateException());
    return false;
  }
  state.update(RegionState.State.OFFLINE);
  try {
    ZKAssign.asyncCreateNodeOffline(master.getZooKeeper(), state.getRegion(),
      this.master.getServerName(), cb, ctx);
  } catch (KeeperException e) {
    // TODO: this error handling will never execute, as the callback is async.
    if (e instanceof NodeExistsException) {
      LOG.warn("Node for " + state.getRegion() + " already exists");
    } else { 
      master.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
    }
    return false;
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:30,代码来源:AssignmentManager.java

示例6: processKeeperException

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
protected void processKeeperException(final KeeperException e, final Watcher watcher,final DataAction dataAction,
        boolean asynchFlag) {
    switch (e.code()) {
    case BADVERSION:

        if (asynchFlag) {
            zooKeeper.getData(e.getPath(), watcher, new AsyncCallback.DataCallback() {
                @Override
                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
                    ZData zData = ZDataImpl.newInstance(path, data, stat.getVersion());
                    updateData(zData, dataAction, watcher);
                }
            }, null);
        } else {

        }

        break;
    default:
        logger.warn("encounter exception", e);
    }
}
 
开发者ID:shaolinwu,项目名称:uimaster,代码行数:23,代码来源:ZookeeperHelper.java

示例7: 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

示例8: asyncSetOfflineInZooKeeper

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * Set region as OFFLINED up in zookeeper asynchronously.
 * @param state
 * @return True if we succeeded, false otherwise (State was incorrect or failed
 * updating zk).
 */
boolean asyncSetOfflineInZooKeeper(final RegionState state,
    final AsyncCallback.StringCallback cb, final Object ctx) {
  if (!state.isClosed() && !state.isOffline()) {
      new RuntimeException("Unexpected state trying to OFFLINE; " + state);
    this.master.abort("Unexpected state trying to OFFLINE; " + state,
      new IllegalStateException());
    return false;
  }
  state.update(RegionState.State.OFFLINE);
  try {
    ZKAssign.asyncCreateNodeOffline(master.getZooKeeper(), state.getRegion(),
      this.master.getServerName(), cb, ctx);
  } catch (KeeperException e) {
    master.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
    return false;
  }
  return true;
}
 
开发者ID:lifeng5042,项目名称:RStore,代码行数:25,代码来源:AssignmentManager.java

示例9: performBackgroundOperation

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<CuratorMultiTransactionRecord> operationAndData) throws Exception
{
    try
    {
        final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background");
        AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, List<OpResult> opResults)
            {
                trace.commit();
                List<CuratorTransactionResult> curatorResults = (opResults != null) ? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData()) : null;
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.TRANSACTION, rc, path, null, ctx, null, null, null, null, null, curatorResults);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().multi(operationAndData.getData(), callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:25,代码来源:CuratorMultiTransactionImpl.java

示例10: performBackgroundOperation

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
{
    final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("BackgroundSyncImpl");
    final String data = operationAndData.getData();
    client.getZooKeeper().sync
    (
        data,
        new AsyncCallback.VoidCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx)
            {
                trace.setReturnCode(rc).setRequestBytesLength(data).commit();
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.SYNC, rc, path, null, ctx, null, null, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        },
        context
    );
}
 
开发者ID:apache,项目名称:curator,代码行数:22,代码来源:BackgroundSyncImpl.java

示例11: performBackgroundOperation

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
{
    try
    {
        final OperationTrace             trace = client.getZookeeperClient().startAdvancedTracer("GetACLBuilderImpl-Background");
        AsyncCallback.ACLCallback   callback = new AsyncCallback.ACLCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, List<ACL> acl, Stat stat)
            {
                trace.setReturnCode(rc).setPath(path).setStat(stat).commit();
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.GET_ACL, rc, path, null, ctx, stat, null, null, null, acl, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().getACL(operationAndData.getData(), responseStat, callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:GetACLBuilderImpl.java

示例12: asyncSetOfflineInZooKeeper

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * Set region as OFFLINED up in zookeeper asynchronously.
 * @param state
 * @return True if we succeeded, false otherwise (State was incorrect or failed
 * updating zk).
 */
private boolean asyncSetOfflineInZooKeeper(final RegionState state,
    final AsyncCallback.StringCallback cb, final ServerName destination) {
  if (!state.isClosed() && !state.isOffline()) {
    this.server.abort("Unexpected state trying to OFFLINE; " + state,
      new IllegalStateException());
    return false;
  }
  regionStates.updateRegionState(
    state.getRegion(), RegionState.State.OFFLINE);
  try {
    ZKAssign.asyncCreateNodeOffline(watcher, state.getRegion(),
      destination, cb, state);
  } catch (KeeperException e) {
    if (e instanceof NodeExistsException) {
      LOG.warn("Node for " + state.getRegion() + " already exists");
    } else {
      server.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
    }
    return false;
  }
  return true;
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:29,代码来源:AssignmentManager.java

示例13: MultiCallback

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
MultiCallback(int expected, AsyncCallback.VoidCallback cb, Object context) {
    this.expected = expected;
    this.cb = cb;
    this.context = context;
    if (expected == 0) {
        cb.processResult(Code.OK.intValue(), null, context);
    }
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:9,代码来源:BookKeeperTools.java

示例14: getAvailableBookies

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * This method asynchronously gets the set of available Bookies that the
 * dead input bookie's data will be copied over into. If the user passed in
 * a specific destination bookie, then just use that one. Otherwise, we'll
 * randomly pick one of the other available bookies to use for each ledger
 * fragment we are replicating.
 * 
 * @param bookieSrc
 *            Source bookie that had a failure. We want to replicate the
 *            ledger fragments that were stored there.
 * @param bookieDest
 *            Optional destination bookie that if passed, we will copy all
 *            of the ledger fragments from the source bookie over to it.
 * @param cb
 *            RecoverCallback to invoke once all of the data on the dead
 *            bookie has been recovered and replicated.
 * @param context
 *            Context for the RecoverCallback to call.
 */
private void getAvailableBookies(final InetSocketAddress bookieSrc, final InetSocketAddress bookieDest,
        final RecoverCallback cb, final Object context) {
    final List<InetSocketAddress> availableBookies = new LinkedList<InetSocketAddress>();
    if (bookieDest != null) {
        availableBookies.add(bookieDest);
        // Now poll ZK to get the active ledgers
        getActiveLedgers(bookieSrc, bookieDest, cb, context, availableBookies);
    } else {
        zk.getChildren(BOOKIES_PATH, null, new AsyncCallback.ChildrenCallback() {
            @Override
            public void processResult(int rc, String path, Object ctx, List<String> children) {
                if (rc != Code.OK.intValue()) {
                    LOG.error("ZK error getting bookie nodes: ", KeeperException.create(KeeperException.Code
                            .get(rc), path));
                    cb.recoverComplete(BKException.Code.ZKException, context);
                    return;
                }
                for (String bookieNode : children) {
                    String parts[] = bookieNode.split(COLON);
                    if (parts.length < 2) {
                        LOG.error("Bookie Node retrieved from ZK has invalid name format: " + bookieNode);
                        cb.recoverComplete(BKException.Code.ZKException, context);
                        return;
                    }
                    availableBookies.add(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
                }
                // Now poll ZK to get the active ledgers
                getActiveLedgers(bookieSrc, bookieDest, cb, context, availableBookies);
            }
        }, null);
    }
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:52,代码来源:BookKeeperTools.java

示例15: testGetACLAsync

import org.apache.zookeeper.AsyncCallback; //导入依赖的package包/类
/**
 * get acl async
 */
@Test
@ZooConfig(initNodes = {"/node"}, async = true)
public void testGetACLAsync() throws Exception {
    zooKeeper.getACL("/node", null, new AsyncCallback.ACLCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, List<ACL> acl, Stat stat) {
            assertTrue(acl.equals(ZooDefs.Ids.OPEN_ACL_UNSAFE));
            assertResult(rc, "/node", path, ctx, stat);
        }

    }, null);
}
 
开发者ID:txazo,项目名称:zookeeper,代码行数:17,代码来源:ACLTest.java


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