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
Make Callbacks Easier to Use #3360
Conversation
|
||
1. Once all the resources for the transaction manager have become ready, **but before the transaction manager becomes initialized**, the registered callback will be run asynchronously. | ||
2. If the callback fails and should not be retried, the transaction manager will be closed. | ||
3. If the callback is successful, the transaction manager then becomes initialized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth clarifying that the transaction manager provided to the callback can be used before the created transaction manager is initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Couple of minor comments. Looks like this works and is probably more usable without needing to figure out how the callback mechanism was implemented
@@ -40,7 +52,7 @@ | |||
* @param initException Throwable thrown by init() | |||
*/ | |||
public void cleanup(R resource, Throwable initException) { | |||
Throwables.rewrapAndThrowUncheckedException(initException); | |||
throw Throwables.rewrapAndThrowUncheckedException(initException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* onInitFailureCleanup is called before calling initialize again. | ||
* @param initialize initialization method. | ||
* @param onInitFailureCleanup cleanup to be done in case initialization throws. If this method also throws, no more | ||
* retries will be attampted and it will bubble up to the caller. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: attampted
} | ||
} | ||
|
||
@Value.Modifiable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! Wasn't aware of this feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah really useful, I saw it in one of the recent PR's
} | ||
|
||
@Test | ||
public void singleAttemptCallbackCallsInitializeAndCleanuoOnceThenRethrowsOnInitFailure() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Cleanup
@@ -0,0 +1,32 @@ | |||
=========================== | |||
Asynchronous Initialization | |||
=========================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing this! I don't think we documented this properly before (certainly not in such detail)
|
||
/** | ||
* Returns a Callback that will retry initialization on failure, unless the cleanup task also throws, in which case | ||
* the cause is not caught. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably implied, but for clarity I'd say in which case the exception thrown by the cleanup task is propagated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the word I was looking for!
Goals (and why):
Make it easier to use Callbacks: make it useful, and prevent wrong usage. Address #3353
Implementation Description (bullets):
Added a bunch of docs, and added an interface that should make it simpler to create your callback.
Concerns (what feedback would you like?):
Is this actually simpler now? Do we need a better example -- I could have
ConsistencyCheckRunner
implementCallbackInitializable
instead of being aCallback
, but not sure it makes sense to do so just to have another example in the codebase.Where should we start reviewing?:
CallbackInitializable.java
Priority (whenever / two weeks / yesterday):
Not super urgent
@pkoenig10 for SA
This change is