public class SphU extends Object
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.
SphO| Modifier and Type | Method and Description |
|---|---|
static AsyncEntry |
asyncEntry(String name)
Record statistics and check all rules of the resource that indicates an async invocation.
|
static AsyncEntry |
asyncEntry(String name,
EntryType trafficType)
Record statistics and check all rules of the resource that indicates an async invocation.
|
static AsyncEntry |
asyncEntry(String name,
EntryType trafficType,
int batchCount,
Object... args)
Record statistics and check all rules of the resource that indicates an async invocation.
|
static AsyncEntry |
asyncEntry(String name,
int resourceType,
EntryType trafficType)
Record statistics and perform rule checking for the given resource that indicates an async invocation.
|
static AsyncEntry |
asyncEntry(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 AsyncEntry |
asyncEntry(String name,
int resourceType,
EntryType trafficType,
Object[] args)
Record statistics and perform rule checking for the given resource that indicates an async invocation.
|
static Entry |
entry(Method method)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType trafficType)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType trafficType,
int batchCount)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType trafficType,
int batchCount,
Object... args)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
int batchCount)
Checking all
Rules about the protected method. |
static Entry |
entry(String name)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
EntryType trafficType)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
EntryType trafficType,
int batchCount)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
EntryType trafficType,
int batchCount,
Object... args)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
int batchCount)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
int resourceType,
EntryType trafficType)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entry(String name,
int resourceType,
EntryType trafficType,
Object[] args)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entryWithPriority(String name)
Record statistics and perform rule checking for the given resource.
|
static Entry |
entryWithPriority(String name,
EntryType trafficType)
Record statistics and perform rule checking for the given resource.
|
public static Entry entry(String name) throws BlockException
name - the unique name of the protected resourceEntry of 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)public static Entry entry(Method method) throws BlockException
Rules about the protected method.method - the protected methodEntry of 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)public static Entry entry(Method method, int batchCount) throws BlockException
Rules about the protected method.method - the protected methodbatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)Entry of 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)public static Entry entry(String name, int batchCount) throws BlockException
name - the unique string for the resourcebatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)Entry of 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)public static Entry entry(Method method, EntryType trafficType) throws BlockException
Rules 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 by SystemRuleBlockException - if the block criteria is met (e.g. metric exceeded the threshold of any rules)public static Entry entry(String name, EntryType trafficType) throws BlockException
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 by SystemRuleBlockException - if the block criteria is met (e.g. metric exceeded the threshold of any rules)public static Entry entry(Method method, EntryType trafficType, int batchCount) throws BlockException
Rules 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 by SystemRulebatchCount - 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)public static Entry entry(String name, EntryType trafficType, int batchCount) throws BlockException
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 by SystemRulebatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)Entry of 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)public static Entry entry(Method method, EntryType trafficType, int batchCount, Object... args) throws BlockException
Rules 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 by SystemRulebatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)args - args for parameter flow control or customized slotsEntry of 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)public static Entry entry(String name, EntryType trafficType, int batchCount, Object... args) throws BlockException
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 by SystemRulebatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)args - args for parameter flow controlBlockException - if the block criteria is met (e.g. metric exceeded the threshold of any rules)public static AsyncEntry asyncEntry(String name) throws BlockException
name - the unique name of the protected resourceBlockException - if the block criteria is met (e.g. metric exceeded the threshold of any rules)public static AsyncEntry asyncEntry(String name, EntryType trafficType) throws BlockException
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 by SystemRuleEntry of 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)public static AsyncEntry asyncEntry(String name, EntryType trafficType, int batchCount, Object... args) throws BlockException
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 by SystemRulebatchCount - the amount of calls within the invocation (e.g. batchCount=2 means request for 2 tokens)args - args for parameter flow controlEntry of 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)public static Entry entryWithPriority(String name) throws BlockException
name - the unique name for the protected resourceBlockException - if the block criteria is met (e.g. metric exceeded the threshold of any rules)public static Entry entryWithPriority(String name, EntryType trafficType) throws BlockException
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 by SystemRuleEntry of 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)public static Entry entry(String name, int resourceType, EntryType trafficType) throws BlockException
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 by SystemRuleEntry of 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)public static Entry entry(String name, int resourceType, EntryType trafficType, Object[] args) throws BlockException
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 by SystemRuleresourceType - classification of the resource (e.g. Web or RPC)args - args for parameter flow control or customized slotsEntry of 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)public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType) throws BlockException
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 by SystemRuleresourceType - classification of the resource (e.g. Web or RPC)Entry of 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)public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType, Object[] args) throws BlockException
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 by SystemRuleresourceType - classification of the resource (e.g. Web or RPC)args - args for parameter flow control or customized slotsEntry of 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)public static AsyncEntry asyncEntry(String name, int resourceType, EntryType trafficType, int batchCount, Object[] args) throws BlockException
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 by SystemRuleresourceType - 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 slotsEntry of 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)Copyright © 2021 Alibaba Group. All rights reserved.