R
- the return type of the original method that should have been executed (but break handler took over the
control instead)public class ExceptionThrowingHandler<R> extends Object implements BreakHandler<R>
BreakHandlerException
.
NOTE: the exception class given as a parameter MUST define an exception with a publicly(!) accessible constructor taking "message" String as the only parameter. This is because such constructor will be used to create instance of exception to throw.
This implementation can be shared between different executions of circuit breaker and therefore does not require
factory method implementing BreakHandlerFactory
to be reusable.
Constructor and Description |
---|
ExceptionThrowingHandler(Class<? extends BreakHandlerException> exceptionClass,
ExceptionThrowingHandlerMessageCallback<R> callback)
Constructs new instance of
ExceptionThrowingHandler which will throw exception of given class
with message obtained from given callback, in case "break" occurred (circuit breaker executed break handler
instead of real-method). |
ExceptionThrowingHandler(Class<? extends BreakHandlerException> exceptionClass,
String exceptionMessage)
Constructs new instance of
ExceptionThrowingHandler which will throw exception of given class
with given message in case "break" occurred (circuit breaker executed break handler instead of
real-method). |
ExceptionThrowingHandler(ExceptionThrowingHandlerMessageCallback<R> callback)
Constructs new instance of
ExceptionThrowingHandler which will throw BreakHandlerException with
message obtained by calling
ExceptionThrowingHandlerMessageCallback.buildMessage(Task, ExecutionContext) . |
ExceptionThrowingHandler(String exceptionMessage)
Constructs new instance of
ExceptionThrowingHandler which will throw BreakHandlerException with
given message in case "break" occurred (circuit breaker executed break handler instead of
real-method). |
Modifier and Type | Method and Description |
---|---|
protected String |
buildMessage(Task<R> task,
ExecutionContext<R> executionContext) |
R |
onBreak(ContextAwareCircuitBreaker<R> circuitBreaker,
Task<R> task,
BreakStrategy<R> breakStrategy,
ExecutionContext<R> executionContext)
Handles situation when break occurs.
|
public ExceptionThrowingHandler(String exceptionMessage)
ExceptionThrowingHandler
which will throw BreakHandlerException
with
given message in case "break" occurred (circuit breaker executed break handler instead of
real-method).exceptionMessage
- the message for the exceptionpublic ExceptionThrowingHandler(ExceptionThrowingHandlerMessageCallback<R> callback)
ExceptionThrowingHandler
which will throw BreakHandlerException
with
message obtained by calling
ExceptionThrowingHandlerMessageCallback.buildMessage(Task, ExecutionContext)
.callback
- a callback method which returns the message for the exceptionpublic ExceptionThrowingHandler(Class<? extends BreakHandlerException> exceptionClass, String exceptionMessage)
ExceptionThrowingHandler
which will throw exception of given class
with given message in case "break" occurred (circuit breaker executed break handler instead of
real-method).exceptionClass
- the type of exception to throw - must be subclass of BreakHandlerException
exceptionMessage
- the message for the exceptionpublic ExceptionThrowingHandler(Class<? extends BreakHandlerException> exceptionClass, ExceptionThrowingHandlerMessageCallback<R> callback)
ExceptionThrowingHandler
which will throw exception of given class
with message obtained from given callback, in case "break" occurred (circuit breaker executed break handler
instead of real-method).exceptionClass
- the type of exception to throw - must be subclass of BreakHandlerException
callback
- a callback method which returns the message for the exceptionpublic R onBreak(ContextAwareCircuitBreaker<R> circuitBreaker, Task<R> task, BreakStrategy<R> breakStrategy, ExecutionContext<R> executionContext) throws BreakHandlerException
BreakHandler
onBreak
in interface BreakHandler<R>
circuitBreaker
- a reference to the ContextAwareCircuitBreaker
which called this break handlertask
- the task which execution was prevented by break strategy and resulted in calling this
break handlerbreakStrategy
- the strategy which prevented the execution of task and resulted in calling this break
handlerexecutionContext
- contains current execution data (specific to current execution)BreakHandlerException
- in case this break handler is not able to provide the the fallback valueprotected String buildMessage(Task<R> task, ExecutionContext<R> executionContext)
Copyright © 2017. All rights reserved.