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 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. |
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.Copyright © 2018 Alibaba Group. All rights reserved.