public final class AsyncClient extends java.lang.Object implements FirebaseClient
FirebaseClient
which executes write operations asynchronously.
Read operations are considered less frequent and less costly, thus are executed synchronously.
Constructor and Description |
---|
AsyncClient(FirebaseClient delegate)
Creates a new async client with the given delegate.
|
AsyncClient(FirebaseClient delegate,
java.util.concurrent.Executor executor)
Creates a new async client with the given delegate and the given executor.
|
Modifier and Type | Method and Description |
---|---|
void |
create(io.spine.web.firebase.NodePath nodePath,
NodeValue value)
Writes the specified value to the Firebase database node.
|
void |
delete(io.spine.web.firebase.NodePath nodePath)
Deletes the node under the given path.
|
java.util.Optional<NodeValue> |
fetchNode(io.spine.web.firebase.NodePath nodePath)
Retrieves the value of the specified Firebase database node.
|
void |
subscribeTo(io.spine.web.firebase.NodePath nodePath,
com.google.firebase.database.ChildEventListener listener)
Subscribes to the child events of the given node.
|
void |
update(io.spine.web.firebase.NodePath nodePath,
NodeValue value)
Merges the specified value to the Firebase database node.
|
public AsyncClient(FirebaseClient delegate, java.util.concurrent.Executor executor)
It is a responsibility of the user to shut down the executor gracefully.
delegate
- the firebase client which performs the requestsexecutor
- the Executor
which executes the write requestspublic AsyncClient(FirebaseClient delegate)
The resulting client uses the ForkJoinPool.commonPool()
to execute the write
operations. Note that this is the same Executor
which is used by default in the Java
concurrency API, such as CompletableFuture
and the conventional
implementations of Stream
.
delegate
- the firebase client which performs the requestsAsyncClient.AsyncClient(FirebaseClient, Executor)
public java.util.Optional<NodeValue> fetchNode(io.spine.web.firebase.NodePath nodePath)
FirebaseClient
The null
value (i.e. the node is not present in the database) is returned as
Optional.empty()
.
fetchNode
in interface FirebaseClient
nodePath
- the path to the requested node in the databaseOptional
if the node is not present in the databasepublic void subscribeTo(io.spine.web.firebase.NodePath nodePath, com.google.firebase.database.ChildEventListener listener)
FirebaseClient
subscribeTo
in interface FirebaseClient
nodePath
- the path to the node to subscribe tolistener
- the callbacks invoked on child eventspublic void create(io.spine.web.firebase.NodePath nodePath, NodeValue value)
FirebaseClient
If the node exists, the value is overridden.
create
in interface FirebaseClient
nodePath
- the path to the node in the Firebase databasevalue
- the value to writepublic void update(io.spine.web.firebase.NodePath nodePath, NodeValue value)
FirebaseClient
If the node doesn't exist, it is created with the given value.
If the node exists, the value entries are added to the node children overwriting common ones if present.
update
in interface FirebaseClient
nodePath
- the path to the node in the Firebase databasevalue
- the value to mergepublic void delete(io.spine.web.firebase.NodePath nodePath)
FirebaseClient
Does nothing if the node does not exist.
delete
in interface FirebaseClient
nodePath
- the path to the node to delete