本文整理汇总了Java中org.apache.curator.framework.recipes.cache.ChildData类的典型用法代码示例。如果您正苦于以下问题:Java ChildData类的具体用法?Java ChildData怎么用?Java ChildData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChildData类属于org.apache.curator.framework.recipes.cache包,在下文中一共展示了ChildData类的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: addChild
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
/**
* add instance;
*
* @param data
*/
private void addChild(ChildData data) {
if (data == null
|| ArrayUtils.isEmpty(data.getData())) {
return;
}
try {
ServiceInstance<RpcPayload> instance = serializer.deserialize(data
.getData());
this.onInstanceAdded(instance);
} catch (Exception ex) {
LOG.error("Could not add zk node " + data.getPath() + " to pool.",
ex);
}
}
示例3: childEvent
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
ChildData data = event.getData();
switch (event.getType()) {
case CHILD_ADDED:
add(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()) ;
break;
case CHILD_REMOVED:
delete(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()); ;
break;
case CHILD_UPDATED:
add(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()) ;
break;
default:
break;
}
}
示例4: startInitialTasks
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
private void startInitialTasks()
{
if( !startedInitialTasks )
{
List<ChildData> currentData = taskCache.getCurrentData();
List<String> taskIds = Lists.newArrayList();
for( ChildData task : currentData )
{
String taskId = ZKPaths.getNodeFromPath(task.getPath());
LOGGER.debug("Task added " + taskId);
taskIds.add(taskId);
addRunner(taskId);
}
requestFullStatus(taskIds);
startedInitialTasks = true;
}
}
示例5: onChanged
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void onChanged(TreeCacheEvent event) {
ChildData data = event.getData();
if (data == null) {
return;
}
String path = data.getPath();
switch (event.getType()) {
case NODE_ADDED:
case NODE_REMOVED:
case NODE_UPDATED: {
boolean isFullHostPath = StringUtils.isNotBlank(path) && path.split(RedirectorConstants.DELIMETER).length == 7;
if (isFullHostPath && path.contains(RedirectorConstants.DELIMETER + applicationName + RedirectorConstants.DELIMETER)) {
snapshotNeeded = true;
}
break;
}
}
}
示例6: 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;
}
示例7: getCurrentDataVersion
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public int getCurrentDataVersion() {
int result = RedirectorConstants.NO_MODEL_NODE_VERSION;
if (isCacheUsageAllowed()) {
ChildData data = cache.getCurrentData();
if (data != null && data.getStat() != null) {
result = data.getStat().getVersion();
}
} else {
try {
if (connector.isPathExists(path)) {
result = connector.getNodeVersion(path);
} else {
log.warn("Node {} does not exist", path);
}
} catch (DataSourceConnectorException e) {
log.error("Failed to get data for zkPath={} {}", path, e);
}
}
return result;
}
示例8: Namespaces
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
/**
* Create a zookeeper-based namespace service
* @param client the curator client
* @param cache the treecache
* @param filePath the file
*/
public Namespaces(final CuratorFramework client, final TreeCache cache, final String filePath) {
requireNonNull(cache, "TreeCache may not be null!");
this.client = client;
this.cache = cache;
try {
this.client.create().orSetData().forPath(ZNODE_NAMESPACES);
this.cache.getListenable().addListener((c, e) -> {
final Map<String, ChildData> tree = cache.getCurrentChildren(ZNODE_NAMESPACES);
readTree(tree).forEach(data::put);
});
init(filePath).forEach(data::put);
} catch (final Exception ex) {
LOGGER.error("Could not create a zk node cache: {}", ex);
throw new RuntimeTrellisException(ex);
}
}
示例9: childEvent
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
ChildData childData = event.getData();
switch (event.getType()) {
case CHILD_ADDED:
try {
lockTableByNewNode(childData);
} catch (Exception e) {
LOGGER.info("CHILD_ADDED error", e);
}
break;
case CHILD_UPDATED:
updateMeta(childData);
break;
case CHILD_REMOVED:
deleteNode(childData);
break;
default:
break;
}
}
示例10: 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;
}
}
示例11: childEvent
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
ChildData childData = event.getData();
switch (event.getType()) {
case CHILD_ADDED:
createOrUpdateViewMeta(childData, false);
break;
case CHILD_UPDATED:
createOrUpdateViewMeta(childData, true);
break;
case CHILD_REMOVED:
deleteNode(childData);
break;
default:
break;
}
}
示例12: 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);
}
示例13: childEvent
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
ChildData data = event.getData();
switch (event.getType()) {
case CHILD_ADDED:
add(data, false);
break;
case CHILD_UPDATED:
add(data, true);
break;
case CHILD_REMOVED:
delete(data);
break;
default:
break;
}
}
示例14: childEvent
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework curator, TreeCacheEvent event) throws Exception {
ChildData data = event.getData();
if (data == null) return;
String dataPath = data.getPath();
if (Strings.isNullOrEmpty(dataPath)) return;
if (dataPath.startsWith(watchPath)) {
switch (event.getType()) {
case NODE_ADDED:
listener.onServiceAdded(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
case NODE_REMOVED:
listener.onServiceRemoved(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
case NODE_UPDATED:
listener.onServiceUpdated(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
}
Logs.RSD.info("ZK node data change={}, nodePath={}, watchPath={}, ns={}");
}
}
示例15: get
import org.apache.curator.framework.recipes.cache.ChildData; //导入依赖的package包/类
@Override
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) {
if (!keyIsNull(k, asyncResultHandler)) {
vertx.runOnContext(event -> {
Map<String, ChildData> maps = curatorCache.getCurrentChildren(keyPath(k));
ChoosableSet<V> choosableSet = new ChoosableSet<>(0);
if (maps != null) {
for (ChildData childData : maps.values()) {
try {
if (childData != null && childData.getData() != null && childData.getData().length > 0)
choosableSet.add(asObject(childData.getData()));
} catch (Exception ex) {
asyncResultHandler.handle(Future.failedFuture(ex));
}
}
}
asyncResultHandler.handle(Future.succeededFuture(choosableSet));
});
}
}