Java Code Examples for org.apache.zookeeper.server.DataTree#copyStat()

The following examples show how to use org.apache.zookeeper.server.DataTree#copyStat() . 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: ReconfigBuilderImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: ZkCacheBaseDataAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
public T get(String path, Stat stat, int options) {
  String clientPath = path;
  String serverPath = prependChroot(clientPath);

  Cache<T> cache = getCache(serverPath);
  if (cache != null) {
    T record = null;
    ZNode znode = cache.get(serverPath);

    if (znode != null) {
      // TODO: shall return a deep copy instead of reference
      record = ((T) znode.getData());
      if (stat != null) {
        DataTree.copyStat(znode.getStat(), stat);
      }
      return record;

    } else {
      // if cache miss, fall back to zk and update cache
      try {
        cache.lockWrite();
        record = _baseAccessor
            .get(serverPath, stat, options | AccessOption.THROW_EXCEPTION_IFNOTEXIST);
        cache.update(serverPath, record, stat);
      } catch (ZkNoNodeException e) {
        if (AccessOption.isThrowExceptionIfNotExist(options)) {
          throw e;
        }
      } finally {
        cache.unlockWrite();
      }

      return record;
    }
  }

  // no cache
  return _baseAccessor.get(serverPath, stat, options);
}
 
Example 3
Source File: MockHelixPropertyStore.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * This is not thread safe if some thread is setting {@link #readLatch}.
 */
@Override
public T get(String path, Stat stat, int options) {
  if (readLatch != null) {
    readLatch.countDown();
  }
  T result = pathToRecords.get(path);
  if (result != null && stat != null) {
    Stat resultStat = pathToStats.get(path);
    DataTree.copyStat(resultStat, stat);
  }
  return result;
}
 
Example 4
Source File: CreateBuilderImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception
{
    try
    {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Background");
        final byte[] data = operationAndData.getData().getData();

        AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, String name, Stat stat)
            {
                trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).commit();

                if ( (stat != null) && (storingStat != null) )
                {
                    DataTree.copyStat(stat, storingStat);
                }

                if ( (rc == KeeperException.Code.NONODE.intValue()) && createParentsIfNeeded )
                {
                    backgroundCreateParentsThenNode(client, operationAndData, operationAndData.getData().getPath(), backgrounding, acling.getACLProviderForParents(), createParentsAsContainers);
                }
                else if ( (rc == KeeperException.Code.NODEEXISTS.intValue()) && setDataIfExists )
                {
                    backgroundSetData(client, operationAndData, operationAndData.getData().getPath(), backgrounding);
                }
                else
                {
                    sendBackgroundResponse(rc, path, ctx, name, stat, operationAndData);
                }
            }
        };
        client.getZooKeeper().create
            (
                operationAndData.getData().getPath(),
                data,
                acling.getAclList(operationAndData.getData().getPath()),
                createMode,
                callback,
                backgrounding.getContext(),
                ttl
            );
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}