Skip to content
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

Merged
merged 4 commits into from Jul 12, 2018
Merged

Make Callbacks Easier to Use #3360

merged 4 commits into from Jul 12, 2018

Conversation

gmaretic
Copy link
Contributor

@gmaretic gmaretic commented Jul 6, 2018

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 implement CallbackInitializable instead of being a Callback, 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 Reviewable

@gmaretic gmaretic requested a review from jeremyk-91 July 6, 2018 16:21

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.
Copy link
Member

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.

Copy link
Contributor

@jeremyk-91 jeremyk-91 left a 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);
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: attampted

}
}

@Value.Modifiable
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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
===========================
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor Author

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!

@sandorw sandorw assigned gmaretic and unassigned sandorw Jul 12, 2018
@gmaretic gmaretic merged commit 94a1607 into develop Jul 12, 2018
@gmaretic gmaretic deleted the feature/simpler-callbacks branch July 12, 2018 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants