Hystrix: Latency and Fault Tolerance for Distributed Systems



com.netflix.hystrix.strategy.executionhook
Class HystrixCommandExecutionHook

java.lang.Object
  extended by com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook

public abstract class HystrixCommandExecutionHook
extends java.lang.Object

Abstract ExecutionHook with invocations at different lifecycle points of HystrixCommand execution with default no-op implementations.

See HystrixPlugins or the Hystrix GitHub Wiki for information on configuring plugins: https://github.com/Netflix/Hystrix/wiki/Plugins.

Note on thread-safety and performance

A single implementation of this class will be used globally so methods on this class will be invoked concurrently from multiple threads so all functionality must be thread-safe.

Methods are also invoked synchronously and will add to execution time of the commands so all behavior should be fast. If anything time-consuming is to be done it should be spawned asynchronously onto separate worker threads.

Since:
1.2

Constructor Summary
HystrixCommandExecutionHook()
           
 
Method Summary
<T> T
onComplete(HystrixCommand<T> commandInstance, T response)
          Invoked after completion of HystrixCommand execution that results in a response.
<T> java.lang.Exception
onError(HystrixCommand<T> commandInstance, HystrixRuntimeException.FailureType failureType, java.lang.Exception e)
          Invoked after failed completion of HystrixCommand execution.
<T> java.lang.Exception
onFallbackError(HystrixCommand<T> commandInstance, java.lang.Exception e)
          Invoked after failed execution of HystrixCommand.getFallback() with thrown exception.
<T> void
onFallbackStart(HystrixCommand<T> commandInstance)
          Invoked before HystrixCommand.getFallback() is about to be executed.
<T> T
onFallbackSuccess(HystrixCommand<T> commandInstance, T fallbackResponse)
          Invoked after successful execution of HystrixCommand.getFallback() with response value.
<T> java.lang.Exception
onRunError(HystrixCommand<T> commandInstance, java.lang.Exception e)
          Invoked after failed execution of HystrixCommand.run() with thrown Exception.
<T> void
onRunStart(HystrixCommand<T> commandInstance)
          Invoked before HystrixCommand.run() is about to be executed.
<T> T
onRunSuccess(HystrixCommand<T> commandInstance, T response)
          Invoked after successful execution of HystrixCommand.run() with response value.
<T> void
onStart(HystrixCommand<T> commandInstance)
          Invoked before HystrixCommand executes.
<T> void
onThreadComplete(HystrixCommand<T> commandInstance)
          Invoked at completion of thread execution when HystrixCommand is executed using HystrixCommandProperties.ExecutionIsolationStrategy.THREAD.
<T> void
onThreadStart(HystrixCommand<T> commandInstance)
          Invoked at start of thread execution when HystrixCommand is executed using HystrixCommandProperties.ExecutionIsolationStrategy.THREAD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HystrixCommandExecutionHook

public HystrixCommandExecutionHook()
Method Detail

onRunStart

public <T> void onRunStart(HystrixCommand<T> commandInstance)
Invoked before HystrixCommand.run() is about to be executed.

Parameters:
commandInstance - The executing HystrixCommand instance.
Since:
1.2

onRunSuccess

public <T> T onRunSuccess(HystrixCommand<T> commandInstance,
                          T response)
Invoked after successful execution of HystrixCommand.run() with response value.

Parameters:
commandInstance - The executing HystrixCommand instance.
response - from HystrixCommand.run()
Returns:
T response object that can be modified, decorated, replaced or just returned as a pass-thru.
Since:
1.2

onRunError

public <T> java.lang.Exception onRunError(HystrixCommand<T> commandInstance,
                                          java.lang.Exception e)
Invoked after failed execution of HystrixCommand.run() with thrown Exception.

Parameters:
commandInstance - The executing HystrixCommand instance.
e - Exception thrown by HystrixCommand.run()
Returns:
Exception that can be decorated, replaced or just returned as a pass-thru.
Since:
1.2

onFallbackStart

public <T> void onFallbackStart(HystrixCommand<T> commandInstance)
Invoked before HystrixCommand.getFallback() is about to be executed.

Parameters:
commandInstance - The executing HystrixCommand instance.
Since:
1.2

onFallbackSuccess

public <T> T onFallbackSuccess(HystrixCommand<T> commandInstance,
                               T fallbackResponse)
Invoked after successful execution of HystrixCommand.getFallback() with response value.

Parameters:
commandInstance - The executing HystrixCommand instance.
fallbackResponse - from HystrixCommand.getFallback()
Returns:
T response object that can be modified, decorated, replaced or just returned as a pass-thru.
Since:
1.2

onFallbackError

public <T> java.lang.Exception onFallbackError(HystrixCommand<T> commandInstance,
                                               java.lang.Exception e)
Invoked after failed execution of HystrixCommand.getFallback() with thrown exception.

Parameters:
commandInstance - The executing HystrixCommand instance.
e - Exception thrown by HystrixCommand.getFallback()
Returns:
Exception that can be decorated, replaced or just returned as a pass-thru.
Since:
1.2

onStart

public <T> void onStart(HystrixCommand<T> commandInstance)
Invoked before HystrixCommand executes.

Parameters:
commandInstance - The executing HystrixCommand instance.
Since:
1.2

onComplete

public <T> T onComplete(HystrixCommand<T> commandInstance,
                        T response)
Invoked after completion of HystrixCommand execution that results in a response.

The response can come either from HystrixCommand.run() or HystrixCommand.getFallback().

Parameters:
commandInstance - The executing HystrixCommand instance.
response - from HystrixCommand.run() or HystrixCommand.getFallback().
Returns:
T response object that can be modified, decorated, replaced or just returned as a pass-thru.
Since:
1.2

onError

public <T> java.lang.Exception onError(HystrixCommand<T> commandInstance,
                                       HystrixRuntimeException.FailureType failureType,
                                       java.lang.Exception e)
Invoked after failed completion of HystrixCommand execution.

Parameters:
commandInstance - The executing HystrixCommand instance.
failureType - HystrixRuntimeException.FailureType representing the type of failure that occurred.

See HystrixRuntimeException for more information.

e - Exception thrown by HystrixCommand
Returns:
Exception that can be decorated, replaced or just returned as a pass-thru.
Since:
1.2

onThreadStart

public <T> void onThreadStart(HystrixCommand<T> commandInstance)
Invoked at start of thread execution when HystrixCommand is executed using HystrixCommandProperties.ExecutionIsolationStrategy.THREAD.

Parameters:
commandInstance - The executing HystrixCommand instance.
Since:
1.2

onThreadComplete

public <T> void onThreadComplete(HystrixCommand<T> commandInstance)
Invoked at completion of thread execution when HystrixCommand is executed using HystrixCommandProperties.ExecutionIsolationStrategy.THREAD.

Parameters:
commandInstance - The executing HystrixCommand instance.
Since:
1.2