-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better type support for reusable FaultTolerance instances #1050
Comments
Yeah, I wonder as well. I don't see a good way, to be honest. Do you? |
One of the possible solutions is to allow sharing the state between these two - the same circuit breaker, rate limit, etc. For example:
I am not sure if this is the proper way. Other option is to have a method within FaultTolerance that contains this ugly cast |
Hmm, I guess something like this might work?
/**
* Creates a copy of this {@link FaultTolerance} object containing the same fault tolerance strategies,
* but guarding an action of a different type. Since the type of the action is only used in fallback,
* this is usually safe; if this {@code FaultTolerance} object contains a fallback, this method throws
* an exception.
* <p>
* Note that the original type <em>must</em> have the same asynchronous "nature" as the new type. That is,
* if the original {@code FaultTolerance} object is synchronous, the new type must also be synchronous.
* If the original {@code FaultTolerance} object is asynchronous and the asynchronous type is
* {@code CompletionStage<T>}, the new type must be {@code CompletionStage<U>}.
*
* @param <U> type of value of the guarded action
*/
<U> FaultTolerance<U> copy(); |
This looks good to me, maybe there should be a different name than Maybe fallback should be checked inside I am also a concerned about other use cases, for example - reuse circuit breaker, but not rate limiter. I was wondering, maybe it is possible to have API like this:
|
If you have a suggestion, I'm all ears.
That's exactly what the documentation says :-)
I'm afraid this goes directly against the existing design. I'll have to think about that. |
The type support in the fault tolerance instances is mostly used for fallback purposes.
I use programatic API to configure fault tolerance, and it requires ugly hacks to reuse the instance for two methods that return different types:
I wonder if there is a better API to support this kind of use case, instead of making this ugly hack.
The text was updated successfully, but these errors were encountered: