当前位置: 首页>>代码示例>>Java>>正文


Java ChildData.getData方法代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.cache.ChildData.getData方法的典型用法代码示例。如果您正苦于以下问题:Java ChildData.getData方法的具体用法?Java ChildData.getData怎么用?Java ChildData.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.recipes.cache.ChildData的用法示例。


在下文中一共展示了ChildData.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processTokenAddOrUpdate

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void processTokenAddOrUpdate(ChildData data) throws IOException {
  ByteArrayInputStream bin = new ByteArrayInputStream(data.getData());
  DataInputStream din = new DataInputStream(bin);
  TokenIdent ident = createIdentifier();
  ident.readFields(din);
  long renewDate = din.readLong();
  int pwdLen = din.readInt();
  byte[] password = new byte[pwdLen];
  int numRead = din.read(password, 0, pwdLen);
  if (numRead > -1) {
    DelegationTokenInformation tokenInfo =
        new DelegationTokenInformation(renewDate, password);
    synchronized (this) {
      currentTokens.put(ident, tokenInfo);
      // The cancel task might be waiting
      notifyAll();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:ZKDelegationTokenSecretManager.java

示例2: getCurrentData

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
@Override
public byte[] getCurrentData() {
    byte[] result = null;
    if (isCacheUsageAllowed()) {
        ChildData data = cache.getCurrentData();
        if (data != null) {
            result = data.getData();
        }
    } else {
        try {
            result = dataIsCompressed ? connector.getDataDecompressed(path) : connector.getData(path);
        } catch (DataSourceConnectorException e) {
            log.warn("Failed to get data for zkPath={} {}", path);
        }
    }
    return result;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:18,代码来源:ZkNodeCacheWrapper.java

示例3: lockTableByNewNode

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void lockTableByNewNode(ChildData childData) throws Exception {
    String data = new String(childData.getData(), StandardCharsets.UTF_8);
    LOGGER.info("DDL node " + childData.getPath() + " created , and data is " + data);
    DDLInfo ddlInfo = new DDLInfo(data);
    final String fromNode = ddlInfo.getFrom();
    if (fromNode.equals(ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID))) {
        return; //self node
    }
    if (DDLStatus.INIT != ddlInfo.getStatus()) {
        return;
    }
    String nodeName = childData.getPath().substring(childData.getPath().lastIndexOf("/") + 1);
    String[] tableInfo = nodeName.split("\\.");
    final String schema = StringUtil.removeBackQuote(tableInfo[0]);
    final String table = StringUtil.removeBackQuote(tableInfo[1]);
    try {
        DbleServer.getInstance().getTmManager().addMetaLock(schema, table);
    } catch (Exception t) {
        DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
        throw t;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:23,代码来源:DDLChildListener.java

示例4: createOrUpdateViewMeta

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
/**
 * update the meta if the view updated
 */
private void createOrUpdateViewMeta(ChildData childData, boolean isReplace) throws Exception {
    String path = childData.getPath();
    String[] paths = path.split("/");
    String jsonValue = new String(childData.getData(), StandardCharsets.UTF_8);
    JSONObject obj = (JSONObject) JSONObject.parse(jsonValue);

    //if the view is create or replace by this server it self
    String serverId = obj.getString(SERVER_ID);
    if (serverId.equals(ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID))) {
        return;
    }
    String createSql = obj.getString(CREATE_SQL);
    String schema = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[0];

    ViewMeta vm = new ViewMeta(createSql, schema, DbleServer.getInstance().getTmManager());
    vm.initAndSet(isReplace);

}
 
开发者ID:actiontech,项目名称:dble,代码行数:22,代码来源:ViewChildListener.java

示例5: dumpDirectly

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void dumpDirectly(final String path, final List<String> result) {
    for (String each : coordinatorRegistryCenter.getElasticConfigRegistryCenter().getChildrenKeys(path)) {
        String zkPath = path + "/" + each;
        String zkValue = coordinatorRegistryCenter.getElasticConfigRegistryCenter().get(zkPath);
        if (null == zkValue) {
            zkValue = "";
        }
        TreeCache treeCache = (TreeCache) coordinatorRegistryCenter.getElasticConfigRegistryCenter().getRawCache(
            "/" + configProfile.getNode());
        ChildData treeCacheData = treeCache.getCurrentData(zkPath);
        String treeCachePath = null == treeCacheData ? "" : treeCacheData.getPath();
        String treeCacheValue = null == treeCacheData ? "" : new String(treeCacheData.getData());
        if (zkValue.equals(treeCacheValue) && zkPath.equals(treeCachePath)) {
            result.add(Joiner.on(" | ").join(zkPath, zkValue));
        }
        else {
            result.add(Joiner.on(" | ").join(zkPath, zkValue, treeCachePath, treeCacheValue));
        }
        dumpDirectly(zkPath, result);
    }
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:22,代码来源:DumpConfigService.java

示例6: dumpDirectly

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void dumpDirectly(final String path, final List<String> result) {
    for (String each : coordinatorRegistryCenter.getChildrenKeys(path)) {
        String zkPath = path + "/" + each;
        String zkValue = coordinatorRegistryCenter.get(zkPath);
        if (null == zkValue) {
            zkValue = "";
        }
        TreeCache treeCache = (TreeCache) coordinatorRegistryCenter.getRawCache("/" + jobName);
        ChildData treeCacheData = treeCache.getCurrentData(zkPath);
        String treeCachePath =  null == treeCacheData ? "" : treeCacheData.getPath();
        String treeCacheValue = null == treeCacheData ? "" : new String(treeCacheData.getData());
        if (zkValue.equals(treeCacheValue) && zkPath.equals(treeCachePath)) {
            result.add(Joiner.on(" | ").join(zkPath, zkValue));
        } else {
            result.add(Joiner.on(" | ").join(zkPath, zkValue, treeCachePath, treeCacheValue));
        }
        dumpDirectly(zkPath, result);
    }
}
 
开发者ID:zhoujia123,项目名称:ElasticJob,代码行数:20,代码来源:MonitorService.java

示例7: get

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
/**
 * Returns the value corresponding to the given key, null otherwise.
 *
 * If the flag consistent is set, the check is consistent as it is made against Zookeeper directly. Otherwise,
 * the check is eventually consistent.
 *
 * If consistency flag is set to true and version holder is not null, passes version holder to get data change version.
 * Data change version is retrieved from {@link Stat} object, it increases each time znode data change is performed.
 * Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes
 *
 * @param path  target path
 * @param consistent consistency check
 * @param version version holder
 */
public byte[] get(final String path, final boolean consistent, final DataChangeVersion version) {
  Preconditions.checkNotNull(path, "path is required");

  final String target = PathUtils.join(root, path);
  if (consistent) {
    try {
      if (version != null) {
        Stat stat = new Stat();
        final byte[] bytes = curator.getData().storingStatIn(stat).forPath(target);
        version.setVersion(stat.getVersion());
        return bytes;
      }
      return curator.getData().forPath(target);
    } catch (final Exception ex) {
      throw new DrillRuntimeException(String.format("error retrieving value for [%s]", path), ex);
    }
  } else {
    final ChildData data = getCache().getCurrentData(target);
    if (data != null) {
      return data.getData();
    }
  }
  return null;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:39,代码来源:ZookeeperClient.java

示例8: onNodeAdded

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
/**
 * Callback when an endpoint is removed
 * @param data the data representing the endpoint 
 */
protected void onNodeAdded(final ChildData data) {
	final Stat stat = data.getStat();
	if(stat!=null) {
		if(stat.getEphemeralOwner() > 0) {
			final byte[] bytes = data.getData();
			final AdvertisedEndpoint ae = JSONOps.parseToObject(bytes, AdvertisedEndpoint.class);
			registered.put(data.getPath(), ae);
			log.info("Discovered Endpoint: [{}]", ae);
			fireOnlinedEndpoint(ae);
			final Notification notif = new Notification(NOTIF_ENDPOINT_UP, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener discovered new endpoint [" + ae + "]");
			notif.setUserData(JSONOps.serializeToString(ae));
			sendNotification(notif);
			upEvents.increment();
		}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:21,代码来源:EndpointListener.java

示例9: onNodeRemoved

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
/**
 * Callback when an endpoint is removed
 * @param data the data representing the endpoint 
 */
protected void onNodeRemoved(final ChildData data) {
	final Stat stat = data.getStat();
	if(stat!=null) {
		if(stat.getEphemeralOwner() > 0) {
			final byte[] bytes = data.getData();
			final AdvertisedEndpoint ae = JSONOps.parseToObject(bytes, AdvertisedEndpoint.class);
			registered.remove(data.getPath());
			log.info("Endpoint Down: [{}]", ae);
			fireOfflinedEndpoint(ae);
			final Notification notif = new Notification(NOTIF_ENDPOINT_DOWN, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "Endpoint down [" + ae + "]");
			notif.setUserData(JSONOps.serializeToString(ae));
			sendNotification(notif);
			downEvents.increment();
		}
	}	
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:21,代码来源:EndpointListener.java

示例10: getData

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
public static Object getData(TreeCache treeCache, String pPath, String encode) throws IOException, KeeperException, InterruptedException {
    log.debug("pPath=" + pPath);
    ChildData cdata = treeCache.getCurrentData(pPath);
    log.debug("cdata=" + cdata);
    byte[] data = cdata.getData();
    log.debug("data=" + data);
    String datas = new String(data, encode);
    Object ret = datas;
    if (datas != null && !datas.trim().isEmpty()) {
        datas = datas.trim();
        if (datas.startsWith("{") && datas.endsWith("}")) {
            Map<String, Object> map = JsonUtil.toJavaBean(datas, Map.class);
            ret = map;
        } else if (datas.startsWith("[") && datas.endsWith("]")) {
            Collection<Object> ocoll = JsonUtil.toJavaBean(datas, Collection.class);
            ret = ocoll;
        }
    }
    log.debug("ret=" + ret);
    return ret;
}
 
开发者ID:dpcn,项目名称:conf-from-zk,代码行数:22,代码来源:ZkWatherUtil.java

示例11: childEvent

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData data = event.getData();
    if(data==null || data.getData()==null){
        return;
    }
    SlaveNode slaveNode = SlaveNode.parse(JSON.parseObject(data.getData(),JSONObject.class));
    if(slaveNode==null){
        LOGGER.error("get a null slaveNode with eventType={},path={},data={}",event.getType(),data.getPath(),data.getData());
    }else {
        switch (event.getType()) {
            case CHILD_ADDED:
                slaveNodeMap.put(slaveNode.getId(), slaveNode);
                LOGGER.info("CHILD_ADDED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            case CHILD_REMOVED:
                slaveNodeMap.remove(slaveNode.getId());
                LOGGER.info("CHILD_REMOVED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            case CHILD_UPDATED:
                slaveNodeMap.replace(slaveNode.getId(), slaveNode);
                LOGGER.info("CHILD_UPDATED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            default:
                break;
        }
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:29,代码来源:DefaultServiceDiscovery.java

示例12: processTokenRemoved

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void processTokenRemoved(ChildData data) throws IOException {
  ByteArrayInputStream bin = new ByteArrayInputStream(data.getData());
  DataInputStream din = new DataInputStream(bin);
  TokenIdent ident = createIdentifier();
  ident.readFields(din);
  synchronized (this) {
    currentTokens.remove(ident);
    // The cancel task might be waiting
    notifyAll();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:12,代码来源:ZKDelegationTokenSecretManager.java

示例13: get

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
@Override
public String get(final String key) {
	TreeCache cache = findTreeCache(key);
	if (null == cache) {
		return getDirectly(key);
	}
	ChildData resultInCache = cache.getCurrentData(key);
	if (null != resultInCache) {
		return null == resultInCache.getData() ? null : new String(resultInCache.getData(), StandardCharsets.UTF_8);
	}
	return getDirectly(key);
}
 
开发者ID:imadcn,项目名称:idworker,代码行数:13,代码来源:ZookeeperRegistryCenter.java

示例14: get

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
@Override
public String get(final String key) {
    TreeCache cache = findTreeCache(key);
    if (null == cache) {
        return getDirectly(key);
    }
    ChildData resultInCache = cache.getCurrentData(key);
    if (null != resultInCache) {
        return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
    }
    return getDirectly(key);
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:13,代码来源:ZookeeperRegistryCenter.java

示例15: refreshConfiguration

import org.apache.curator.framework.recipes.cache.ChildData; //导入方法依赖的package包/类
private void refreshConfiguration() throws IOException {
  LOGGER.info("Refreshing configuration from ZooKeeper");
  byte[] data = null;
  ChildData childData = agentNodeCache.getCurrentData();
  if (childData != null) {
    data = childData.getData();
  }
  flumeConfiguration = configFromBytes(data);
  eventBus.post(getConfiguration());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:11,代码来源:PollingZooKeeperConfigurationProvider.java


注:本文中的org.apache.curator.framework.recipes.cache.ChildData.getData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。