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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations