Skip to content

Conversation

@hiranya911
Copy link
Contributor

In order to support Java 7 runtime in App Engine, we had implemented a number of abstractions and workarounds:

  • GaeThreadFactory and GaeExecutorService for leveraging background threads support
  • GaePlatform class for injecting the GAE threads into RTDB client code
  • RevivingScheduledExecutor for periodically restarting threads, to work around GAE thread deadlines

With the new Java 8 runtime, none of the above is necessary. We can use regular threads instead of the expensive background threads, and the threads are no longer killed abruptly by the runtime (verified via long running tests of this PR).

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Bye bye Java 7! :)

Some small nits.

CHANGELOG.md Outdated
- [changed] Removed the deprecated `FirebaseCredential` interface.
- [changed] Removed the deprecated `Task` interface along with the
`com.google.firebase.tasks` package.
- [changed] Dropped support for App Engine Java 7 runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

This might sound scary to someone unfamiliar with the subject. Do you want to state that Java 8 is now fully supported? Maybe something like Dropped support for App Engine's Java 7 runtime. We recommend to use the Admin SDK with Java 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

List<String> loggedComponents;
Logger.Level logLevel = Logger.Level.INFO;
boolean persistenceEnabled;
long cacheSize = DEFAULT_CACHE_SIZE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can any of these be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of them are accessed from DatabaseConfig and a couple of other places. I managed to make firebaseApp package-protected though.


public FirebaseScheduledExecutor(
ThreadFactory threadFactory, String name, Thread.UncaughtExceptionHandler handler) {
super(1, decorateThreadFactory(threadFactory, name, handler));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be super duper awesome if we just used ScheduledThreadPoolExecutor in our code. It would be much easier to grasp that we are now using an off-the-shelf executor. Maybe you can find a different place for decorateThreadFactory?

Copy link
Contributor Author

@hiranya911 hiranya911 Mar 19, 2018

Choose a reason for hiding this comment

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

In addition to decorating the ThreadFactory this class also customizes the executor a little bit by calling setRemoveOnCancelPolicy(). I'd rather not duplicate that in all the places we use this class. Also having all this in one place gives us an easy way to introduce more customizations in the future if required. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another way to get around this would be to introduce a new util method somewhere:

public static ScheduledThreadPoolExecutor newScheduledExecutor(ThreadFactory factory, String name)

We can do all the decorating/customizing in the method. DefaultRunLoop will have to find another approach though, since it extends the executor. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like your last approach better, but I can't think of a good way to replace the inheritance in DefaultRunLoop. We might want to ponder a little more about this, but I don't think we should hold up this PR on it. If anything, we could argue that this derisks this change since it keeps the existing pattern.

setRemoveOnCancelPolicy(true);
}

static ThreadFactory decorateThreadFactory(ThreadFactory threadFactory, String name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this external method is somewhat generic and as such it is hard to tell what it does. Do you mind finding a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to getThreadFactoryWithName()

@hiranya911
Copy link
Contributor Author

@schmidt-sebastian I've addressed the trivial comments. As for removing FirebaseScheduledExecutor, I've left some follow up questions to get you take on. Please take a look.


public FirebaseScheduledExecutor(
ThreadFactory threadFactory, String name, Thread.UncaughtExceptionHandler handler) {
super(1, decorateThreadFactory(threadFactory, name, handler));
Copy link
Contributor

Choose a reason for hiding this comment

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

I like your last approach better, but I can't think of a good way to replace the inheritance in DefaultRunLoop. We might want to ponder a little more about this, but I don't think we should hold up this PR on it. If anything, we could argue that this derisks this change since it keeps the existing pattern.

executor = new FirebaseScheduledExecutor(threadFactory, "firebase-database-worker") {
@Override
protected void afterExecute(Runnable runnable, Throwable throwable) {
if (throwable == null && runnable instanceof Future<?>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please call super.afterExecute().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@hiranya911 hiranya911 merged commit edd825e into v6 Mar 20, 2018
@hiranya911 hiranya911 deleted the hkj-gae-8 branch March 20, 2018 17:51
hiranya911 added a commit that referenced this pull request May 7, 2018
* Adding the sync APIs for FirebaseAuth

* Added more tests; Added sync APIs for FirebaseMessaging

* Removing Task references from database, iid and fcm APIs

* Fixing a typo

* Minor code clean up

* Updated javadocs; Renamed internal helpers of FirebaseMessaging for consistency

* Removed the deprecated FirebaseCredential API (#149)

* Removing the Task API (#152)

* Removed the deprecated FirebaseCredential API

* Removing the deprecated Task API

* Dropping Support for App Engine Java 7 Runtime (#153)

* 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

* Removing Deprecated LogWrapper API (#154)

* 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

* Minor API doc fixes (#171)
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.

2 participants