本文整理匯總了Java中org.apache.twill.zookeeper.NodeData.getData方法的典型用法代碼示例。如果您正苦於以下問題:Java NodeData.getData方法的具體用法?Java NodeData.getData怎麽用?Java NodeData.getData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.twill.zookeeper.NodeData
的用法示例。
在下文中一共展示了NodeData.getData方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: instanceNodeUpdated
import org.apache.twill.zookeeper.NodeData; //導入方法依賴的package包/類
@Override
protected void instanceNodeUpdated(NodeData nodeData) {
if (nodeData == null || nodeData.getData() == null) {
LOG.warn("Instance node was updated but data is null.");
return;
}
try {
Gson gson = new Gson();
JsonElement json = gson.fromJson(new String(nodeData.getData(), Charsets.UTF_8), JsonElement.class);
if (json.isJsonObject()) {
JsonElement data = json.getAsJsonObject().get("data");
if (data != null) {
this.liveData = gson.fromJson(data, ContainerLiveNodeData.class);
LOG.info("Container LiveNodeData updated: " + new String(nodeData.getData(), Charsets.UTF_8));
}
}
} catch (Throwable t) {
LOG.warn("Error deserializing updated instance node data", t);
}
}
示例2: decode
import org.apache.twill.zookeeper.NodeData; //導入方法依賴的package包/類
/**
* Decodes the {@link ApplicationMasterLiveNodeData} from the given ZK node data.
*
* @return the {@link ApplicationMasterLiveNodeData} or {@code null} if failed to decode.
*/
@Nullable
static ApplicationMasterLiveNodeData decode(@Nullable NodeData nodeData) {
byte[] data = nodeData == null ? null : nodeData.getData();
if (data == null) {
return null;
}
JsonElement json = GSON.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
if (!json.isJsonObject()) {
LOG.warn("Unable to decode live data node.");
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
json = jsonObj.get("data");
if (json == null || !json.isJsonObject()) {
LOG.warn("Property data not found in live data node.");
return null;
}
try {
return GSON.fromJson(json, ApplicationMasterLiveNodeData.class);
} catch (Exception e) {
LOG.warn("Failed to decode application live node data.", e);
return null;
}
}
示例3: decodeNodeData
import org.apache.twill.zookeeper.NodeData; //導入方法依賴的package包/類
/**
* Gson decode the NodeData into object.
* @param nodeData The data to decode
* @param type Object class to decode into.
* @param <T> Type of the object.
* @return The decoded object or {@code null} if node data is null.
*/
private <T> T decodeNodeData(NodeData nodeData, Class<T> type) {
byte[] data = nodeData == null ? null : nodeData.getData();
if (data == null) {
return null;
}
return GSON.fromJson(new String(data, Charsets.UTF_8), type);
}
示例4: getApplicationId
import org.apache.twill.zookeeper.NodeData; //導入方法依賴的package包/類
/**
* Decodes application ID stored inside the node data.
* @param nodeData The node data to decode from. If it is {@code null}, this method would return {@code null}.
* @return The ApplicationId or {@code null} if failed to decode.
*/
private ApplicationId getApplicationId(NodeData nodeData) {
byte[] data = nodeData == null ? null : nodeData.getData();
if (data == null) {
return null;
}
Gson gson = new Gson();
JsonElement json = gson.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
if (!json.isJsonObject()) {
LOG.warn("Unable to decode live data node.");
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
json = jsonObj.get("data");
if (!json.isJsonObject()) {
LOG.warn("Property data not found in live data node.");
return null;
}
try {
ApplicationMasterLiveNodeData amLiveNode = gson.fromJson(json, ApplicationMasterLiveNodeData.class);
return YarnUtils.createApplicationId(amLiveNode.getAppIdClusterTime(), amLiveNode.getAppId());
} catch (Exception e) {
LOG.warn("Failed to decode application live node data.", e);
return null;
}
}