类 SphO

java.lang.Object
com.alibaba.csp.sentinel.SphO

public class SphO extends Object
Conceptually, physical or logical resource that need protection should be surrounded by an entry. The requests to this resource will be blocked if any criteria is met, eg. when any Rule's threshold is exceeded. Once blocked, SphO#entry() will return false.

To configure the criteria, we can use XXXRuleManager.loadRules() to add rules. eg. FlowRuleManager.loadRules(List), DegradeRuleManager.loadRules(List), SystemRuleManager.loadRules(List).

Following code is an example. "abc" represent a unique name for the protected resource:

 public void foo() {
    if (SphO.entry("abc")) {
        try {
            // business logic
        } finally {
            SphO.exit(); // must exit()
        }
    } else {
        // failed to enter the protected resource.
    }
 }
 
Make sure SphO.entry() and exit() be paired in the same thread, otherwise ErrorEntryFreeException will be thrown.
作者:
jialiang.linjl, leyou, Eric Zhao
另请参阅:
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static boolean
    entry(Method method)
    Checking all Rules about the protected method.
    static boolean
    entry(Method method, int batchCount)
    Checking all Rules about the protected method.
    static boolean
    entry(Method method, EntryType type)
    Checking all Rules about the protected method.
    static boolean
    entry(Method method, EntryType type, int count)
    Checking all Rules about the protected method.
    static boolean
    entry(Method method, EntryType trafficType, int batchCount, Object... args)
    Record statistics and perform rule checking for the given method resource.
    static boolean
    entry(String name)
    Record statistics and perform rule checking for the given resource.
    static boolean
    entry(String name, int batchCount)
    Record statistics and perform rule checking for the given resource.
    static boolean
    entry(String name, EntryType type)
    Record statistics and perform rule checking for the given resource.
    static boolean
    entry(String name, EntryType type, int count)
    Record statistics and perform rule checking for the given resource.
    static boolean
    entry(String name, EntryType trafficType, int batchCount, Object... args)
    Record statistics and perform rule checking for the given resource.
    static void
     
    static void
    exit(int count)
     
    static void
    exit(int count, Object... args)
     

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • SphO

      public SphO()
  • 方法详细资料

    • entry

      public static boolean entry(String name)
      Record statistics and perform rule checking for the given resource.
      参数:
      name - the unique name of the protected resource
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(Method method)
      Checking all Rules about the protected method.
      参数:
      method - the protected method
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(Method method, int batchCount)
      Checking all Rules about the protected method.
      参数:
      method - the protected method
      batchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(String name, int batchCount)
      Record statistics and perform rule checking for the given resource.
      参数:
      name - the unique string for the resource
      batchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(Method method, EntryType type)
      Checking all Rules about the protected method.
      参数:
      method - the protected method
      type - the resource is an inbound or an outbound method. This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(String name, EntryType type)
      Record statistics and perform rule checking for the given resource.
      参数:
      name - the unique name for the protected resource
      type - the resource is an inbound or an outbound method. This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(Method method, EntryType type, int count)
      Checking all Rules about the protected method.
      参数:
      method - the protected method
      type - the resource is an inbound or an outbound method. This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      count - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(String name, EntryType type, int count)
      Record statistics and perform rule checking for the given resource.
      参数:
      name - the unique name for the protected resource
      type - the resource is an inbound or an outbound method. This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      count - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(String name, EntryType trafficType, int batchCount, Object... args)
      Record statistics and perform rule checking for the given resource.
      参数:
      name - the unique name for the protected resource
      trafficType - the traffic type (inbound, outbound or internal). This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      batchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      args - args for parameter flow control or customized slots
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • entry

      public static boolean entry(Method method, EntryType trafficType, int batchCount, Object... args)
      Record statistics and perform rule checking for the given method resource.
      参数:
      method - the protected method
      trafficType - the traffic type (inbound, outbound or internal). This is used to mark whether it can be blocked when the system is unstable, only inbound traffic could be blocked by SystemRule
      batchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)
      args - args for parameter flow control or customized slots
      返回:
      true if no rule's threshold is exceeded, otherwise return false.
    • exit

      public static void exit(int count, Object... args)
    • exit

      public static void exit(int count)
    • exit

      public static void exit()