提交 e1325615 编写于 作者: wu-sheng's avatar wu-sheng

Support to find node by id and output type. Node<?, Integer> foundNode =...

Support to find node by id and output type. Node<?, Integer> foundNode = GraphManager.INSTANCE.findGraph(6).toBuilder().findNode(2, Integer.class);
上级 381d718d
......@@ -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;
}
}
/*
* 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();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册