import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public void loadPositions(String json) {
if (StringHelper.isEmpty(json)) {
return;
}
Long inode = 0L, pos = 0L, number = 0L;
String file = "";
JSONArray positionRecords = JSONArray.parseArray(json);
for (int i = 0; i < positionRecords.size(); i++) {
JSONObject positionObject = (JSONObject) positionRecords.get(i);
inode = positionObject.getLong("inode");
pos = positionObject.getLong("pos");
file = positionObject.getString("file");
// add line number
number = positionObject.getLongValue("num");
for (Object v : Arrays.asList(inode, pos, file)) {
Preconditions.checkNotNull(v, "Detected missing value in position file. " + "inode: " + inode
+ ", pos: " + pos + ", path: " + file);
}
TailFile tf = tailFiles.get(inode);
try {
if (tf != null && tf.updatePos(file, inode, pos, number)) {
tailFiles.put(inode, tf);
}
else {
// add old tail file into memory
maybeReloadMap.put(inode, new Long[] { pos, number });
if (log.isDebugEnable()) {
log.debug(this, "add old&inInterrupt file: " + file + ", inode: " + inode + ", pos: " + pos);
}
}
}
catch (IOException e) {
log.err(this, "TailFile updatePos FAILED.", e);
}
}
}