failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.2k stars 297 forks source link

Copy Config into Builder #310

Closed sunng87 closed 3 years ago

sunng87 commented 3 years ago

With new separation of builder and config APIs, it would be nice to be able to create a builder from an existed config, with which we can copy a pre-configured policy, like .copy API from 2.x.

For example, a withConfig method in builder to accept a XXXConfig and copy all the data into the builder. We can still have further customizations by calling other withXXX APIs from the builder.

jhalterman commented 3 years ago

@sunng87 Will do. Is this a blocker for you to get to 3.0? How soon do you need this?

Tembrel commented 3 years ago

As a temporary workaround, isn't it possible to treat a Builder instance as effectively being a kind of non-queryable Config? Builders aren't automatically safe to share between threads, but if you take care, you could re-use Builders to get the effect of constructing a Builder from a Config.

jhalterman commented 3 years ago

I just pushed 311ff96 which adds builder(PolicyConfig) to each of the policy types. It also relaxes some of the illegal state validation in RetryPolicyBuilder so that different types of delays can be configured to replace previous configuration, and relaxes the requirement that a jitter be configured after a delay. This should make RetryPolicyBuilder a bit more flexible.

Closing, but feel free to reopen if you see any problem with the commit. I'll probably release this as part of 3.0.1 in the next few days.

sunng87 commented 3 years ago

Thank you for fast response. I confirm the change in 311ff96 fixed the issue for me.

jhalterman commented 3 years ago

Sure - I just released 3.0.1 with this change. It should be synced to Maven central in a few hours.