-
Notifications
You must be signed in to change notification settings - Fork 298
Introducing Synchronous Methods to Public APIs #146
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
Conversation
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.
Have you thought of just calling the async methods directly from the synchronous methods? That would get rid of the "...Op()" methods and could drastically reduce the testing code in this PR while retaining the same test coverage.
| try { | ||
| return initializeApp(getOptionsFromEnvironment(), name); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException("Failed to load settings from the environment", e); |
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.
Can you be more descriptive here? Maybe something like 'from you system's environment variables'?
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.
Done
| * @return A Firebase custom token string. | ||
| * @throws IllegalArgumentException If the specified uid is null or empty, or if the app has not | ||
| * been initialized with service account credentials. | ||
| * @throws FirebaseAuthException If an error occurs while minting the custom token. |
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.
"retrieving" instead of minting? "Minting" seems like an internal term.
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.
Changed to "generating"
| */ | ||
| public ApiFuture<Void> setValueAsync(Object value) { | ||
| return new TaskToApiFuture<>(setValue(value)); | ||
| return setValueInternal(value, PriorityUtilities.parsePriority(this.path, null), null); |
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.
Are we planning on either renaming these back to setValue() or on adding blocking methods?
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.
There are no plans to introduce blocking methods to database, since the implementation is asynchronous all the way down to the core. Developers can wait on the futures if they need blocking-like semantics.
| if (TEST_FIREBASE_THREAD.equals(threadName)) { | ||
| return threadName; | ||
| } | ||
| return SAME_THREAD; |
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.
Should this just return the thread name? Or a boolean/enum with the result of the thread check?
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.
Done
| /** | ||
| * A generic operation that can be called with arbitrary arguments. | ||
| */ | ||
| public interface GenericFunction<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.
I don't see any code that uses more than one argument. If I remember correctly, this Admin SDK is also moving to Java 7. Can you then just use https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html?
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.
There are some multi arg function calls in FCM tests. But you're right. Once we are on java8 we should be able to clean this up significantly with native Function interface and lambdas. Specifically, I plan to replace most anonymous CallableOp instances with lambdas.
|
Made the suggested changes. As for calling async methods from sync ones, we are trying to provide a stronger guarantee here than merely providing blocking semantics. We are trying to ensure that blocking methods actually execute on the calling thread, and are guaranteed to not spawn any new threads under the hood. This means developers can easily plug the SDK into thread-constrained runtimes (GAE, other J2EE containers etc) and run everything on runtime-provisioned threads if they want to. |
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 but a nit.
| * | ||
| * @param uid The UID to store in the token. This identifies the user to other Firebase services | ||
| * (Realtime Database, Storage, etc.). Should be less than 128 characters. | ||
| * (Firebase Realtime Database, Firebase Auth, etc.). |
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.
Any reason to drop the length qualifier? (good either way)
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.
Added it back.
| checkTopic(topic); | ||
|
|
||
| return ImplFirebaseTrampolines.submitCallable(app, new Callable<TopicManagementResponse>() { | ||
| private CallableOperation<String, FirebaseMessagingException> makeSendRequest( |
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 this be named sendOp to be in line with the rest of the CallableOperations names?
(and topicManagementOp , below)
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.
Good idea. Changed to sendOp and manageTopicOp
| try { | ||
| return initializeApp(getOptionsFromEnvironment(), name); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException( |
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.
Change javadocs to IllegalArgumentException.
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.
Done
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.
nm
DO NOT MERGE (BREAKING CHANGES) |
* Removed the deprecated FirebaseCredential API * Removing the deprecated Task API
* Dropping support for GAE 7 * Removed GaeThreadFactory, GaeExecutorService and RevivingScheduledExecutor * Removed the deprecated FirebaseCredential API * Removing GAE java7 related APIs (GaeThreadFactory, RevivingScheduledExecutor) * Removed GaePlatform implementation * Added FirebaseScheduledExecutor * Updated documentation * Some minor nits from code reviews * Calling super method in DefaultRunLoop executor
* Dropping support for GAE 7 * Removed GaeThreadFactory, GaeExecutorService and RevivingScheduledExecutor * Removed the deprecated FirebaseCredential API * Removing GAE java7 related APIs (GaeThreadFactory, RevivingScheduledExecutor) * Removed GaePlatform implementation * Added FirebaseScheduledExecutor * Updated documentation * Removing LogWrapper API * Removing PrefixedLogger * Removing test config file * Updated CHANGELOG * Minor clean ups pointed out in the code review
|
Hi @hiranya911, as I commented already, removing the Task based API precludes us from sharing code between Android and the Server. This is a non-trivial problem, and it completely breaks a lot of our testing harness that shares code from Android. |
|
@dimipaun This is not a use case we intend to support. FWIW, we did not intend to support it in the past either. It sort of worked that way due to the similarity in the API signatures. But we certainly don't want developers to rely on that behavior. We want the Admin SDK, and the Android SDK to evolve independently. Specifically, we want the Admin SDK to follow the conventions established by the other server-side gcloud libraries. Therefore supporting an adhoc To be honest I'm not sure how you even got the same code to work in these 2 environments. The You may have noticed that this change is now in effect in the 6.0.0 release. You can continue to use the 5.x.x versions of the SDK while you figure out a migration plan. I would highly encourage you to migrate your server-side components to use the |
We are now approaching the final phase of the thread model refactoring work we started last year (#55). So far we have deprecated the
TaskAPI and all the methods that return aTask. This PR removes those deprecated public methods, and adds a set of synchronous methods in their place. For instanceFirebaseAuthwill now have:This is a breaking change, and hence will not be merged/released anytime soon. Instead I'll use this PR as a way to set up the
v6branch, and develop other breaking changes planned for the next major release on top it.go/firebase-admin-java-sync