Example usage for org.apache.zookeeper.server DataTree copyStat

List of usage examples for org.apache.zookeeper.server DataTree copyStat

Introduction

In this page you can find the example usage for org.apache.zookeeper.server DataTree copyStat.

Prototype

public static void copyStat(Stat from, Stat to) 

Source Link

Usage

From source file:com.facebook.zookeeper.mock.MockZooKeeperDataStore.java

License:Apache License

public synchronized Stat exists(long sessionId, String path, Watcher watcher) throws KeeperException {
    try {//from   w w  w.ja va  2  s  . c  o m
        ZNode node = isRootPath(path) ? root : root.findDescendant(stripRootFromPath(path));
        if (watcher != null) {
            node.addWatcher(sessionId, watcher, WatchTriggerPolicy.WatchType.EXISTS);
        }
        Stat stat = new Stat();
        DataTree.copyStat(node.getStat(), stat);
        return stat;
    } catch (KeeperException.NoNodeException e) {
        if (watcher != null) {
            // Set a watch for this node when it gets created
            if (!creationWatchers.containsKey(path)) {
                creationWatchers.put(path, new RetrieveableSet<ContextedWatcher>());
            }
            ContextedWatcher contextedWatcher = new ContextedWatcher(watcher, sessionId,
                    WatchTriggerPolicy.WatchType.EXISTS);
            if (!creationWatchers.get(path).contains(contextedWatcher)) {
                creationWatchers.get(path).add(contextedWatcher);
            }
        }
        return null;
    }
}

From source file:com.facebook.zookeeper.mock.MockZooKeeperDataStore.java

License:Apache License

public synchronized byte[] getData(long sessionId, String path, Watcher watcher, Stat stat)
        throws KeeperException {
    ZNode node = isRootPath(path) ? root : root.findDescendant(stripRootFromPath(path));
    if (watcher != null) {
        node.addWatcher(sessionId, watcher, WatchTriggerPolicy.WatchType.GETDATA);
    }//w w  w.  j  a v a  2  s.c o m
    if (stat != null) {
        DataTree.copyStat(node.getStat(), stat);
    }
    return node.getData();
}

From source file:com.facebook.zookeeper.mock.MockZooKeeperDataStore.java

License:Apache License

public synchronized Stat setData(String path, byte[] data, int expectedVersion) throws KeeperException {
    ZNode node = isRootPath(path) ? root : root.findDescendant(stripRootFromPath(path));
    node.setData(data, expectedVersion);
    Stat stat = new Stat();
    DataTree.copyStat(node.getStat(), stat);
    return stat;/*from  w  w w. ja  va  2 s  .  c o m*/
}

From source file:org.apache.curator.framework.imps.ReconfigBuilderImpl.java

License:Apache License

@Override
public void performBackgroundOperation(final OperationAndData<Void> data) throws Exception {
    try {/*ww w  .  ja  v a 2s.  c  om*/
        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);
    }
}

From source file:org.apache.curator.x.async.modeled.details.CachedModeledFrameworkImpl.java

License:Apache License

@Override
public AsyncStage<T> read(Stat storingStatIn) {
    return internalRead(n -> {
        if (storingStatIn != null) {
            DataTree.copyStat(n.stat(), storingStatIn);
        }//w w w .ja v  a2s  . com
        return n.model();
    }, this::exceptionally);
}

From source file:org.apache.helix.manager.zk.ZkCacheBaseDataAccessor.java

License:Apache License

@Override
public T get(String path, Stat stat, int options) {
    String clientPath = path;//from   w w w . j a v a 2  s.  co m
    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);
}