本文整理汇总了Java中org.apache.zookeeper.AsyncCallback.StatCallback类的典型用法代码示例。如果您正苦于以下问题:Java StatCallback类的具体用法?Java StatCallback怎么用?Java StatCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatCallback类属于org.apache.zookeeper.AsyncCallback包,在下文中一共展示了StatCallback类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exists
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The asynchronous version of exists.
*
* @see #exists(String, Watcher)
*/
public void exists(final String path, Watcher watcher,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new ExistsWatchRegistration(watcher, clientPath);
}
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.exists);
ExistsRequest request = new ExistsRequest();
request.setPath(serverPath);
request.setWatch(watcher != null);
SetDataResponse response = new SetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, wcb);
}
示例2: setData
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The asynchronous version of setData.
*
* @see #setData(String, byte[], int)
*/
public void setData(final String path, byte data[], int version,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.setData);
SetDataRequest request = new SetDataRequest();
request.setPath(serverPath);
request.setData(data);
request.setVersion(version);
SetDataResponse response = new SetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, null);
}
示例3: setACL
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The asynchronous version of setACL.
*
* @see #setACL(String, List, int)
*/
public void setACL(final String path, List<ACL> acl, int version,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.setACL);
SetACLRequest request = new SetACLRequest();
request.setPath(serverPath);
request.setAcl(acl);
request.setVersion(version);
SetACLResponse response = new SetACLResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, null);
}
示例4: exists
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The Asynchronous version of exists. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #exists(String, boolean)
*/
public void exists(final String path, Watcher watcher,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new ExistsWatchRegistration(watcher, clientPath);
}
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.exists);
ExistsRequest request = new ExistsRequest();
request.setPath(serverPath);
request.setWatch(watcher != null);
SetDataResponse response = new SetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, wcb);
}
示例5: setData
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The Asynchronous version of setData. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #setData(String, byte[], int)
*/
public void setData(final String path, byte data[], int version,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.setData);
SetDataRequest request = new SetDataRequest();
request.setPath(serverPath);
request.setData(data);
request.setVersion(version);
SetDataResponse response = new SetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, null);
}
示例6: setACL
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* The Asynchronous version of setACL. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #setACL(String, List, int)
*/
public void setACL(final String path, List<ACL> acl, int version,
StatCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.setACL);
SetACLRequest request = new SetACLRequest();
request.setPath(serverPath);
request.setAcl(acl);
request.setVersion(version);
SetACLResponse response = new SetACLResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, null);
}
示例7: updateNamespaceBundles
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
/**
* update new bundle-range to LocalZk (create a new node if not present)
*
* @param nsname
* @param nsBundles
* @param callback
* @throws Exception
*/
private void updateNamespaceBundles(NamespaceName nsname, NamespaceBundles nsBundles, StatCallback callback)
throws Exception {
checkNotNull(nsname);
checkNotNull(nsBundles);
String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString());
Optional<LocalPolicies> policies = pulsar.getLocalZkCacheService().policiesCache().get(path);
if (!policies.isPresent()) {
// if policies is not present into localZk then create new policies
this.pulsar.getLocalZkCacheService().createPolicies(path, false).get(cacheTimeOutInSec, SECONDS);
policies = this.pulsar.getLocalZkCacheService().policiesCache().get(path);
}
policies.get().bundles = getBundlesData(nsBundles);
this.pulsar.getLocalZkCache().getZooKeeper().setData(path,
ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies.get()), -1, callback, null);
// invalidate namespace's local-policies
this.pulsar.getLocalZkCacheService().policiesCache().invalidate(path);
}
示例8: exists
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
@Override
public void exists(String path, boolean watch, StatCallback cb, Object ctx) {
executor.execute(() -> {
mutex.lock();
if (getProgrammedFailStatus()) {
mutex.unlock();
cb.processResult(failReturnCode.intValue(), path, ctx, null);
return;
} else if (stopped) {
mutex.unlock();
cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
return;
}
if (tree.containsKey(path)) {
mutex.unlock();
cb.processResult(0, path, ctx, new Stat());
} else {
mutex.unlock();
cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
}
});
}
示例9: installWatch
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
@Override
protected void installWatch() {
connection.exists(getNode(), this, new StatCallback() {
public void processResult(int rc, String path, Object ctx, Stat stat) {
}
}, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Installed exists watch");
}
}
示例10: writeLedgerConfig
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
public void writeLedgerConfig(StatCallback callback, Object ctx) {
bk.getZkHandle().setData(StringUtils.getLedgerNodePath(ledgerId),
metadata.serialize(), -1, callback, ctx);
}
示例11: handleBookieFailure
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
void handleBookieFailure(InetSocketAddress addr, final int bookieIndex) {
InetSocketAddress newBookie;
if (LOG.isDebugEnabled()) {
LOG.debug("Handling failure of bookie: " + addr + " index: "
+ bookieIndex);
}
try {
newBookie = bk.bookieWatcher
.getAdditionalBookie(metadata.currentEnsemble);
} catch (BKNotEnoughBookiesException e) {
LOG
.error("Could not get additional bookie to remake ensemble, closing ledger: "
+ ledgerId);
handleUnrecoverableErrorDuringAdd(e.getCode());
return;
}
final ArrayList<InetSocketAddress> newEnsemble = new ArrayList<InetSocketAddress>(
metadata.currentEnsemble);
newEnsemble.set(bookieIndex, newBookie);
if (LOG.isDebugEnabled()) {
LOG.debug("Changing ensemble from: " + metadata.currentEnsemble + " to: "
+ newEnsemble + " for ledger: " + ledgerId + " starting at entry: "
+ (lastAddConfirmed + 1));
}
metadata.addEnsemble(lastAddConfirmed + 1, newEnsemble);
writeLedgerConfig(new StatCallback() {
@Override
public void processResult(final int rc, String path, Object ctx, Stat stat) {
bk.mainWorkerPool.submitOrdered(ledgerId, new SafeRunnable() {
@Override
public void safeRun() {
if (rc != KeeperException.Code.OK.intValue()) {
LOG
.error("Could not persist ledger metadata while changing ensemble to: "
+ newEnsemble + " , closing ledger");
handleUnrecoverableErrorDuringAdd(BKException.Code.ZKException);
return;
}
for (PendingAddOp pendingAddOp : pendingAddOps) {
pendingAddOp.unsetSuccessAndSendWriteRequest(bookieIndex);
}
}
});
}
}, null);
}
示例12: setData
import org.apache.zookeeper.AsyncCallback.StatCallback; //导入依赖的package包/类
@Override
public void setData(final String path, final byte[] data, int version, final StatCallback cb, final Object ctx) {
if (stopped) {
cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
return;
}
executor.execute(() -> {
final Set<Watcher> toNotify = Sets.newHashSet();
mutex.lock();
if (getProgrammedFailStatus()) {
mutex.unlock();
cb.processResult(failReturnCode.intValue(), path, ctx, null);
return;
} else if (stopped) {
mutex.unlock();
cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
return;
}
if (!tree.containsKey(path)) {
mutex.unlock();
cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
return;
}
int currentVersion = tree.get(path).second;
// Check version
if (version != -1 && version != currentVersion) {
log.debug("[{}] Current version: {} -- Expected: {}", path, currentVersion, version);
mutex.unlock();
cb.processResult(KeeperException.Code.BadVersion, path, ctx, null);
return;
}
int newVersion = currentVersion + 1;
log.debug("[{}] Updating -- current version: {}", path, currentVersion);
tree.put(path, Pair.create(data, newVersion));
Stat stat = new Stat();
stat.setVersion(newVersion);
mutex.unlock();
cb.processResult(0, path, ctx, stat);
toNotify.addAll(watchers.get(path));
watchers.removeAll(path);
for (Watcher watcher : toNotify) {
watcher.process(new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path));
}
});
}