use of org.apache.curator.framework.api.CuratorEvent in project xian by happyyangyuan.
the class SetACLBuilderImpl method performBackgroundOperation.
@Override
public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception {
try {
final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("SetACLBuilderImpl-Background");
String path = operationAndData.getData();
client.getZooKeeper().setACL(path, acling.getAclList(path), version, new AsyncCallback.StatCallback() {
@SuppressWarnings({ "unchecked" })
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
trace.setReturnCode(rc).setPath(path).setStat(stat).commit();
CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.SET_ACL, rc, path, null, ctx, stat, null, null, null, null);
client.processBackgroundOperation(operationAndData, event);
}
}, backgrounding.getContext());
} catch (Throwable e) {
backgrounding.checkError(e);
}
}
use of org.apache.curator.framework.api.CuratorEvent in project xian by happyyangyuan.
the class DistributedQueue method doPutInBackground.
private void doPutInBackground(final T item, String path, final MultiItem<T> givenMultiItem, byte[] bytes) throws Exception {
BackgroundCallback callback = new BackgroundCallback() {
@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
if (event.getResultCode() != KeeperException.Code.OK.intValue()) {
return;
}
if (event.getType() == CuratorEventType.CREATE) {
synchronized (putCount) {
putCount.decrementAndGet();
putCount.notifyAll();
}
}
putListenerContainer.forEach(new Function<QueuePutListener<T>, Void>() {
@Override
public Void apply(QueuePutListener<T> listener) {
if (item != null) {
listener.putCompleted(item);
} else {
listener.putMultiCompleted(givenMultiItem);
}
return null;
}
});
}
};
internalCreateNode(path, bytes, callback);
}
use of org.apache.curator.framework.api.CuratorEvent in project xian by happyyangyuan.
the class LeaderLatch method getChildren.
private void getChildren() throws Exception {
BackgroundCallback callback = new BackgroundCallback() {
@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
checkLeadership(event.getChildren());
}
}
};
client.getChildren().inBackground(callback).forPath(ZKPaths.makePath(latchPath, null));
}
use of org.apache.curator.framework.api.CuratorEvent in project xian by happyyangyuan.
the class CrudExamples method setDataAsync.
public static void setDataAsync(CuratorFramework client, String path, byte[] payload) throws Exception {
// this is one method of getting event/async notifications
CuratorListener listener = new CuratorListener() {
@Override
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception {
// examine event for details
}
};
client.getCuratorListenable().addListener(listener);
// set data for the given node asynchronously. The completion notification
// is done via the CuratorListener.
client.setData().inBackground().forPath(path, payload);
}
use of org.apache.curator.framework.api.CuratorEvent in project xian by happyyangyuan.
the class TestLeaderSelectorEdges method createProtectedNodeInBackgroundTest.
/**
* Create a protected node in background with a retry policy
*/
@Test
public void createProtectedNodeInBackgroundTest() throws Exception {
final CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new RetryNTimes(2, 1)).connectionTimeoutMs(100).sessionTimeoutMs(60000).build();
final CountDownLatch latch = new CountDownLatch(1);
client.start();
try {
client.create().forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE);
client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).inBackground(new BackgroundCallback() {
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
log.info("Receive event {}", event.toString());
if (event.getResultCode() == KeeperException.Code.CONNECTIONLOSS.intValue()) {
latch.countDown();
}
}
}).forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE_PREFIX + "foo-");
Assert.assertTrue(latch.await(30, TimeUnit.SECONDS), "Callback has not been called");
// Wait for the znode to be deleted
Thread.sleep(ChaosMonkeyCnxnFactory.LOCKOUT_DURATION_MS * 2);
// Check that there is no znode
final int children = client.getChildren().forPath(ChaosMonkeyCnxnFactory.CHAOS_ZNODE).size();
Assert.assertEquals(children, 0, "Still " + children + " znodes under " + ChaosMonkeyCnxnFactory.CHAOS_ZNODE + " lock");
} finally {
client.close();
}
}
Aggregations