Skip to content

add fail fast policy #475

Open
Open
@Ladicek

Description

@Ladicek

Currently, we have @CircuitBreaker, which automatically (based on relatively simple criteria) provides a "fail fast" behavior. I propose to add general @FailFast policy, which would delegate the "should fail fast?" decision to some handler. For example:

public class MyService {
    @FailFast(MyServiceFailFastHandler.class)
    public void someCostlyMethod() {
        ...
    }
}

public class MyServiceFailFastHandler implements FailFastHandler {
    public boolean shouldFailFast(FailFastContext ctx) {
        ...
    }
}

The API would look something like this:

public @interface FailFast {
    Class<? extends FailFastHandler> value();
}

public interface FailFastHandler {
    boolean shouldFailFast(FailFastContext ctx);
}

// similar to existing `ExecutionContext`
//
// we could also use `ExecutionContext` unmodified,
// and specify that `getFailure` is always `null` (or throws an exception)
public interface FailFastContext {
    Method getMethod();
    Object[] getParameters();
}

// thrown when `FailFastHandler.shouldFailFast` returns `true`
public class FailFastException extends FaultToleranceException {
}

I didn't have much time to look into this yet, so I'm filing this issue just to gather some feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions