Procházet zdrojové kódy

Remove useless global NodeBuilder in Env class

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao před 5 roky
rodič
revize
468327bdcd
7 změnil soubory, kde provedl 14 přidání a 135 odebrání
  1. +11
    -7
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java
  2. +0
    -3
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/Env.java
  3. +0
    -37
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilder.java
  4. +1
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/NodeBuilder.java
  5. +1
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java
  6. +1
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java
  7. +0
    -84
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java

+ 11
- 7
sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java Zobrazit soubor

@@ -38,26 +38,30 @@ public final class Constants {
public final static String ROOT_ID = "machine-root";
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__";

/**
* Global ROOT statistic node that represents the universal parent node.
*/
public final static DefaultNode ROOT = new EntranceNode(new StringResourceWrapper(ROOT_ID, EntryType.IN),
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();

/**
* Response time that exceeds TIME_DROP_VALVE will be calculated as TIME_DROP_VALVE.
* Default value is 4900 ms
* It can be configured by property file or JVM parameter -Dcsp.sentinel.statistic.max.rt=xxx
* See {@link SentinelConfig#statisticMaxRt()}
* Response time that exceeds TIME_DROP_VALVE will be calculated as TIME_DROP_VALVE. Default value is 4900 ms.
* It can be configured by property file or JVM parameter via {@code -Dcsp.sentinel.statistic.max.rt=xxx}.
*/
public static int TIME_DROP_VALVE = SentinelConfig.statisticMaxRt();
public static final int TIME_DROP_VALVE = SentinelConfig.statisticMaxRt();

/**
* The global switch for Sentinel.
*/
public static volatile boolean ON = true;
}
}

+ 0
- 3
sentinel-core/src/main/java/com/alibaba/csp/sentinel/Env.java Zobrazit soubor

@@ -16,8 +16,6 @@
package com.alibaba.csp.sentinel;

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.
@@ -31,7 +29,6 @@ import com.alibaba.csp.sentinel.node.NodeBuilder;
*/
public class Env {

public static final NodeBuilder nodeBuilder = new DefaultNodeBuilder();
public static final Sph sph = new CtSph();

static {


+ 0
- 37
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilder.java Zobrazit soubor

@@ -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();
}

}

+ 1
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/NodeBuilder.java Zobrazit soubor

@@ -22,6 +22,7 @@ import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
*
* @author qinan.qn
*/
@Deprecated
public interface NodeBuilder {

/**


+ 1
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/clusterbuilder/ClusterBuilderSlot.java Zobrazit soubor

@@ -18,7 +18,6 @@ package com.alibaba.csp.sentinel.slots.clusterbuilder;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.csp.sentinel.Env;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.context.Context;
import com.alibaba.csp.sentinel.context.ContextUtil;
@@ -79,7 +78,7 @@ public class ClusterBuilderSlot extends AbstractLinkedProcessorSlot<DefaultNode>
synchronized (lock) {
if (clusterNode == null) {
// Create the cluster node.
clusterNode = Env.nodeBuilder.buildClusterNode();
clusterNode = new ClusterNode();
HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<>(Math.max(clusterNodeMap.size(), 16));
newMap.putAll(clusterNodeMap);
newMap.put(node.getId(), clusterNode);


+ 1
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java Zobrazit soubor

@@ -18,7 +18,6 @@ package com.alibaba.csp.sentinel.slots.nodeselector;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.csp.sentinel.Env;
import com.alibaba.csp.sentinel.context.Context;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.node.ClusterNode;
@@ -156,7 +155,7 @@ public class NodeSelectorSlot extends AbstractLinkedProcessorSlot<Object> {
synchronized (this) {
node = map.get(context.getName());
if (node == null) {
node = Env.nodeBuilder.buildTreeNode(resourceWrapper, null);
node = new DefaultNode(resourceWrapper, null);
HashMap<String, DefaultNode> cacheMap = new HashMap<String, DefaultNode>(map.size());
cacheMap.putAll(map);
cacheMap.put(context.getName(), node);


+ 0
- 84
sentinel-core/src/test/java/com/alibaba/csp/sentinel/node/DefaultNodeBuilderTest.java Zobrazit soubor

@@ -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);
}
}

Načítá se…
Zrušit
Uložit