googleapis / java-spanner Public
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).
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.