Remove useless global NodeBuilder in Env class
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
7feaf709fc
commit
468327bdcd
|
|
@ -38,23 +38,27 @@ public final class Constants {
|
||||||
public final static String ROOT_ID = "machine-root";
|
public final static String ROOT_ID = "machine-root";
|
||||||
public final static String CONTEXT_DEFAULT_NAME = "sentinel_default_context";
|
public final static String CONTEXT_DEFAULT_NAME = "sentinel_default_context";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A virtual resource identifier for total inbound statistics (since 1.5.0).
|
||||||
|
*/
|
||||||
public final static String TOTAL_IN_RESOURCE_NAME = "__total_inbound_traffic__";
|
public final static String TOTAL_IN_RESOURCE_NAME = "__total_inbound_traffic__";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global ROOT statistic node that represents the universal parent node.
|
||||||
|
*/
|
||||||
public final static DefaultNode ROOT = new EntranceNode(new StringResourceWrapper(ROOT_ID, EntryType.IN),
|
public final static DefaultNode ROOT = new EntranceNode(new StringResourceWrapper(ROOT_ID, EntryType.IN),
|
||||||
new ClusterNode());
|
new ClusterNode());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistics for {@link SystemRule} checking.
|
* Global statistic node for inbound traffic. Usually used for {@link SystemRule} checking.
|
||||||
*/
|
*/
|
||||||
public final static ClusterNode ENTRY_NODE = new ClusterNode();
|
public final static ClusterNode ENTRY_NODE = new ClusterNode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response time that exceeds TIME_DROP_VALVE will be calculated as TIME_DROP_VALVE.
|
* Response time that exceeds TIME_DROP_VALVE will be calculated as TIME_DROP_VALVE. Default value is 4900 ms.
|
||||||
* Default value is 4900 ms
|
* It can be configured by property file or JVM parameter via {@code -Dcsp.sentinel.statistic.max.rt=xxx}.
|
||||||
* It can be configured by property file or JVM parameter -Dcsp.sentinel.statistic.max.rt=xxx
|
|
||||||
* See {@link SentinelConfig#statisticMaxRt()}
|
|
||||||
*/
|
*/
|
||||||
public static int TIME_DROP_VALVE = SentinelConfig.statisticMaxRt();
|
public static final int TIME_DROP_VALVE = SentinelConfig.statisticMaxRt();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global switch for Sentinel.
|
* The global switch for Sentinel.
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
package com.alibaba.csp.sentinel;
|
package com.alibaba.csp.sentinel;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.init.InitExecutor;
|
import com.alibaba.csp.sentinel.init.InitExecutor;
|
||||||
import com.alibaba.csp.sentinel.node.DefaultNodeBuilder;
|
|
||||||
import com.alibaba.csp.sentinel.node.NodeBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sentinel Env. This class will trigger all initialization for Sentinel.
|
* Sentinel Env. This class will trigger all initialization for Sentinel.
|
||||||
|
|
@ -31,7 +29,6 @@ import com.alibaba.csp.sentinel.node.NodeBuilder;
|
||||||
*/
|
*/
|
||||||
public class Env {
|
public class Env {
|
||||||
|
|
||||||
public static final NodeBuilder nodeBuilder = new DefaultNodeBuilder();
|
|
||||||
public static final Sph sph = new CtSph();
|
public static final Sph sph = new CtSph();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package com.alibaba.csp.sentinel.node;
|
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link NodeBuilder}.
|
|
||||||
*
|
|
||||||
* @author qinan.qn
|
|
||||||
*/
|
|
||||||
public class DefaultNodeBuilder implements NodeBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DefaultNode buildTreeNode(ResourceWrapper id, ClusterNode clusterNode) {
|
|
||||||
return new DefaultNode(id, clusterNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClusterNode buildClusterNode() {
|
|
||||||
return new ClusterNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -22,6 +22,7 @@ import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
|
||||||
*
|
*
|
||||||
* @author qinan.qn
|
* @author qinan.qn
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface NodeBuilder {
|
public interface NodeBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package com.alibaba.csp.sentinel.slots.clusterbuilder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.Env;
|
|
||||||
import com.alibaba.csp.sentinel.EntryType;
|
import com.alibaba.csp.sentinel.EntryType;
|
||||||
import com.alibaba.csp.sentinel.context.Context;
|
import com.alibaba.csp.sentinel.context.Context;
|
||||||
import com.alibaba.csp.sentinel.context.ContextUtil;
|
import com.alibaba.csp.sentinel.context.ContextUtil;
|
||||||
|
|
@ -79,7 +78,7 @@ public class ClusterBuilderSlot extends AbstractLinkedProcessorSlot<DefaultNode>
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (clusterNode == null) {
|
if (clusterNode == null) {
|
||||||
// Create the cluster node.
|
// Create the cluster node.
|
||||||
clusterNode = Env.nodeBuilder.buildClusterNode();
|
clusterNode = new ClusterNode();
|
||||||
HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<>(Math.max(clusterNodeMap.size(), 16));
|
HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<>(Math.max(clusterNodeMap.size(), 16));
|
||||||
newMap.putAll(clusterNodeMap);
|
newMap.putAll(clusterNodeMap);
|
||||||
newMap.put(node.getId(), clusterNode);
|
newMap.put(node.getId(), clusterNode);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package com.alibaba.csp.sentinel.slots.nodeselector;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.Env;
|
|
||||||
import com.alibaba.csp.sentinel.context.Context;
|
import com.alibaba.csp.sentinel.context.Context;
|
||||||
import com.alibaba.csp.sentinel.context.ContextUtil;
|
import com.alibaba.csp.sentinel.context.ContextUtil;
|
||||||
import com.alibaba.csp.sentinel.node.ClusterNode;
|
import com.alibaba.csp.sentinel.node.ClusterNode;
|
||||||
|
|
@ -156,7 +155,7 @@ public class NodeSelectorSlot extends AbstractLinkedProcessorSlot<Object> {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
node = map.get(context.getName());
|
node = map.get(context.getName());
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
node = Env.nodeBuilder.buildTreeNode(resourceWrapper, null);
|
node = new DefaultNode(resourceWrapper, null);
|
||||||
HashMap<String, DefaultNode> cacheMap = new HashMap<String, DefaultNode>(map.size());
|
HashMap<String, DefaultNode> cacheMap = new HashMap<String, DefaultNode>(map.size());
|
||||||
cacheMap.putAll(map);
|
cacheMap.putAll(map);
|
||||||
cacheMap.put(context.getName(), node);
|
cacheMap.put(context.getName(), node);
|
||||||
|
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package com.alibaba.csp.sentinel.node;
|
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.EntryType;
|
|
||||||
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
|
|
||||||
import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test cases for {@link DefaultNodeBuilder}.
|
|
||||||
*
|
|
||||||
* @author cdfive
|
|
||||||
*/
|
|
||||||
public class DefaultNodeBuilderTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildTreeNode() {
|
|
||||||
DefaultNodeBuilder builder = new DefaultNodeBuilder();
|
|
||||||
|
|
||||||
ResourceWrapper id = new StringResourceWrapper("resA", EntryType.IN);
|
|
||||||
ClusterNode clusterNode = new ClusterNode();
|
|
||||||
DefaultNode defaultNode = builder.buildTreeNode(id, clusterNode);
|
|
||||||
|
|
||||||
assertNotNull(defaultNode);
|
|
||||||
assertEquals(id, defaultNode.getId());
|
|
||||||
assertEquals(clusterNode, defaultNode.getClusterNode());
|
|
||||||
|
|
||||||
// verify each call returns a different instance
|
|
||||||
DefaultNode defaultNode2 = builder.buildTreeNode(id, clusterNode);
|
|
||||||
assertNotNull(defaultNode2);
|
|
||||||
assertNotSame(defaultNode, defaultNode2);
|
|
||||||
// now DefaultNode#equals(Object) is not implemented, they are not equal
|
|
||||||
assertNotEquals(defaultNode, defaultNode2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildTreeNodeNullClusterNode() {
|
|
||||||
DefaultNodeBuilder builder = new DefaultNodeBuilder();
|
|
||||||
|
|
||||||
ResourceWrapper id = new StringResourceWrapper("resA", EntryType.IN);
|
|
||||||
DefaultNode defaultNode = builder.buildTreeNode(id, null);
|
|
||||||
|
|
||||||
assertNotNull(defaultNode);
|
|
||||||
assertEquals(id, defaultNode.getId());
|
|
||||||
assertNull(defaultNode.getClusterNode());
|
|
||||||
|
|
||||||
// verify each call returns a different instance
|
|
||||||
DefaultNode defaultNode2 = builder.buildTreeNode(id, null);
|
|
||||||
assertNotNull(defaultNode2);
|
|
||||||
assertNotSame(defaultNode, defaultNode2);
|
|
||||||
// now DefaultNode#equals(Object) is not implemented, they are not equal
|
|
||||||
assertNotEquals(defaultNode, defaultNode2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildClusterNode() {
|
|
||||||
DefaultNodeBuilder builder = new DefaultNodeBuilder();
|
|
||||||
ClusterNode clusterNode = builder.buildClusterNode();
|
|
||||||
assertNotNull(clusterNode);
|
|
||||||
|
|
||||||
// verify each call returns a different instance
|
|
||||||
ClusterNode clusterNode2 = builder.buildClusterNode();
|
|
||||||
assertNotNull(clusterNode2);
|
|
||||||
assertNotSame(clusterNode, clusterNode2);
|
|
||||||
// as new a ClusterNode instance in DefaultNodeBuilder#buildClusterNode(), they are not equal
|
|
||||||
assertNotEquals(clusterNode, clusterNode2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue