类 NodeSelectorSlot

java.lang.Object
com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot<Object>
com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot
所有已实现的接口:
ProcessorSlot<Object>

@Spi(isSingleton=false, order=-10000) public class NodeSelectorSlot extends AbstractLinkedProcessorSlot<Object>

This class will try to build the calling traces via
  1. adding a new DefaultNode if needed as the last child in the context. The context's last node is the current node or the parent node of the context.
  2. setting itself to the context current node.

It works as follow:

 ContextUtil.enter("entrance1", "appA");
 Entry nodeA = SphU.entry("nodeA");
 if (nodeA != null) {
     nodeA.exit();
 }
 ContextUtil.exit();
 
Above code will generate the following invocation structure in memory:

              machine-root
                  /
                 /
           EntranceNode1
               /
              /
        DefaultNode(nodeA)- - - - - -> ClusterNode(nodeA);
 

Here the EntranceNode represents "entrance1" given by ContextUtil.enter("entrance1", "appA").

Both DefaultNode(nodeA) and ClusterNode(nodeA) holds statistics of "nodeA", which is given by SphU.entry("nodeA")

The ClusterNode is uniquely identified by the ResourceId; the DefaultNode is identified by both the resource id and Context. In other words, one resource id will generate multiple DefaultNode for each distinct context, but only one ClusterNode.

the following code shows one resource id in two different context:

    ContextUtil.enter("entrance1", "appA");
    Entry nodeA = SphU.entry("nodeA");
    if (nodeA != null) {
        nodeA.exit();
    }
    ContextUtil.exit();

    ContextUtil.enter("entrance2", "appA");
    nodeA = SphU.entry("nodeA");
    if (nodeA != null) {
        nodeA.exit();
    }
    ContextUtil.exit();
 
Above code will generate the following invocation structure in memory:

                  machine-root
                  /         \
                 /           \
         EntranceNode1   EntranceNode2
               /               \
              /                 \
      DefaultNode(nodeA)   DefaultNode(nodeA)
             |                    |
             +- - - - - - - - - - +- - - - - - -> ClusterNode(nodeA);
 

As we can see, two DefaultNode are created for "nodeA" in two context, but only one ClusterNode is created.

We can also check this structure by calling:
curl http://localhost:8719/tree?type=root

作者:
jialiang.linjl
另请参阅:
  • 构造器详细资料

    • NodeSelectorSlot

      public NodeSelectorSlot()
  • 方法详细资料

    • entry

      public void entry(Context context, ResourceWrapper resourceWrapper, Object obj, int count, boolean prioritized, Object... args) throws Throwable
      从接口复制的说明: ProcessorSlot
      Entrance of this slot.
      参数:
      context - current Context
      resourceWrapper - current resource
      obj - generics parameter, usually is a Node
      count - tokens needed
      prioritized - whether the entry is prioritized
      args - parameters of the original call
      抛出:
      Throwable - blocked exception or unexpected error
    • exit

      public void exit(Context context, ResourceWrapper resourceWrapper, int count, Object... args)
      从接口复制的说明: ProcessorSlot
      Exit of this slot.
      参数:
      context - current Context
      resourceWrapper - current resource
      count - tokens needed
      args - parameters of the original call