use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class CloudJobConfigurationListenerTest method assertChildEventWhenStateIsUpdateAndIsConfigPathAndMisfireDisabled.
@Test
public void assertChildEventWhenStateIsUpdateAndIsConfigPathAndMisfireDisabled() throws Exception {
cloudJobConfigurationListener.childEvent(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_UPDATED, new ChildData("/config/job/test_job", null, CloudJsonConstants.getJobJson(false).getBytes())));
verify(readyService).setMisfireDisabled("test_job");
verify(producerManager).reschedule(Matchers.<CloudJobConfiguration>any());
}
use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class CloudJobConfigurationListenerTest method assertChildEventWhenIsRootConfigPath.
@Test
public void assertChildEventWhenIsRootConfigPath() throws Exception {
cloudJobConfigurationListener.childEvent(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/config/job", null, "".getBytes())));
verify(producerManager, times(0)).schedule(Matchers.<CloudJobConfiguration>any());
verify(producerManager, times(0)).reschedule(Matchers.<CloudJobConfiguration>any());
verify(producerManager, times(0)).unschedule(Matchers.<String>any());
}
use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class CloudJobConfigurationListenerTest method assertChildEventWhenStateIsUpdateAndIsConfigPathAndDaemonJob.
@Test
public void assertChildEventWhenStateIsUpdateAndIsConfigPathAndDaemonJob() throws Exception {
cloudJobConfigurationListener.childEvent(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_UPDATED, new ChildData("/config/job/test_job", null, CloudJsonConstants.getJobJson(CloudJobExecutionType.DAEMON).getBytes())));
verify(readyService).remove(Collections.singletonList("test_job"));
verify(producerManager).reschedule(Matchers.<CloudJobConfiguration>any());
}
use of org.apache.curator.framework.recipes.cache.ChildData in project BRFS by zhangnianli.
the class TestZKNode method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, 5 * 1000, 30 * 1000, retryPolicy);
client.start();
client.blockUntilConnected();
PathChildrenCache cache = new PathChildrenCache(client.usingNamespace("test"), "/fileCoordinator/big", true);
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
System.out.println("---" + event);
ChildData data = event.getData();
if (data != null) {
switch(event.getType()) {
case CHILD_ADDED:
System.out.println("###PATH-" + data.getPath());
break;
default:
break;
}
}
}
});
cache.start();
PersistentNode node = new PersistentNode(client.usingNamespace("test"), CreateMode.EPHEMERAL, false, "/fileCoordinator/temp-1", "node1".getBytes());
node.getListenable().addListener(new PersistentNodeListener() {
@Override
public void nodeCreated(String path) throws Exception {
System.out.println("node1--created:" + path);
}
});
node.start();
PersistentNode node2 = new PersistentNode(client.usingNamespace("test"), CreateMode.EPHEMERAL, false, "/fileCoordinator/temp-1", "node2".getBytes());
node2.getListenable().addListener(new PersistentNodeListener() {
@Override
public void nodeCreated(String path) throws Exception {
System.out.println("node2--created:" + path);
}
});
node2.start();
Thread.sleep(2000);
node2.close();
synchronized (node) {
node.wait();
}
}
use of org.apache.curator.framework.recipes.cache.ChildData in project coprhd-controller by CoprHD.
the class DistributedLockQueueManagerImpl method dequeue.
@Override
@SuppressWarnings("unchecked")
public boolean dequeue(String lockKey) {
String lockPath = ZKPaths.makePath(rootPath, lockKey);
log.info("Attempting to de-queue from {}", lockPath);
Map<String, ChildData> children = treeCache.getCurrentChildren(lockPath);
if (children == null || children.isEmpty()) {
log.info("Nothing to de-queue");
return false;
}
String first = getFirstItem(children);
log.info("Dequeueing {}", first);
final String fullPath = ZKPaths.makePath(lockPath, first);
ChildData childData = treeCache.getCurrentData(fullPath);
final T task = (T) GenericSerializer.deserialize(childData.getData());
log.info("Deserialized {}", task.toString());
consumer.startConsumeTask(task, new DistributedLockQueueTaskConsumerCallback() {
@Override
public void taskConsumed() {
if (deleteTask(fullPath)) {
notifyListeners(task, Event.REMOVED);
}
}
});
return true;
}
Aggregations