Search in sources :

Example 11 with OperationTrace

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

the class TempGetDataBuilderImpl method forPath.

@Override
public byte[] forPath(String path) throws Exception {
    final String localPath = client.fixForNamespace(path);
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("GetDataBuilderImpl-Foreground");
    byte[] responseData = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<byte[]>() {

        @Override
        public byte[] call() throws Exception {
            return client.getZooKeeper().getData(localPath, false, responseStat);
        }
    });
    trace.setResponseBytesLength(responseData).setPath(path).setStat(responseStat).commit();
    return decompress ? client.getCompressionProvider().decompress(path, responseData) : responseData;
}
Also used : OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 12 with OperationTrace

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

the class CreateBuilderImpl method pathInForeground.

private String pathInForeground(final String path, final byte[] data) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Foreground");
    final AtomicBoolean firstTime = new AtomicBoolean(true);
    String returnPath = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<String>() {

        @Override
        public String call() throws Exception {
            boolean localFirstTime = firstTime.getAndSet(false) && !debugForceFindProtectedNode;
            String createdPath = null;
            if (!localFirstTime && doProtected) {
                debugForceFindProtectedNode = false;
                createdPath = findProtectedNodeInForeground(path);
            }
            if (createdPath == null) {
                try {
                    createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
                } catch (KeeperException.NoNodeException e) {
                    if (createParentsIfNeeded) {
                        ZKPaths.mkdirs(client.getZooKeeper(), path, false, client.getAclProvider(), createParentsAsContainers);
                        createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
                    } else {
                        throw e;
                    }
                }
            }
            if (failNextCreateForTesting) {
                failNextCreateForTesting = false;
                throw new KeeperException.ConnectionLossException();
            }
            return createdPath;
        }
    });
    trace.setRequestBytesLength(data).setPath(path).commit();
    return returnPath;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 13 with OperationTrace

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

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 14 with OperationTrace

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

the class GetDataBuilderImpl method performBackgroundOperation.

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

            @Override
            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
                trace.setReturnCode(rc).setResponseBytesLength(data).setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(stat).commit();
                if (decompress && (data != null)) {
                    try {
                        data = client.getCompressionProvider().decompress(path, data);
                    } catch (Exception e) {
                        ThreadUtils.checkInterrupted(e);
                        log.error("Decompressing for path: " + path, e);
                        rc = KeeperException.Code.DATAINCONSISTENCY.intValue();
                    }
                }
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_DATA, rc, path, null, ctx, stat, data, null, null, null);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        if (watching.isWatched()) {
            client.getZooKeeper().getData(operationAndData.getData(), true, callback, backgrounding.getContext());
        } else {
            client.getZooKeeper().getData(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) KeeperException(org.apache.zookeeper.KeeperException) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 15 with OperationTrace

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

the class GetDataBuilderImpl method pathInForeground.

private byte[] pathInForeground(final String path) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("GetDataBuilderImpl-Foreground");
    byte[] responseData = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<byte[]>() {

        @Override
        public byte[] call() throws Exception {
            byte[] responseData;
            if (watching.isWatched()) {
                responseData = client.getZooKeeper().getData(path, true, responseStat);
            } else {
                responseData = client.getZooKeeper().getData(path, watching.getWatcher(), responseStat);
            }
            return responseData;
        }
    });
    trace.setResponseBytesLength(responseData).setPath(path).setWithWatcher(watching.getWatcher() != null).setStat(responseStat).commit();
    return decompress ? client.getCompressionProvider().decompress(path, responseData) : responseData;
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) 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