Search in sources :

Example 31 with ChildData

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());
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 32 with ChildData

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());
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 33 with ChildData

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());
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 34 with ChildData

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();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PersistentNodeListener(org.apache.curator.framework.recipes.nodes.PersistentNodeListener) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) ChildData(org.apache.curator.framework.recipes.cache.ChildData) PersistentNode(org.apache.curator.framework.recipes.nodes.PersistentNode) RetryPolicy(org.apache.curator.RetryPolicy)

Example 35 with ChildData

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;
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Aggregations

ChildData (org.apache.curator.framework.recipes.cache.ChildData)119 Test (org.junit.Test)75 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)70 IOException (java.io.IOException)10 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 LeaderElectionJobListener (com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener)7 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)6 KeeperException (org.apache.zookeeper.KeeperException)6 JobPausedStatusJobListener (com.dangdang.ddframe.job.lite.internal.server.JobOperationListenerManager.JobPausedStatusJobListener)5 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)5 TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)5 TestSimpleJob (com.dangdang.ddframe.job.lite.fixture.TestSimpleJob)4 CronSettingAndJobEventChangedJobListener (com.dangdang.ddframe.job.lite.internal.config.ConfigurationListenerManager.CronSettingAndJobEventChangedJobListener)4 MonitorExecutionChangedJobListener (com.dangdang.ddframe.job.lite.internal.execution.ExecutionListenerManager.MonitorExecutionChangedJobListener)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ServiceDTO (io.fabric8.gateway.ServiceDTO)3 ObjectInputStream (java.io.ObjectInputStream)3 URISyntaxException (java.net.URISyntaxException)3