Class ExceptionHandler<C>
java.lang.Object
org.apache.nifi.processor.util.pattern.ExceptionHandler<C>
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BiFunction<C, ErrorTypes, ErrorTypes.Result> Adjust error type based on the context.private Function<Exception, ErrorTypes> Simply categorise an Exception.private ExceptionHandler.OnError<C, ?> Do some action to the input based on the final error type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustError(BiFunction<C, ErrorTypes, ErrorTypes.Result> adjustError) Specify a function that adjust ErrorType based on a function context.static <C> ExceptionHandler.OnError<C, org.apache.nifi.flowfile.FlowFile> createOnError(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, RoutingResult routingResult, org.apache.nifi.processor.Relationship relFailure, org.apache.nifi.processor.Relationship relRetry) Create aExceptionHandler.OnErrorfunction instance that routes input based onErrorTypes.Resultdestination and penalty.static <C,I extends PartialFunctions.FlowFileGroup>
ExceptionHandler.OnError<C, I> createOnGroupError(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, RoutingResult routingResult, org.apache.nifi.processor.Relationship relFailure, org.apache.nifi.processor.Relationship relRetry) Same ascreateOnError(ProcessContext, ProcessSession, RoutingResult, Relationship, Relationship)for FlowFileGroup.<I> booleanexecute(C context, I input, ExceptionHandler.Procedure<I> procedure) Executes specified procedure function with the input.<I> booleanexecute(C context, I input, ExceptionHandler.Procedure<I> procedure, ExceptionHandler.OnError<C, I> onError) Executes specified procedure function with the input.voidmapException(Function<Exception, ErrorTypes> mapException) Specify a function that maps an Exception to certain ErrorType.voidonError(ExceptionHandler.OnError<C, ?> onError) Specify a default OnError function that will be called if one is not explicitly specified whenexecute(Object, Object, Procedure)is called.private static org.apache.nifi.flowfile.FlowFilepenalize(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, org.apache.nifi.flowfile.FlowFile flowFile, ErrorTypes.Penalty penalty)
-
Field Details
-
mapException
Simply categorise an Exception. -
adjustError
Adjust error type based on the context. -
onError
Do some action to the input based on the final error type.
-
-
Constructor Details
-
ExceptionHandler
public ExceptionHandler()
-
-
Method Details
-
mapException
Specify a function that maps an Exception to certain ErrorType. -
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. -
onError
Specify a default OnError function that will be called if one is not explicitly specified when
execute(Object, Object, Procedure)is called. -
execute
public <I> boolean execute(C context, I input, ExceptionHandler.Procedure<I> procedure) throws org.apache.nifi.processor.exception.ProcessException, DiscontinuedException Executes specified procedure function with the input.
Default OnError function will be called when an exception is thrown.
- Parameters:
context- function contextinput- input for procedureprocedure- a function that does something with the input- Returns:
- True if the procedure finished without issue. False if procedure threw an Exception but it was handled by
ExceptionHandler.OnError. - Throws:
org.apache.nifi.processor.exception.ProcessException- Thrown if the exception was not handled byExceptionHandler.OnErrorDiscontinuedException- Indicating the exception was handled byExceptionHandler.OnErrorbut process should stop immediately without processing any further input
-
execute
public <I> boolean execute(C context, I input, ExceptionHandler.Procedure<I> procedure, ExceptionHandler.OnError<C, I> onError) throws org.apache.nifi.processor.exception.ProcessException, DiscontinuedExceptionExecutes specified procedure function with the input.
- Parameters:
context- function contextinput- input for procedureprocedure- a function that does something with the inputonError- specifyExceptionHandler.OnErrorfunction for this execution- Returns:
- True if the procedure finished without issue. False if procedure threw an Exception but it was handled by
ExceptionHandler.OnError. - Throws:
org.apache.nifi.processor.exception.ProcessException- Thrown if the exception was not handled byExceptionHandler.OnErrorDiscontinuedException- Indicating the exception was handled byExceptionHandler.OnErrorbut process should stop immediately without processing any further input
-
penalize
private static org.apache.nifi.flowfile.FlowFile penalize(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, org.apache.nifi.flowfile.FlowFile flowFile, ErrorTypes.Penalty penalty) -
createOnError
public static <C> ExceptionHandler.OnError<C,org.apache.nifi.flowfile.FlowFile> createOnError(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, RoutingResult routingResult, org.apache.nifi.processor.Relationship relFailure, org.apache.nifi.processor.Relationship relRetry) Create aExceptionHandler.OnErrorfunction instance that routes input based onErrorTypes.Resultdestination and penalty.- Parameters:
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 thisRoutingResultrelFailure- specify failure relationship of a processorrelRetry- specify retry relationship of a processor- Returns:
- composed function
-
createOnGroupError
public static <C,I extends PartialFunctions.FlowFileGroup> ExceptionHandler.OnError<C,I> createOnGroupError(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session, RoutingResult routingResult, org.apache.nifi.processor.Relationship relFailure, org.apache.nifi.processor.Relationship relRetry) Same ascreateOnError(ProcessContext, ProcessSession, RoutingResult, Relationship, Relationship)for FlowFileGroup.- Parameters:
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 thisRoutingResultrelFailure- specify failure relationship of a processorrelRetry- specify retry relationship of a processor- Returns:
- composed function
-