|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.netflix.hystrix.HystrixCommand<R>
R - the return type@ThreadSafe public abstract class HystrixCommand<R>
Used to wrap code that will execute potentially risky functionality (typically meaning a service call over the network) with fault and latency tolerance, statistics and performance metrics capture, circuit breaker and bulkhead functionality.
| Nested Class Summary | |
|---|---|
static class |
HystrixCommand.Setter
Fluent interface for arguments to the HystrixCommand constructor. |
| Constructor Summary | |
|---|---|
protected |
HystrixCommand(HystrixCommand.Setter setter)
Construct a HystrixCommand with defined HystrixCommand.Setter that allows
injecting property and strategy overrides and other optional arguments. |
protected |
HystrixCommand(HystrixCommandGroupKey group)
Construct a HystrixCommand with defined HystrixCommandGroupKey. |
| Method Summary | |
|---|---|
R |
execute()
Used for synchronous execution of command. |
protected java.lang.String |
getCacheKey()
Key to be used for request caching. |
HystrixCommandGroupKey |
getCommandGroup()
|
HystrixCommandKey |
getCommandKey()
|
java.util.List<HystrixEventType> |
getExecutionEvents()
List of HystrixCommandEventType enums representing events that occurred during execution. |
int |
getExecutionTimeInMilliseconds()
The execution time of this command instance in milliseconds, or -1 if not executed. |
protected R |
getFallback()
If HystrixCommand.execute() or HystrixCommand.queue() fails in any way then this method will be invoked to provide an opportunity to return a fallback response. |
HystrixCommandMetrics |
getMetrics()
The HystrixCommandMetrics associated with this HystrixCommand instance. |
HystrixCommandProperties |
getProperties()
The HystrixCommandProperties associated with this HystrixCommand instance. |
HystrixThreadPoolKey |
getThreadPoolKey()
|
boolean |
isCircuitBreakerOpen()
Whether the 'circuit-breaker' is open meaning that execute() will immediately return
the getFallback() response and not attempt a HystrixCommand execution. |
boolean |
isExecutedInThread()
Whether the execution occurred in a separate thread. |
boolean |
isExecutionComplete()
If this command has completed execution either successfully, via fallback or failure. |
boolean |
isFailedExecution()
Whether the execute() resulted in a failure (exception). |
boolean |
isResponseFromCache()
Whether the response is from cache and execute() was not invoked. |
boolean |
isResponseFromFallback()
Whether the response received from execute() was the result of a failure
and getFallback() being called. |
boolean |
isResponseRejected()
Whether the response received from execute() was a fallback as result of being
rejected (from thread-pool or semaphore) and getFallback() being called. |
boolean |
isResponseShortCircuited()
Whether the response received from execute() was a fallback as result of being
short-circuited (meaning isCircuitBreakerOpen() == true) and getFallback() being called. |
boolean |
isResponseTimedOut()
Whether the response received from execute() was the result of a timeout
and getFallback() being called. |
java.util.concurrent.Future<R> |
queue()
Used for asynchronous execution of command. |
protected abstract R |
run()
Implement this method with code to be executed when HystrixCommand.execute() or HystrixCommand.queue() are invoked. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected HystrixCommand(HystrixCommandGroupKey group)
HystrixCommand with defined HystrixCommandGroupKey.
group - HystrixCommandGroupKey used to group together multiple HystrixCommand objects.
The HystrixCommandGroupKey is used to represent a common relationship between commands. For example, a library or team name, the system all related commands interace with,
common business purpose etc.
protected HystrixCommand(HystrixCommand.Setter setter)
HystrixCommand with defined HystrixCommand.Setter that allows
injecting property and strategy overrides and other optional arguments.
Null values on everything except 'group' will result in the default being used.
setter - Fluent interface for constructor arguments| Method Detail |
|---|
protected abstract R run()
HystrixCommand.execute() or HystrixCommand.queue() are invoked.
protected R getFallback()
HystrixCommand.execute() or HystrixCommand.queue() fails in any way then this method will be invoked to provide an opportunity to return a fallback response.
This should do work that does not require network transport to produce.
In other words, this should be a static or cached result that can immediately be returned upon failure.
If network traffic is wanted for fallback (such as going to MemCache) then the fallback implementation should invoke another HystrixCommand instance that protects against that network
access and possibly has another level of fallback that does not involve network access.
DEFAULT BEHAVIOR: It throws UnsupportedOperationException.
public final HystrixCommandGroupKey getCommandGroup()
HystrixCommandGroupKey used to group together multiple HystrixCommand objects.
The HystrixCommandGroupKey is used to represent a common relationship between commands. For example, a library or team name, the system all related commands interace with,
common business purpose etc.
public final HystrixCommandKey getCommandKey()
HystrixCommandKey identifying this command instance for statistics, circuit-breaker, properties, etc.public final HystrixThreadPoolKey getThreadPoolKey()
HystrixThreadPoolKey identifying which thread-pool this command uses (when configured to run on separate threads via
HystrixCommandProperties.executionIsolationStrategy()).public final HystrixCommandMetrics getMetrics()
HystrixCommandMetrics associated with this HystrixCommand instance.
public final HystrixCommandProperties getProperties()
HystrixCommandProperties associated with this HystrixCommand instance.
public final R execute()
execute in interface HystrixExecutable<R>HystrixCommand.run() execution or a fallback from HystrixCommand.getFallback() if the command fails for any reason.
HystrixRuntimeException - if a failure occurs and a fallback cannot be retrieved
HystrixBadRequestException - if invalid arguments or state were used representing a user failure, not a system failurepublic final java.util.concurrent.Future<R> queue()
This will queue up the command on the thread pool and return an Future to get the result once it completes.
NOTE: If configured to not run in a separate thread, this will have the same effect as HystrixCommand.execute() and will block.
We don't throw an exception but just flip to synchronous execution so code doesn't need to change in order to switch a command from running on a separate thread to the calling thread.
queue in interface HystrixExecutable<R>Future<R> Result of HystrixCommand.run() execution or a fallback from HystrixCommand.getFallback() if the command fails for any reason.
HystrixRuntimeException - via Future.get() in Throwable.getCause() if a failure occurs and a fallback cannot be retrieved
HystrixBadRequestException - via Future.get() in Throwable.getCause() if invalid arguments or state were used representing a user failure, not a system failurepublic final boolean isCircuitBreakerOpen()
execute() will immediately return
the getFallback() response and not attempt a HystrixCommand execution.
public final boolean isExecutionComplete()
public final boolean isExecutedInThread()
This should be called only once execute()/queue()/fireOrForget() are called otherwise it will always return false.
This specifies if a thread execution actually occurred, not just if it is configured to be executed in a thread.
public final boolean isFailedExecution()
execute() resulted in a failure (exception).
public final boolean isResponseFromFallback()
execute() was the result of a failure
and getFallback() being called.
public final boolean isResponseTimedOut()
execute() was the result of a timeout
and getFallback() being called.
public final boolean isResponseShortCircuited()
execute() was a fallback as result of being
short-circuited (meaning isCircuitBreakerOpen() == true) and getFallback() being called.
public final boolean isResponseFromCache()
execute() was not invoked.
public final boolean isResponseRejected()
execute() was a fallback as result of being
rejected (from thread-pool or semaphore) and getFallback() being called.
public final java.util.List<HystrixEventType> getExecutionEvents()
Examples of events are SUCCESS, FAILURE, TIMEOUT, and SHORT_CIRCUITED
List<HystrixEventType>public final int getExecutionTimeInMilliseconds()
protected java.lang.String getCacheKey()
By default this returns null which means "do not cache".
To enable caching override this method and return a string key uniquely representing the state of a command instance.
If multiple command instances in the same request scope match keys then only the first will be executed and all others returned from cache.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||