本文整理汇总了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();
}
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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());
}