Search in sources :

Example 6 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project xian by happyyangyuan.

the class SyncBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("SyncBuilderImpl-Background");
        final String path = operationAndData.getData();
        String adjustedPath = client.fixForNamespace(path);
        AsyncCallback.VoidCallback voidCallback = new AsyncCallback.VoidCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx) {
                trace.setReturnCode(rc).setPath(path).commit();
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.SYNC, rc, path, path, ctx, null, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().sync(adjustedPath, voidCallback, backgrounding.getContext());
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) CuratorEvent(org.apache.curator.framework.api.CuratorEvent) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 7 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project xian by happyyangyuan.

the class ExistsBuilderImpl method pathInForegroundStandard.

private Stat pathInForegroundStandard(final String path) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("ExistsBuilderImpl-Foreground");
    Stat returnStat = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<Stat>() {

        @Override
        public Stat call() throws Exception {
            Stat returnStat;
            if (watching.isWatched()) {
                returnStat = client.getZooKeeper().exists(path, true);
            } else {
                returnStat = client.getZooKeeper().exists(path, watching.getWatcher());
            }
            return returnStat;
        }
    });
    trace.setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(returnStat).commit();
    return returnStat;
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 8 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project xian by happyyangyuan.

the class ExistsBuilderImpl method pathInForeground.

private Stat pathInForeground(final String path) throws Exception {
    if (createParentContainersIfNeeded) {
        final String parent = ZKPaths.getPathAndNode(path).getPath();
        if (!parent.equals(ZKPaths.PATH_SEPARATOR)) {
            OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("ExistsBuilderImpl-Foreground-CreateParents");
            RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        ZKPaths.mkdirs(client.getZooKeeper(), parent, true, client.getAclProvider(), true);
                    } catch (KeeperException.NodeExistsException e) {
                    // ignore
                    } catch (KeeperException.NoNodeException e) {
                    // ignore
                    }
                    return null;
                }
            });
            trace.setPath(path).commit();
        }
    }
    return pathInForegroundStandard(path);
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 9 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project xian by happyyangyuan.

the class GetChildrenBuilderImpl method pathInForeground.

private List<String> pathInForeground(final String path) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("GetChildrenBuilderImpl-Foreground");
    List<String> children = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<List<String>>() {

        @Override
        public List<String> call() throws Exception {
            List<String> children;
            if (watching.isWatched()) {
                children = client.getZooKeeper().getChildren(path, true, responseStat);
            } else {
                children = client.getZooKeeper().getChildren(path, watching.getWatcher(), responseStat);
            }
            return children;
        }
    });
    trace.setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(responseStat).commit();
    return children;
}
Also used : List(java.util.List) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 10 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project xian by happyyangyuan.

the class SetDataBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("SetDataBuilderImpl-Background");
        final byte[] data = operationAndData.getData().getData();
        client.getZooKeeper().setData(operationAndData.getData().getPath(), data, version, new AsyncCallback.StatCallback() {

            @SuppressWarnings({ "unchecked" })
            @Override
            public void processResult(int rc, String path, Object ctx, Stat stat) {
                trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).setStat(stat).commit();
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.SET_DATA, rc, path, null, ctx, stat, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        }, backgrounding.getContext());
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) Stat(org.apache.zookeeper.data.Stat) OperationTrace(org.apache.curator.drivers.OperationTrace)

Aggregations

OperationTrace (org.apache.curator.drivers.OperationTrace)25 AsyncCallback (org.apache.zookeeper.AsyncCallback)11 Stat (org.apache.zookeeper.data.Stat)10 KeeperException (org.apache.zookeeper.KeeperException)8 List (java.util.List)6 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Watcher (org.apache.zookeeper.Watcher)1 ACL (org.apache.zookeeper.data.ACL)1