提交 7e17692d 编写于 作者: P pengys5

add comment

上级 753cb284
......@@ -20,7 +20,6 @@ import org.skywalking.apm.collector.worker.segment.entity.SegmentDeserialize;
/**
* @author pengys5
*/
public abstract class AbstractPost extends AbstractLocalAsyncWorker {
public AbstractPost(Role role, ClusterWorkerContext clusterContext, LocalWorkerContext selfContext) {
......@@ -43,6 +42,16 @@ public abstract class AbstractPost extends AbstractLocalAsyncWorker {
this.ownerWorkerRef = ownerWorkerRef;
}
/**
* Get segment's buffer from request then execute deserialize operation.
*
* @param request an {@link HttpServletRequest} object that contains the request the client has made of the
* servlet
* @param response {@link HttpServletResponse} object that contains the response the servlet sends to the
* client
* @throws ServletException if the request for the POST could not be handled
* @throws IOException if an input or output error is detected when the servlet handles the request
*/
@Override final protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
JsonObject resJson = new JsonObject();
......@@ -57,6 +66,13 @@ public abstract class AbstractPost extends AbstractLocalAsyncWorker {
}
}
/**
* Read segment's buffer from buffer reader by stream mode. when finish read one segment then send to analysis.
* This method in there, so post servlet just can receive segments data.
*
* @param bufferedReader an {@link BufferedReader} object that contains the segment's data using the construct of chars.
* @throws Exception
*/
private void streamReader(BufferedReader bufferedReader) throws Exception {
Segment segment;
do {
......
......@@ -8,18 +8,36 @@ import java.util.ArrayList;
import java.util.List;
/**
* The <code>SegmentDeserialize</code> provides single segment json string deserialize and segment array file
* deserialize.
*
* @author pengys5
* @since v3.0-2017
*/
public enum SegmentDeserialize {
INSTANCE;
private final Gson gson = new Gson();
/**
* Single segment json string deserialize.
*
* @param singleSegmentJsonStr a segment json string
* @return an {@link Segment}
* @throws IOException if json string illegal or file broken.
*/
public Segment deserializeSingle(String singleSegmentJsonStr) throws IOException {
Segment segment = gson.fromJson(singleSegmentJsonStr, Segment.class);
return segment;
}
/**
* Read a json array file contains multiple segments.
*
* @param segmentJsonFile a segments json array file path
* @return on {@link List<Segment>}
* @throws Exception if json data illegal or file broken.
*/
public List<Segment> deserializeMultiple(String segmentJsonFile) throws Exception {
List<Segment> segmentList = new ArrayList<>();
streamReader(segmentList, new FileReader(segmentJsonFile));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册