Fix graph.
This commit is contained in:
parent
a1423b5642
commit
515d18d899
|
|
@ -11,7 +11,7 @@ Sky Walking | [中文](README_ZH.md)
|
|||
[](http://opentracing.io)
|
||||
|
||||
* Provide Java agent, **no need to CHANGE any application source code**.
|
||||
* High performance agent. Only increase extra **10%** cpu cost in 5000+ tps application, even **When collect all traces**, [check test reports](#test-reports).
|
||||
* High performance agent. Only increase extra **10%** cpu cost in 5000+ tps application, even **when collect all traces**.
|
||||
* [Supported middlewares, frameworks and libraries](https://github.com/OpenSkywalking/sky-walking/wiki/3.2-supported-list).
|
||||
* Manual instrumentation
|
||||
* As an [OpenTracing supported tracer](http://opentracing.io/documentation/pages/supported-tracers)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
/**
|
||||
* @author peng-yongsheng, wu-sheng
|
||||
*/
|
||||
public final class Graph<Input> {
|
||||
public final class Graph<INPUT> {
|
||||
private int id;
|
||||
private Node startNode;
|
||||
private ConcurrentHashMap<Integer, Node> nodeIndex = new ConcurrentHashMap<>();
|
||||
|
|
@ -32,11 +32,11 @@ public final class Graph<Input> {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public void start(Input input) {
|
||||
startNode.execute(input);
|
||||
public void start(INPUT INPUT) {
|
||||
startNode.execute(INPUT);
|
||||
}
|
||||
|
||||
public <Output> Node<Input, Output> addNode(NodeHandler<Input, Output> nodeHandler) {
|
||||
public <OUTPUT> Node<INPUT, OUTPUT> addNode(NodeHandler<INPUT, OUTPUT> nodeHandler) {
|
||||
synchronized (this) {
|
||||
startNode = new Node(this, nodeHandler);
|
||||
return startNode;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.skywalking.apm.collector.core.framework.Executor;
|
|||
*
|
||||
* @author peng-yongsheng, wu-sheng
|
||||
*/
|
||||
public class Next<Input> implements Executor<Input> {
|
||||
public class Next<INPUT> implements Executor<INPUT> {
|
||||
|
||||
private final List<Node> nextNodes;
|
||||
|
||||
|
|
@ -42,9 +42,9 @@ public class Next<Input> implements Executor<Input> {
|
|||
/**
|
||||
* Drive to the next nodes
|
||||
*
|
||||
* @param input
|
||||
* @param INPUT
|
||||
*/
|
||||
@Override public void execute(Input input) {
|
||||
nextNodes.forEach(node -> node.execute(input));
|
||||
@Override public void execute(INPUT INPUT) {
|
||||
nextNodes.forEach(node -> node.execute(INPUT));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,39 +19,39 @@
|
|||
package org.skywalking.apm.collector.core.graph;
|
||||
|
||||
/**
|
||||
* The <code>Node</code> in the graph with explicit Input and Output types.
|
||||
* The <code>Node</code> in the graph with explicit INPUT and OUTPUT types.
|
||||
*
|
||||
* @author peng-yongsheng, wu-sheng
|
||||
*/
|
||||
public final class Node<Input, Output> {
|
||||
public final class Node<INPUT, OUTPUT> {
|
||||
private final NodeHandler nodeHandler;
|
||||
private final Next<Output> next;
|
||||
private final Next<OUTPUT> next;
|
||||
private final Graph graph;
|
||||
|
||||
Node(Graph graph, NodeHandler<Input, Output> nodeHandler) {
|
||||
Node(Graph graph, NodeHandler<INPUT, OUTPUT> nodeHandler) {
|
||||
this.graph = graph;
|
||||
this.nodeHandler = nodeHandler;
|
||||
this.next = new Next<>();
|
||||
this.graph.checkForNewNode(this);
|
||||
}
|
||||
|
||||
public final <NextOutput> Node<Output, NextOutput> addNext(NodeHandler<Output, NextOutput> nodeHandler) {
|
||||
public final <NEXTOUTPUT> Node<OUTPUT, NEXTOUTPUT> addNext(NodeHandler<OUTPUT, NEXTOUTPUT> nodeHandler) {
|
||||
synchronized (graph) {
|
||||
Node<Output, NextOutput> node = new Node<>(graph, nodeHandler);
|
||||
Node<OUTPUT, NEXTOUTPUT> node = new Node<>(graph, nodeHandler);
|
||||
next.addNext(node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
final void execute(Input input) {
|
||||
nodeHandler.process(input, next);
|
||||
final void execute(INPUT INPUT) {
|
||||
nodeHandler.process(INPUT, next);
|
||||
}
|
||||
|
||||
NodeHandler getHandler() {
|
||||
return nodeHandler;
|
||||
}
|
||||
|
||||
Next<Output> getNext() {
|
||||
Next<OUTPUT> getNext() {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ package org.skywalking.apm.collector.core.graph;
|
|||
/**
|
||||
* @author peng-yongsheng, wu-sheng
|
||||
*/
|
||||
public interface NodeHandler<Input, Output> {
|
||||
public interface NodeHandler<INPUT, OUTPUT> {
|
||||
/**
|
||||
* The unique id in the certain graph.
|
||||
*
|
||||
|
|
@ -29,5 +29,5 @@ public interface NodeHandler<Input, Output> {
|
|||
*/
|
||||
int id();
|
||||
|
||||
void process(Input input, Next<Output> next);
|
||||
void process(INPUT INPUT, Next<OUTPUT> next);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.junit.Test;
|
|||
public class GraphManagerTest {
|
||||
private static PrintStream OUT_REF;
|
||||
private ByteArrayOutputStream outputStream;
|
||||
private static String lineSeparator = System.lineSeparator();
|
||||
|
||||
@Before
|
||||
public void initAndHoldOut() {
|
||||
|
|
@ -53,8 +54,8 @@ public class GraphManagerTest {
|
|||
testGraph.start("Input String");
|
||||
|
||||
String output = outputStream.toString();
|
||||
String expected = "Node1 process: s=Input String\n" +
|
||||
"Node2 process: s=Input String\n";
|
||||
String expected = "Node1 process: s=Input String" + lineSeparator +
|
||||
"Node2 process: s=Input String" + lineSeparator;
|
||||
|
||||
Assert.assertEquals(expected, output);
|
||||
}
|
||||
|
|
@ -67,9 +68,9 @@ public class GraphManagerTest {
|
|||
graph.start("Input String");
|
||||
|
||||
String output = outputStream.toString();
|
||||
String expected = "Node1 process: s=Input String\n" +
|
||||
"Node2 process: s=Input String\n" +
|
||||
"Node4 process: int=123\n";
|
||||
String expected = "Node1 process: s=Input String" + lineSeparator +
|
||||
"Node2 process: s=Input String" + lineSeparator +
|
||||
"Node4 process: int=123" + lineSeparator;
|
||||
|
||||
Assert.assertEquals(expected, output);
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ public class GraphManagerTest {
|
|||
next.execute(123);
|
||||
String output = outputStream.toString();
|
||||
String expected =
|
||||
"Node4 process: int=123\n";
|
||||
"Node4 process: int=123" + lineSeparator;
|
||||
|
||||
Assert.assertEquals(expected, output);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue