-
Notifications
You must be signed in to change notification settings - Fork 128
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
feat: add lazy initializer #423
Conversation
Codecov Report
@@ Coverage Diff @@
## master #423 +/- ##
=========================================
Coverage 82.16% 82.17%
- Complexity 2455 2460 +5
=========================================
Files 136 138 +2
Lines 13589 13605 +16
Branches 1307 1309 +2
=========================================
+ Hits 11166 11180 +14
- Misses 1895 1896 +1
- Partials 528 529 +1
Continue to review full report at Codecov.
|
* Generic {@link AbstractLazyInitializer} for any heavy-weight object that might throw an exception | ||
* during initialization. The underlying object is initialized at most once. | ||
*/ | ||
public abstract class AbstractLazyInitializer<T> { |
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.
Could we use composition instead of inheritance (pass in the initialiser function instead of overriding it)?
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 would be possible, but as we have to support Java 7, that would mean that we would have to use com.google.cloud.base.Function
in the public interface. I think that it is more idiomatic to use inheritance than composition for Java 7 (once we drop Java 7 support, I would agree that using composition would be a lot nicer in this case).
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.
LGTM
This is an auto-generated regeneration of the .pb.go files by cloud.google.com/go/internal/gapicgen. Once this PR is submitted, genbot will update the corresponding PR to depend on the newer version of go-genproto, and assign reviewers. Whilst this or any regen PR is open in go-genproto, genbot will not create any more regeneration PRs. If all regen PRs are closed, gapicgen will create a new set of regeneration PRs once per night. If you have been assigned to review this PR, please: - Ensure that CI is passing. If it's failing, it requires your manual attention. - Approve and submit this PR if you believe it's ready to ship. That will prompt genbot to assign reviewers to the google-cloud-go PR. Corresponding google-cloud-go PR: googleapis/google-cloud-go#2682
Adds a
LazyInitializer
forSpanner
instances that can be used in environments where it is desirable to initialize one instance once, and reuse this for multiple purposes, such as for example Google Cloud Functions.This change would allow us to simplify the Google Cloud Functions Java sample.
Towards GoogleCloudPlatform/java-docs-samples#2862.