Search in sources :

Example 1 with OperationTrace

use of org.apache.curator.drivers.OperationTrace in project fabric8 by jboss-fuse.

the class CuratorZookeeperClient method blockUntilConnectedOrTimedOut.

/**
 * This method blocks until the connection to ZK succeeds. Use with caution. The block
 * will timeout after the connection timeout (as passed to the constructor) has elapsed
 *
 * @return true if the connection succeeded, false if not
 * @throws InterruptedException interrupted while waiting
 */
public boolean blockUntilConnectedOrTimedOut() throws InterruptedException {
    Preconditions.checkState(started.get(), "Client is not started");
    log.debug("blockUntilConnectedOrTimedOut() start");
    OperationTrace trace = startAdvancedTracer("blockUntilConnectedOrTimedOut");
    internalBlockUntilConnectedOrTimedOut();
    trace.commit();
    boolean localIsConnected = state.isConnected();
    log.debug("blockUntilConnectedOrTimedOut() end. isConnected: " + localIsConnected);
    return localIsConnected;
}
Also used : OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 2 with OperationTrace

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

the class DeleteBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("DeleteBuilderImpl-Background");
        client.getZooKeeper().delete(operationAndData.getData(), version, new AsyncCallback.VoidCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx) {
                trace.setReturnCode(rc).setPath(path).commit();
                if ((rc == KeeperException.Code.NOTEMPTY.intValue()) && deletingChildrenIfNeeded) {
                    backgroundDeleteChildrenThenNode(operationAndData);
                } else {
                    CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.DELETE, rc, path, null, ctx, null, null, null, null, null);
                    client.processBackgroundOperation(operationAndData, event);
                }
            }
        }, backgrounding.getContext());
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 3 with OperationTrace

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

the class DeleteBuilderImpl method pathInForeground.

private void pathInForeground(final String path, String unfixedPath) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("DeleteBuilderImpl-Foreground");
    try {
        RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                try {
                    client.getZooKeeper().delete(path, version);
                } catch (KeeperException.NotEmptyException e) {
                    if (deletingChildrenIfNeeded) {
                        ZKPaths.deleteChildren(client.getZooKeeper(), path, true);
                    } else {
                        throw e;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        ThreadUtils.checkInterrupted(e);
        // Only retry a guaranteed delete if it's a retryable error
        if ((RetryLoop.isRetryException(e) || (e instanceof InterruptedException)) && guaranteed) {
            client.getFailedDeleteManager().addFailedDelete(unfixedPath);
        }
        throw e;
    }
    trace.setPath(path).commit();
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 4 with OperationTrace

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

the class GetACLBuilderImpl method performBackgroundOperation.

@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);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().getACL(operationAndData.getData(), responseStat, 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)

Example 5 with OperationTrace

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

the class GetACLBuilderImpl method pathInForeground.

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

        @Override
        public List<ACL> call() throws Exception {
            return client.getZooKeeper().getACL(path, responseStat);
        }
    });
    trace.setPath(path).setStat(responseStat).commit();
    return result;
}
Also used : ACL(org.apache.zookeeper.data.ACL) 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