public class SphU extends Object
Rule's threshold is exceeded. Once blocked,
a BlockException will be thrown.
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() {
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| Constructor and Description |
|---|
SphU() |
| Modifier and Type | Method and Description |
|---|---|
static AsyncEntry |
asyncEntry(String name)
Checking all rules about the asynchronous resource.
|
static AsyncEntry |
asyncEntry(String name,
EntryType type)
Checking all
Rules about the asynchronous resource. |
static AsyncEntry |
asyncEntry(String name,
EntryType type,
int count,
Object... args)
Checking all
Rules about the asynchronous resource. |
static AsyncEntry |
asyncEntry(String name,
int resourceType,
EntryType type,
int acquireCount,
Object[] args)
Record statistics and check all rules of the resource.
|
static AsyncEntry |
asyncEntry(String name,
int resourceType,
EntryType type,
Object[] args)
Record statistics and check all rules of the resource.
|
static Entry |
entry(Method method)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType type)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType type,
int count)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
EntryType type,
int count,
Object... args)
Checking all
Rules about the protected method. |
static Entry |
entry(Method method,
int count)
Checking all
Rules about the protected method. |
static Entry |
entry(String name)
Checking all
Rules about the resource. |
static Entry |
entry(String name,
EntryType type)
Checking all
Rules about the resource. |
static Entry |
entry(String name,
EntryType type,
int count)
Checking all
Rules about the resource. |
static Entry |
entry(String name,
EntryType type,
int count,
Object... args)
Checking all
Rules about the resource. |
static Entry |
entry(String name,
int count)
Checking all
Rules about the resource. |
static Entry |
entry(String name,
int resourceType,
EntryType type)
Record statistics and check all rules of the resource.
|
static Entry |
entry(String name,
int resourceType,
EntryType type,
Object[] args)
Record statistics and check all rules of the resource.
|
static Entry |
entryWithPriority(String name)
Checking all
Rules related the resource. |
static Entry |
entryWithPriority(String name,
EntryType type)
Checking all
Rules related the resource. |
public static Entry entry(String name) throws BlockException
Rules about the resource.name - the unique name of the protected resourceBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(Method method) throws BlockException
Rules about the protected method.method - the protected methodBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(Method method, int count) throws BlockException
Rules about the protected method.method - the protected methodcount - tokens requiredBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(String name, int count) throws BlockException
Rules about the resource.name - the unique string for the resourcecount - tokens requiredBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(Method method, EntryType type) throws BlockException
Rules about the protected method.method - the protected methodtype - 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 SystemRuleBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(String name, EntryType type) throws BlockException
Rules about the resource.name - the unique name for the protected resourcetype - 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 SystemRuleBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(Method method, EntryType type, int count) throws BlockException
Rules about the protected method.method - the protected methodtype - 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 SystemRulecount - tokens requiredBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(String name, EntryType type, int count) throws BlockException
Rules about the resource.name - the unique name for the protected resourcetype - 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 SystemRulecount - tokens requiredBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(Method method, EntryType type, int count, Object... args) throws BlockException
Rules about the protected method.method - the protected methodtype - 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 SystemRulecount - tokens requiredargs - the parameters of the method.BlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(String name, EntryType type, int count, Object... args) throws BlockException
Rules about the resource.name - the unique name for the protected resourcetype - 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 SystemRulecount - tokens requiredargs - extra parameters.BlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static AsyncEntry asyncEntry(String name) throws BlockException
name - the unique name of the protected resourceBlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static AsyncEntry asyncEntry(String name, EntryType type) throws BlockException
Rules about the asynchronous resource.name - the unique name for the protected resourcetype - 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 SystemRuleBlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static AsyncEntry asyncEntry(String name, EntryType type, int count, Object... args) throws BlockException
Rules about the asynchronous resource.name - the unique name for the protected resourcetype - 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 SystemRulecount - tokens requiredargs - extra parametersBlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static Entry entryWithPriority(String name) throws BlockException
Rules related the resource. The entry is prioritized.name - the unique name for the protected resourceBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entryWithPriority(String name, EntryType type) throws BlockException
Rules related the resource. The entry is prioritized.name - the unique name for the protected resourcetype - 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 SystemRuleBlockException - if the block criteria is met, eg. when any rule's threshold is exceeded.public static Entry entry(String name, int resourceType, EntryType type) throws BlockException
name - the unique name for the protected resourceresourceType - classification of the resource (e.g. Web or RPC)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 SystemRuleBlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static Entry entry(String name, int resourceType, EntryType type, Object[] args) throws BlockException
name - the unique name for the protected resourcetype - 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 SystemRuleresourceType - classification of the resource (e.g. Web or RPC)args - extra parameters.BlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static AsyncEntry asyncEntry(String name, int resourceType, EntryType type, Object[] args) throws BlockException
name - the unique name for the protected resourcetype - 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 SystemRuleresourceType - classification of the resource (e.g. Web or RPC)args - extra parametersBlockException - if the block criteria is met, eg. when any rule's threshold is exceededpublic static AsyncEntry asyncEntry(String name, int resourceType, EntryType type, int acquireCount, Object[] args) throws BlockException
name - the unique name for the protected resourcetype - 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 SystemRuleresourceType - classification of the resource (e.g. Web or RPC)acquireCount - tokens requiredargs - extra parametersBlockException - if the block criteria is met, eg. when any rule's threshold is exceededCopyright © 2019 Alibaba Group. All rights reserved.