Skip to content
Advertisement

How to move from deprecated Task to ApiFuture for firebase admin SDK 5.4 and above

I’m just trying to solve the deprecation notes from my Java code of new firebase-admin SDK, the code is written in version 5.3.1 but after upgrading the version into 5.5.0 the deprecation notes appeared, here is a sample of my code:

Using FirebaseAuth (deprecatation on: Task, addOnSuccessListener and addOnFailureListener) :

JavaScript

And for FirebaseDatabase (deprecatation on: Task, addOnSuccessListener, addOnFailureListener, updateChildren and removeValue) :

JavaScript

The deprecation note saying I have to use ApiFuture as what the release notes saying: https://firebase.google.com/support/release-notes/admin/java

And inside source, as for example:

JavaScript

And

JavaScript

Advertisement

Answer

Almost 2 years, but need to add my answers, current answers gave me a guide but were not a full solution, so Kudos for @Enylton Machado and @Hiranya Jayathilaka it is still good to refer to their answers, give them upvotes.

Currently, I did change toCompletableFuture to:

JavaScript

Where executionContext got injected in the constructor, since I’m using Play Framework, or you can initialize your own using Executors.newFixedThreadPool(10) as for example! but you need to handle shutting down it and other stuff, more details can be learned from here ExecutorService in Java or A Guide to the Java ExecutorService.

So when I do call like this.getUserDataReference().child(path).push().setValueAsync(value), I do call it like:

JavaScript

Edit: if you prefer use ApiFutures:

JavaScript
Advertisement