I use the Hazelcast Jet core API to design new processors for my DAGs. Some of these processors might fail throwing exceptions that - if not handled somehow - will cause the entire job to fail and stop.
I'm trying therefore to design a mechanism to introduce some optional fault tolerance policies inside my processors' code. Just to give an idea, I'd like to make it possible to handle errors by configuring one of these strategies:
- failing as soon as it happens (current behaviours when exceptions are unhandled)
- retrying a few times before failing
- executing some fallback code that will typically catch the exception, audit the error and just go on.
However, given the way the Processor interface is designed, there is no way to provide this behaviour by generically decorating processors, unless they are internally designed to support this fault tolerance policies.
In fact, I would like to be able to somehow decorate them using a method that could be like this:
Processors.faultTolerantP(ProcessorMetaSupplier supplier, FaultTolerancePolicy policy)
where FaultTolerancePolicy
is a description of the above mentioned policies.
So far, the only thing I could do is to design my "fault tolerant processors" to implement the IFaultTolerant
interface allowing to inject the policy into the processor. Then the processor code must "manually" handle the fault-tolerance policy.
interface IFaultTolerant{
void setFaultTolerancePolicy(FaultTolerancePolicy policy);
}
class MyProcessor extends AbstractProcessor implements IFaultTolerant{
public void setFaultTolerancePolicy(FaultTolerancePolicy policy){
// stores the policy and behaves as specified by the policy when errors occur
}
}
class MyProcessors{
public static ProcessorMetaSupplier faultTolerantP(ProcessorMetaSupplier supplier, FaultTolerancePolicy policy) {
return new WrappingProcessorMetaSupplier(supplier, p -> faultTolerantP(p, policy));
}
private static Processor faultTolerantP(Processor p, FaultTolerancePolicy policy) {
if (p instanceof IFaultTolerant) {
((IFaultTolerant)p).setFaultTolerancePolicy(policy);
}
return p;
}
}
Do you have any advice about this? Would it be possible to intercept faults at a higher level, so that any processor can become fault tolerant without having to be designed for that?