Search in sources :

Example 16 with OperationTrace

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

the class SetACLBuilderImpl method pathInForeground.

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

        @Override
        public Stat call() throws Exception {
            return client.getZooKeeper().setACL(path, acling.getAclList(path), version);
        }
    });
    trace.setPath(path).setStat(resultStat).commit();
    return resultStat;
}
Also used : Stat(org.apache.zookeeper.data.Stat) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 17 with OperationTrace

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

the class SetACLBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("SetACLBuilderImpl-Background");
        String path = operationAndData.getData();
        client.getZooKeeper().setACL(path, acling.getAclList(path), version, new AsyncCallback.StatCallback() {

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

Example 18 with OperationTrace

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

the class ExistsBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("ExistsBuilderImpl-Background");
        AsyncCallback.StatCallback callback = new AsyncCallback.StatCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, Stat stat) {
                trace.setReturnCode(rc).setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(stat).commit();
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.EXISTS, rc, path, null, ctx, stat, null, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        if (watching.isWatched()) {
            client.getZooKeeper().exists(operationAndData.getData(), true, callback, backgrounding.getContext());
        } else {
            client.getZooKeeper().exists(operationAndData.getData(), watching.getWatcher(), callback, backgrounding.getContext());
        }
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) AsyncCallback(org.apache.zookeeper.AsyncCallback) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 19 with OperationTrace

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

the class FindAndDeleteProtectedNodeInBackground method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<Void> operationAndData) throws Exception {
    final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("FindAndDeleteProtectedNodeInBackground");
    AsyncCallback.Children2Callback callback = new AsyncCallback.Children2Callback() {

        @Override
        public void processResult(int rc, String path, Object o, List<String> strings, Stat stat) {
            trace.setReturnCode(rc).setPath(path).setStat(stat).commit();
            if (debugInsertError.compareAndSet(true, false)) {
                rc = KeeperException.Code.CONNECTIONLOSS.intValue();
            }
            if (rc == KeeperException.Code.OK.intValue()) {
                // due to namespacing, don't let CreateBuilderImpl.findNode adjust the path
                final String node = CreateBuilderImpl.findNode(strings, "/", protectedId);
                if (node != null) {
                    try {
                        String deletePath = client.unfixForNamespace(ZKPaths.makePath(namespaceAdjustedParentPath, node));
                        client.delete().guaranteed().inBackground().forPath(deletePath);
                    } catch (Exception e) {
                        ThreadUtils.checkInterrupted(e);
                        log.error("Could not start guaranteed delete for node: " + node);
                        rc = KeeperException.Code.CONNECTIONLOSS.intValue();
                    }
                }
            }
            if (rc != KeeperException.Code.OK.intValue()) {
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.CHILDREN, rc, path, null, o, stat, null, strings, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        }
    };
    client.getZooKeeper().getChildren(namespaceAdjustedParentPath, false, callback, null);
}
Also used : Stat(org.apache.zookeeper.data.Stat) AsyncCallback(org.apache.zookeeper.AsyncCallback) List(java.util.List) KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 20 with OperationTrace

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

the class GetChildrenBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("GetChildrenBuilderImpl-Background");
        AsyncCallback.Children2Callback callback = new AsyncCallback.Children2Callback() {

            @Override
            public void processResult(int rc, String path, Object o, List<String> strings, Stat stat) {
                trace.setReturnCode(rc).setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(stat).commit();
                if (strings == null) {
                    strings = Lists.newArrayList();
                }
                CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.CHILDREN, rc, path, null, o, stat, null, strings, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        if (watching.isWatched()) {
            client.getZooKeeper().getChildren(operationAndData.getData(), true, callback, backgrounding.getContext());
        } else {
            client.getZooKeeper().getChildren(operationAndData.getData(), watching.getWatcher(), callback, backgrounding.getContext());
        }
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) AsyncCallback(org.apache.zookeeper.AsyncCallback) List(java.util.List) 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