-
Notifications
You must be signed in to change notification settings - Fork 301
Make some internal APIs more open #292
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
Comments
Sure, the goal is to make protected or public anything that needs to be to extend Failsafe while guarding the rest. Are there specific methods/fields/classes you'd like to see by made protected or public? |
Yep, all the methods and classes currently referenced from a timeout or retry policies and executions (e.g. an abstract execution's methods, a timeout execution itself). A test for this would be a custom timeout or retry policy in a different package that adjust existing ones a bit. |
This commit includes a large refactoring with various improvements, but generally is aimed towards having a separate SPI package that provides access to most of the Failsafe internals such that it's easy to implement policies. The changes in this commit include: - Separating the execution types into separate public and internal interfaces - Creating an spi package and putting the various internal extensible classes in there - Improved the way internal classes interact with FailsafeFuture Fixes #292
This commit includes a large refactoring with various improvements, but generally is aimed towards having a separate SPI package that provides access to most of the Failsafe internals such that it's easy to implement policies. The changes in this commit include: - Separating the execution types into separate public and internal interfaces - Creating an spi package and putting the various internal extensible classes in there - Improved the way internal classes interact with FailsafeFuture Fixes #292
This commit includes a large refactoring with various improvements, but generally is aimed towards having a separate SPI package that provides access to most of the Failsafe internals such that it's easy to implement policies. The changes in this commit include: - Separating the execution types into separate public and internal interfaces - Creating an spi package and putting the various internal extensible classes in there - Improved the way internal classes interact with FailsafeFuture Fixes #292
@timothybasanov I just pushed a big refactoring to the master branch to support a more proper SPI, where the various internals are exposed and creating custom policies should be more possible now. Have a look and please let me know what you think. I'd like to release this for 2.5.0 soon. Most of the interesting things for you are now in the spi package. This is where PolicyExecutor now lives, which uses new ExecutionInternal, SyncExecutionInternal, and AsyncExecutionInternal interfaces for internal common, internal sync, and internal async execution behaviors respectively. Let me know how this looks and if I'm missing anything. |
This issue auto-closed since I just merged the related changes to master. @timothybasanov let me know what you think if you can soon. Would be good before I make a 2.5 release. |
As an exercise I've tried to create a few custom policies. A few things that spring to my attention:
This is still a significant improvement over 2.4. I can now copy-paste the whole |
Thanks for the responses Timothy...
So you'd prefer a protected constructor? Are you using Timeout with the existing TImeoutExecutor or with your own? For 3.0 I'm actually planning to have private constructors on all policies and to let them be built via a Builder, FWIW, as part of #47.
You mean something like
Hmm - maybe the PolicyExecutors can move to the internal package and as you say, become public.
I assume you mean the lack of thread safety (#47)? I am working on that for 3.0, but the plan is to actually make policies immutable, except for adding event listeners, once they're built. Of course we could make it easy to create a new copy. Would that work for you? Maybe you can talk more about your use case.
I can make those methods protected. I'm curious though what kind of jitter changes you're making. Perhaps it would be better to support some kind of jitter function config rather than having to override some methods in the PolicyExecutor?
I'll make
This might be better as a top ievel feature - same for CircuitBreakers. Does #225 sound right for that? |
Yes, protected constructors for all policies would be appreciated. I often want to tweak only one aspect of the policy by extending it (e.g.
Yep, ideally a
Yep, if I can freely convert from policy to its builder and back, it would solve some of my issues. I would be able to store a "master copy" of a policy, and create "adjusted" ones when necessary for special cases. As an example different methods called on the same RPC service have very similar, but still slightly different configuration.
These were only a few random examples. In general, I would recommend against locking up a framework with package locals or privates unless there is absolute certainty that end user would not want to reuse or adjust this functionality. |
I'd argue the opposite. Exposing internals and even allowing inheritance makes it extremely hard to maintain a library in the long run. I'd avoid inheritance like the plague and go with composition instead: https://whiskeysierra.github.io/knowledge/composition/ |
Amplifying what @whiskeysierra wrote: Making classes extensible is extremely hard to get right, and it's often at odds with the goal of a builder-based API. It can add maintenance costs that dominate the original re-use benefits. I don't have a good answer to @timothybasanov — I understand the desire to be able to take advantage of all that working code that is currently locked up, but I'd hate to see the already severe maintenance burden increase further in an attempt to meet that desire. |
@timothybasanov I just merged a PR into master which introduces a builder API in preparation for 3.0. I'm interested to get your revised take on how the new API works for you, and this issue. |
3.0 has been released, which includes the SPI package. I'm still interested to hear how this works for you @timothybasanov in case there are more improvements needed. |
Currently a lot of internal APIs are well, internal. It should be possible to implement a different
Timeout
orRetry
policy from an application package. This may require to make some package local methods and classes to be public.The text was updated successfully, but these errors were encountered: