类 SphU
java.lang.Object
com.alibaba.csp.sentinel.SphU
The fundamental Sentinel API for recording statistics and performing rule checking for resources.
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,
a BlockException will be thrown.
To configure the criteria, we can use XxxRuleManager.loadRules() to load rules.
Following code is an example, "abc" represent a unique name for the
protected resource:
public void foo() {
Entry entry = null;
try {
entry = SphU.entry("abc");
// resource that need protection
} catch (BlockException blockException) {
// when goes there, it is blocked
// add blocked handle logic here
} catch (Throwable bizException) {
// business exception
Tracer.trace(bizException);
} finally {
// ensure finally be executed
if (entry != null){
entry.exit();
}
}
}
Make sure SphU.entry() and Entry.exit() be paired in the same thread,
otherwise ErrorEntryFreeException will be thrown.
- 作者:
- jialiang.linjl, Eric Zhao
- 另请参阅:
-
方法概要
修饰符和类型方法说明static AsyncEntryasyncEntry(String name) Record statistics and check all rules of the resource that indicates an async invocation.static AsyncEntryasyncEntry(String name, int resourceType, EntryType trafficType) Record statistics and perform rule checking for the given resource that indicates an async invocation.static AsyncEntryasyncEntry(String name, int resourceType, EntryType trafficType, int batchCount, Object[] args) Record statistics and perform rule checking for the given resource that indicates an async invocation.static AsyncEntryasyncEntry(String name, int resourceType, EntryType trafficType, Object[] args) Record statistics and perform rule checking for the given resource that indicates an async invocation.static AsyncEntryasyncEntry(String name, EntryType trafficType) Record statistics and check all rules of the resource that indicates an async invocation.static AsyncEntryasyncEntry(String name, EntryType trafficType, int batchCount, Object... args) Record statistics and check all rules of the resource that indicates an async invocation.static EntryChecking allRules about the protected method.static EntryChecking allRules about the protected method.static EntryChecking allRules about the protected method.static EntryChecking allRules about the protected method.static EntryChecking allRules about the protected method.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryRecord statistics and perform rule checking for the given resource.static EntryentryWithPriority(String name) Record statistics and perform rule checking for the given resource.static EntryentryWithPriority(String name, EntryType trafficType) Record statistics and perform rule checking for the given resource.
-
方法详细资料
-
entry
Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name of the protected resource- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Checking allRules about the protected method.- 参数:
method- the protected method- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Checking allRules about the protected method.- 参数:
method- the protected methodbatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Record statistics and perform rule checking for the given resource.- 参数:
name- the unique string for the resourcebatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Checking allRules about the protected method.- 参数:
method- the protected methodtrafficType- 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 bySystemRule- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRule- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
public static Entry entry(Method method, EntryType trafficType, int batchCount) throws BlockException Checking allRules about the protected method.- 参数:
method- the protected methodtrafficType- 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 bySystemRulebatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRulebatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
public static Entry entry(Method method, EntryType trafficType, int batchCount, Object... args) throws BlockException Checking allRules about the protected method.- 参数:
method- the protected methodtrafficType- 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 bySystemRulebatchCount- 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- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
entry
public static Entry entry(String name, EntryType trafficType, int batchCount, Object... args) throws BlockException Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRulebatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)args- args for parameter flow control- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)
-
asyncEntry
Record statistics and check all rules of the resource that indicates an async invocation.- 参数:
name- the unique name of the protected resource- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 0.2.0
-
asyncEntry
Record statistics and check all rules of the resource that indicates an async invocation.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRule- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 0.2.0
-
asyncEntry
public static AsyncEntry asyncEntry(String name, EntryType trafficType, int batchCount, Object... args) throws BlockException Record statistics and check all rules of the resource that indicates an async invocation.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRulebatchCount- the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)args- args for parameter flow control- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 0.2.0
-
entryWithPriority
Record statistics and perform rule checking for the given resource. The entry is prioritized.- 参数:
name- the unique name for the protected resource- 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.4.0
-
entryWithPriority
Record statistics and perform rule checking for the given resource. The entry is prioritized.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRule- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.4.0
-
entry
public static Entry entry(String name, int resourceType, EntryType trafficType) throws BlockException Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name for the protected resourceresourceType- classification of the resource (e.g. Web or RPC)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 bySystemRule- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.7.0
-
entry
public static Entry entry(String name, int resourceType, EntryType trafficType, Object[] args) throws BlockException Record statistics and perform rule checking for the given resource.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRuleresourceType- classification of the resource (e.g. Web or RPC)args- args for parameter flow control or customized slots- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.7.0
-
asyncEntry
public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType) throws BlockException Record statistics and perform rule checking for the given resource that indicates an async invocation.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRuleresourceType- classification of the resource (e.g. Web or RPC)- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.7.0
-
asyncEntry
public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType, Object[] args) throws BlockException Record statistics and perform rule checking for the given resource that indicates an async invocation.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRuleresourceType- classification of the resource (e.g. Web or RPC)args- args for parameter flow control or customized slots- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.7.0
-
asyncEntry
public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType, int batchCount, Object[] args) throws BlockException Record statistics and perform rule checking for the given resource that indicates an async invocation.- 参数:
name- the unique name for the protected resourcetrafficType- 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 bySystemRuleresourceType- classification of the resource (e.g. Web or RPC)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- 返回:
- the
Entryof this invocation (used for mark the invocation complete and get context data) - 抛出:
BlockException- if the block criteria is met (e.g. metric exceeded the threshold of any rules)- 从以下版本开始:
- 1.7.0
-