Support to find node by id and output type. Node<?, Integer> foundNode = GraphManager.INSTANCE.findGraph(6).toBuilder().findNode(2, Integer.class);
This commit is contained in:
parent
381d718d69
commit
e1325615dc
|
|
@ -48,7 +48,7 @@ public final class Graph<INPUT> {
|
|||
if (node == null) {
|
||||
throw new NodeNotFoundException("Can't find node with handlerId="
|
||||
+ handlerId
|
||||
+ " in graph[" + id + "】");
|
||||
+ " in graph[" + id + "]");
|
||||
}
|
||||
return node.getNext();
|
||||
}
|
||||
|
|
@ -63,4 +63,11 @@ public final class Graph<INPUT> {
|
|||
nodeIndex.put(nodeId, node);
|
||||
}
|
||||
|
||||
public GraphBuilder toBuilder(){
|
||||
return new GraphBuilder(this);
|
||||
}
|
||||
|
||||
ConcurrentHashMap<Integer, Node> getNodeIndex() {
|
||||
return nodeIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.graph;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public class GraphBuilder {
|
||||
private Graph graph;
|
||||
|
||||
GraphBuilder(Graph graph) {
|
||||
this.graph = graph;
|
||||
}
|
||||
|
||||
public <NODE_OUTPUT> Node<?, NODE_OUTPUT> findNode(int handlerId, Class<NODE_OUTPUT> outputClass) {
|
||||
ConcurrentHashMap<Integer, Node> graphNodeIndex = graph.getNodeIndex();
|
||||
Node node = graphNodeIndex.get(handlerId);
|
||||
if (node == null) {
|
||||
throw new NodeNotFoundException("Can't find node with handlerId="
|
||||
+ handlerId
|
||||
+ " in graph[" + handlerId + "]");
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
|
@ -52,4 +52,8 @@ public enum GraphManager {
|
|||
}
|
||||
return graph;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
allGraphs.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,4 +104,18 @@ public class GraphManagerTest {
|
|||
|
||||
Next next = GraphManager.INSTANCE.findGraph(5).findNext(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindNode() {
|
||||
Graph<String> graph = GraphManager.INSTANCE.createIfAbsent(6, String.class);
|
||||
graph.addNode(new Node1Processor()).addNext(new Node2Processor());
|
||||
|
||||
Node<?, Integer> foundNode = GraphManager.INSTANCE.findGraph(6).toBuilder().findNode(2, Integer.class);
|
||||
foundNode.addNext(new Node4Processor());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
GraphManager.INSTANCE.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue