當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。