public class ExceptionHandler<C> extends Object
ExceptionHandler provides a structured Exception handling logic composed by reusable partial functions.
Benefits of using ExceptionHandler:
ErrorTypes, consolidated error handling based on error type.RollbackOnFailure for instance.| Modifier and Type | Class and Description |
|---|---|
static interface |
ExceptionHandler.OnError<C,I> |
static interface |
ExceptionHandler.Procedure<I> |
| Modifier and Type | Field and Description |
|---|---|
private BiFunction<C,ErrorTypes,ErrorTypes.Result> |
adjustError
Adjust error type based on the context.
|
private Function<Exception,ErrorTypes> |
mapException
Simply categorise an Exception.
|
private ExceptionHandler.OnError<C,?> |
onError
Do some action to the input based on the final error type.
|
| Constructor and Description |
|---|
ExceptionHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
adjustError(BiFunction<C,ErrorTypes,ErrorTypes.Result> adjustError)
Specify a function that adjust ErrorType based on a function context.
|
static <C> ExceptionHandler.OnError<C,FlowFile> |
createOnError(ProcessContext context,
ProcessSession session,
RoutingResult routingResult,
Relationship relFailure,
Relationship relRetry)
Create a
ExceptionHandler.OnError function instance that routes input based on ErrorTypes.Result destination and penalty. |
static <C,I extends PartialFunctions.FlowFileGroup> |
createOnGroupError(ProcessContext context,
ProcessSession session,
RoutingResult routingResult,
Relationship relFailure,
Relationship relRetry)
Same as
createOnError(ProcessContext, ProcessSession, RoutingResult, Relationship, Relationship) for FlowFileGroup. |
<I> boolean |
execute(C context,
I input,
ExceptionHandler.Procedure<I> procedure)
Executes specified procedure function with the input.
|
<I> boolean |
execute(C context,
I input,
ExceptionHandler.Procedure<I> procedure,
ExceptionHandler.OnError<C,I> onError)
Executes specified procedure function with the input.
|
void |
mapException(Function<Exception,ErrorTypes> mapException)
Specify a function that maps an Exception to certain ErrorType.
|
void |
onError(ExceptionHandler.OnError<C,?> onError)
Specify a default OnError function that will be called if one is not explicitly specified when
execute(Object, Object, Procedure) is called. |
private static FlowFile |
penalize(ProcessContext context,
ProcessSession session,
FlowFile flowFile,
ErrorTypes.Penalty penalty) |
private Function<Exception,ErrorTypes> mapException
private BiFunction<C,ErrorTypes,ErrorTypes.Result> adjustError
private ExceptionHandler.OnError<C,?> onError
public void mapException(Function<Exception,ErrorTypes> mapException)
public void adjustError(BiFunction<C,ErrorTypes,ErrorTypes.Result> adjustError)
Specify a function that adjust ErrorType based on a function context.
For example, RollbackOnFailure.createAdjustError(ComponentLog) decides
whether a process session should rollback or transfer input to failure or retry.
public void onError(ExceptionHandler.OnError<C,?> onError)
Specify a default OnError function that will be called if one is not explicitly specified when execute(Object, Object, Procedure) is called.
public <I> boolean execute(C context, I input, ExceptionHandler.Procedure<I> procedure) throws ProcessException, DiscontinuedException
Executes specified procedure function with the input.
Default OnError function will be called when an exception is thrown.
context - function contextinput - input for procedureprocedure - a function that does something with the inputExceptionHandler.OnError.ProcessException - Thrown if the exception was not handled by ExceptionHandler.OnErrorDiscontinuedException - Indicating the exception was handled by ExceptionHandler.OnError but process should stop immediately
without processing any further inputpublic <I> boolean execute(C context, I input, ExceptionHandler.Procedure<I> procedure, ExceptionHandler.OnError<C,I> onError) throws ProcessException, DiscontinuedException
Executes specified procedure function with the input.
context - function contextinput - input for procedureprocedure - a function that does something with the inputonError - specify ExceptionHandler.OnError function for this executionExceptionHandler.OnError.ProcessException - Thrown if the exception was not handled by ExceptionHandler.OnErrorDiscontinuedException - Indicating the exception was handled by ExceptionHandler.OnError but process should stop immediately
without processing any further inputprivate static FlowFile penalize(ProcessContext context, ProcessSession session, FlowFile flowFile, ErrorTypes.Penalty penalty)
public static <C> ExceptionHandler.OnError<C,FlowFile> createOnError(ProcessContext context, ProcessSession session, RoutingResult routingResult, Relationship relFailure, Relationship relRetry)
ExceptionHandler.OnError function instance that routes input based on ErrorTypes.Result destination and penalty.context - process context is used to yield a processorsession - process session is used to penalize a FlowFileroutingResult - input FlowFile will be routed to a destination relationship in this RoutingResultrelFailure - specify failure relationship of a processorrelRetry - specify retry relationship of a processorpublic static <C,I extends PartialFunctions.FlowFileGroup> ExceptionHandler.OnError<C,I> createOnGroupError(ProcessContext context, ProcessSession session, RoutingResult routingResult, Relationship relFailure, Relationship relRetry)
createOnError(ProcessContext, ProcessSession, RoutingResult, Relationship, Relationship) for FlowFileGroup.context - process context is used to yield a processorsession - process session is used to penalize FlowFilesroutingResult - input FlowFiles will be routed to a destination relationship in this RoutingResultrelFailure - specify failure relationship of a processorrelRetry - specify retry relationship of a processorCopyright © 2019 Apache NiFi Project. All rights reserved.