Search in sources :

Example 81 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData in project flink by apache.

the class ZooKeeperLeaderRetrievalService method nodeChanged.

@Override
public void nodeChanged() throws Exception {
    try {
        LOG.debug("Leader node has changed.");
        ChildData childData = cache.getCurrentData();
        String leaderAddress;
        UUID leaderSessionID;
        if (childData == null) {
            leaderAddress = null;
            leaderSessionID = null;
        } else {
            byte[] data = childData.getData();
            if (data == null || data.length == 0) {
                leaderAddress = null;
                leaderSessionID = null;
            } else {
                ByteArrayInputStream bais = new ByteArrayInputStream(data);
                ObjectInputStream ois = new ObjectInputStream(bais);
                leaderAddress = ois.readUTF();
                leaderSessionID = (UUID) ois.readObject();
            }
        }
        if (!(Objects.equals(leaderAddress, lastLeaderAddress) && Objects.equals(leaderSessionID, lastLeaderSessionID))) {
            LOG.debug("New leader information: Leader={}, session ID={}.", leaderAddress, leaderSessionID);
            lastLeaderAddress = leaderAddress;
            lastLeaderSessionID = leaderSessionID;
            leaderListener.notifyLeaderAddress(leaderAddress, leaderSessionID);
        }
    } catch (Exception e) {
        leaderListener.handleError(new Exception("Could not handle node changed event.", e));
        throw e;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ChildData(org.apache.curator.framework.recipes.cache.ChildData) UUID(java.util.UUID) ObjectInputStream(java.io.ObjectInputStream)

Example 82 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData in project archaius by Netflix.

the class ZooKeeperConfigurationSource method getCurrentData.

@Override
public Map<String, Object> getCurrentData() throws Exception {
    logger.debug("getCurrentData() retrieving current data.");
    List<ChildData> children = pathChildrenCache.getCurrentData();
    Map<String, Object> all = new HashMap<String, Object>(children.size());
    for (ChildData child : children) {
        String path = child.getPath();
        String key = removeRootPath(path);
        byte[] value = child.getData();
        all.put(key, new String(value, charset));
    }
    logger.debug("getCurrentData() retrieved [{}] config elements.", children.size());
    return all;
}
Also used : HashMap(java.util.HashMap) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Example 83 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData in project exhibitor by soabase.

the class ZookeeperConfigProvider method loadConfig.

@Override
public LoadedInstanceConfig loadConfig() throws Exception {
    int version = -1;
    Properties properties = new Properties();
    ChildData childData = getConfigNode();
    if (childData != null) {
        version = childData.getStat().getVersion();
        properties.load(new ByteArrayInputStream(childData.getData()));
    }
    PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
    return new LoadedInstanceConfig(config, version);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) ChildData(org.apache.curator.framework.recipes.cache.ChildData) Properties(java.util.Properties) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Aggregations

ChildData (org.apache.curator.framework.recipes.cache.ChildData)83 Test (org.junit.Test)71 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)67 LeaderElectionJobListener (com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener)7 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 JobPausedStatusJobListener (com.dangdang.ddframe.job.lite.internal.server.JobOperationListenerManager.JobPausedStatusJobListener)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 CuratorFramework (org.apache.curator.framework.CuratorFramework)4 KeeperException (org.apache.zookeeper.KeeperException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)3 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)3 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)3 ObjectInputStream (java.io.ObjectInputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2