浏览代码

demo: Update slot chain SPI demo (#1581)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>
master
ZhiQiang Gu GitHub 4 年前
父节点
当前提交
5e1a443663
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 4 个文件被更改,包括 10 次插入14 次删除
  1. +3
    -1
      sentinel-demo/sentinel-demo-slot-chain-spi/src/main/java/com/alibaba/csp/sentinel/demo/slot/DemoSlot.java
  2. +5
    -11
      sentinel-demo/sentinel-demo-slot-chain-spi/src/main/java/com/alibaba/csp/sentinel/demo/slot/DemoSlotChainBuilder.java
  3. +2
    -0
      sentinel-demo/sentinel-demo-slot-chain-spi/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.slotchain.ProcessorSlot
  4. +0
    -2
      sentinel-demo/sentinel-demo-slot-chain-spi/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.slotchain.SlotChainBuilder

+ 3
- 1
sentinel-demo/sentinel-demo-slot-chain-spi/src/main/java/com/alibaba/csp/sentinel/demo/slot/DemoSlot.java 查看文件

@@ -19,17 +19,19 @@ import com.alibaba.csp.sentinel.context.Context;
import com.alibaba.csp.sentinel.node.DefaultNode;
import com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot;
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
import com.alibaba.csp.sentinel.spi.SpiOrder;

/**
* An example slot that records current context and entry resource.
*
* @author Eric Zhao
*/
@SpiOrder(-3500)
public class DemoSlot extends AbstractLinkedProcessorSlot<DefaultNode> {

@Override
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args)
throws Throwable {
throws Throwable {
System.out.println("Current context: " + context.getName());
System.out.println("Current entry resource: " + context.getCurEntry().getResourceWrapper().getName());



+ 5
- 11
sentinel-demo/sentinel-demo-slot-chain-spi/src/main/java/com/alibaba/csp/sentinel/demo/slot/DemoSlotChainBuilder.java 查看文件

@@ -20,17 +20,11 @@ import com.alibaba.csp.sentinel.slotchain.SlotChainBuilder;
import com.alibaba.csp.sentinel.slots.DefaultSlotChainBuilder;

/**
* An example slot chain builder. To activate this slot chain builder,
* add the class name to corresponding SPI file in `resource/META-INF/services` directory.
*
* @author Eric Zhao
*
* @deprecated since 1.7.2, we can use @SpiOrder(-3500) to adjust the order of {@link DemoSlot},
* this class is reserved for compatibility with older versions.
*/
public class DemoSlotChainBuilder implements SlotChainBuilder {

@Override
public ProcessorSlotChain build() {
ProcessorSlotChain chain = new DefaultSlotChainBuilder().build();
chain.addLast(new DemoSlot());
return chain;
}
@Deprecated
public class DemoSlotChainBuilder extends DefaultSlotChainBuilder {
}

+ 2
- 0
sentinel-demo/sentinel-demo-slot-chain-spi/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.slotchain.ProcessorSlot 查看文件

@@ -0,0 +1,2 @@
# Custom slot processor
com.alibaba.csp.sentinel.demo.slot.DemoSlot

+ 0
- 2
sentinel-demo/sentinel-demo-slot-chain-spi/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.slotchain.SlotChainBuilder 查看文件

@@ -1,2 +0,0 @@
# Custom slot chain builder
com.alibaba.csp.sentinel.demo.slot.DemoSlotChainBuilder

正在加载...
取消
保存