Search in sources :

Example 21 with OperationTrace

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

the class SetDataBuilderImpl method pathInForeground.

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

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

Example 22 with OperationTrace

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

the class ConnectionState method process.

@Override
public void process(WatchedEvent event) {
    if (LOG_EVENTS) {
        log.debug("ConnectState watcher: " + event);
    }
    final boolean eventTypeNone = event.getType() == Watcher.Event.EventType.None;
    if (eventTypeNone) {
        boolean wasConnected = isConnected.get();
        boolean newIsConnected = checkState(event.getState(), wasConnected);
        if (newIsConnected != wasConnected) {
            isConnected.set(newIsConnected);
            connectionStartMs = System.currentTimeMillis();
        }
    }
    // only wait during tests
    if (debugWaitOnExpiredEvent && event.getState() == Event.KeeperState.Expired) {
        waitOnExpiredEvent();
    }
    for (Watcher parentWatcher : parentWatchers) {
        OperationTrace trace = new OperationTrace("connection-state-parent-process", tracer.get(), getSessionId());
        parentWatcher.process(event);
        trace.commit();
    }
    if (eventTypeNone)
        handleState(event.getState());
}
Also used : Watcher(org.apache.zookeeper.Watcher) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 23 with OperationTrace

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

the class BackgroundSyncImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
    final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("BackgroundSyncImpl");
    final String data = operationAndData.getData();
    client.getZooKeeper().sync(data, new AsyncCallback.VoidCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx) {
            trace.setReturnCode(rc).setRequestBytesLength(data).commit();
            CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.SYNC, rc, path, null, ctx, null, null, null, null, null);
            client.processBackgroundOperation(operationAndData, event);
        }
    }, context);
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 24 with OperationTrace

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

the class CreateBuilderImpl method performBackgroundOperation.

@Override
public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception {
    try {
        final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Background");
        final byte[] data = operationAndData.getData().getData();
        client.getZooKeeper().create(operationAndData.getData().getPath(), data, acling.getAclList(operationAndData.getData().getPath()), createMode, new AsyncCallback.StringCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, String name) {
                trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).commit();
                if ((rc == KeeperException.Code.NONODE.intValue()) && createParentsIfNeeded) {
                    backgroundCreateParentsThenNode(client, operationAndData, operationAndData.getData().getPath(), backgrounding, createParentsAsContainers);
                } else {
                    sendBackgroundResponse(rc, path, ctx, name, operationAndData);
                }
            }
        }, backgrounding.getContext());
    } catch (Throwable e) {
        backgrounding.checkError(e);
    }
}
Also used : AsyncCallback(org.apache.zookeeper.AsyncCallback) OperationTrace(org.apache.curator.drivers.OperationTrace)

Example 25 with OperationTrace

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

the class CreateBuilderImpl method findProtectedNodeInForeground.

private String findProtectedNodeInForeground(final String path) throws Exception {
    OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-findProtectedNodeInForeground");
    String returnPath = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<String>() {

        @Override
        public String call() throws Exception {
            String foundNode = null;
            try {
                final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path);
                List<String> children = client.getZooKeeper().getChildren(pathAndNode.getPath(), false);
                foundNode = findNode(children, pathAndNode.getPath(), protectedId);
            } catch (KeeperException.NoNodeException ignore) {
            // ignore
            }
            return foundNode;
        }
    });
    trace.setPath(path).commit();
    return returnPath;
}
Also used : List(java.util.List) 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