1616
1717package com .google .firebase .database ;
1818
19+ import com .google .api .core .ApiFuture ;
1920import com .google .firebase .database .DatabaseReference .CompletionListener ;
2021import com .google .firebase .database .core .Path ;
2122import com .google .firebase .database .core .Repo ;
2728import com .google .firebase .database .utilities .Utilities ;
2829import com .google .firebase .database .utilities .Validation ;
2930import com .google .firebase .database .utilities .encoding .CustomClassMapper ;
31+ import com .google .firebase .internal .TaskToApiFuture ;
3032import com .google .firebase .tasks .Task ;
3133
3234import java .util .Map ;
@@ -51,44 +53,35 @@ public class OnDisconnect {
5153 }
5254
5355 /**
54- * Ensure the data at this location is set to the specified value when the client is disconnected
55- * (due to closing the browser, navigating to a new page, or network issues). <br>
56- * <br>
57- * This method is especially useful for implementing "presence" systems, where a value should be
58- * changed or cleared when a user disconnects so that they appear "offline" to other users.
56+ * Similar to {@link #setValueAsync(Object)}, but returns a Task.
5957 *
6058 * @param value The value to be set when a disconnect occurs
6159 * @return The {@link Task} for this operation.
60+ * @deprecated Use {@link #setValueAsync(Object)}
6261 */
6362 public Task <Void > setValue (Object value ) {
6463 return onDisconnectSetInternal (value , PriorityUtilities .NullPriority (), null );
6564 }
6665
6766 /**
68- * Ensure the data at this location is set to the specified value and priority when the client is
69- * disconnected (due to closing the browser, navigating to a new page, or network issues). <br>
70- * <br>
71- * This method is especially useful for implementing "presence" systems, where a value should be
72- * changed or cleared when a user disconnects so that they appear "offline" to other users.
67+ * Similar to {@link #setValueAsync(Object, String)}, but returns a Task.
7368 *
7469 * @param value The value to be set when a disconnect occurs
7570 * @param priority The priority to be set when a disconnect occurs
7671 * @return The {@link Task} for this operation.
72+ * @deprecated Use {@link #setValueAsync(Object, String)}
7773 */
7874 public Task <Void > setValue (Object value , String priority ) {
7975 return onDisconnectSetInternal (value , PriorityUtilities .parsePriority (priority ), null );
8076 }
8177
8278 /**
83- * Ensure the data at this location is set to the specified value and priority when the client is
84- * disconnected (due to closing the browser, navigating to a new page, or network issues). <br>
85- * <br>
86- * This method is especially useful for implementing "presence" systems, where a value should be
87- * changed or cleared when a user disconnects so that they appear "offline" to other users.
79+ * Similar to {@link #setValueAsync(Object, double)}, but returns a Task.
8880 *
8981 * @param value The value to be set when a disconnect occurs
9082 * @param priority The priority to be set when a disconnect occurs
9183 * @return The {@link Task} for this operation.
84+ * @deprecated Use {@link #setValueAsync(Object, double)}
9285 */
9386 public Task <Void > setValue (Object value , double priority ) {
9487 return onDisconnectSetInternal (value , PriorityUtilities .parsePriority (priority ), null );
@@ -153,6 +146,50 @@ public void setValue(Object value, Map priority, CompletionListener listener) {
153146 onDisconnectSetInternal (value , PriorityUtilities .parsePriority (priority ), listener );
154147 }
155148
149+ /**
150+ * Ensure the data at this location is set to the specified value when the client is disconnected
151+ * (due to closing the browser, navigating to a new page, or network issues). <br>
152+ * <br>
153+ * This method is especially useful for implementing "presence" systems, where a value should be
154+ * changed or cleared when a user disconnects so that they appear "offline" to other users.
155+ *
156+ * @param value The value to be set when a disconnect occurs
157+ * @return The ApiFuture for this operation.
158+ */
159+ public ApiFuture <Void > setValueAsync (Object value ) {
160+ return new TaskToApiFuture <>(setValue (value ));
161+ }
162+
163+ /**
164+ * Ensure the data at this location is set to the specified value and priority when the client is
165+ * disconnected (due to closing the browser, navigating to a new page, or network issues). <br>
166+ * <br>
167+ * This method is especially useful for implementing "presence" systems, where a value should be
168+ * changed or cleared when a user disconnects so that they appear "offline" to other users.
169+ *
170+ * @param value The value to be set when a disconnect occurs
171+ * @param priority The priority to be set when a disconnect occurs
172+ * @return The ApiFuture for this operation.
173+ */
174+ public ApiFuture <Void > setValueAsync (Object value , String priority ) {
175+ return new TaskToApiFuture <>(setValue (value , priority ));
176+ }
177+
178+ /**
179+ * Ensure the data at this location is set to the specified value and priority when the client is
180+ * disconnected (due to closing the browser, navigating to a new page, or network issues). <br>
181+ * <br>
182+ * This method is especially useful for implementing "presence" systems, where a value should be
183+ * changed or cleared when a user disconnects so that they appear "offline" to other users.
184+ *
185+ * @param value The value to be set when a disconnect occurs
186+ * @param priority The priority to be set when a disconnect occurs
187+ * @return The ApiFuture for this operation.
188+ */
189+ public ApiFuture <Void > setValueAsync (Object value , double priority ) {
190+ return new TaskToApiFuture <>(setValue (value , priority ));
191+ }
192+
156193 private Task <Void > onDisconnectSetInternal (
157194 Object value , Node priority , final CompletionListener optListener ) {
158195 Validation .validateWritablePath (path );
@@ -174,10 +211,11 @@ public void run() {
174211 // Update
175212
176213 /**
177- * Ensure the data has the specified child values updated when the client is disconnected
214+ * Similar to {@link #updateChildrenAsync(Map)}, but returns a Task.
178215 *
179216 * @param update The paths to update, along with their desired values
180217 * @return The {@link Task} for this operation.
218+ * @deprecated Use {@link #updateChildrenAsync(Map)}
181219 */
182220 public Task <Void > updateChildren (Map <String , Object > update ) {
183221 return updateChildrenInternal (update , null );
@@ -193,6 +231,16 @@ public void updateChildren(final Map<String, Object> update, final CompletionLis
193231 updateChildrenInternal (update , listener );
194232 }
195233
234+ /**
235+ * Ensure the data has the specified child values updated when the client is disconnected
236+ *
237+ * @param update The paths to update, along with their desired values
238+ * @return The ApiFuture for this operation.
239+ */
240+ public ApiFuture <Void > updateChildrenAsync (Map <String , Object > update ) {
241+ return new TaskToApiFuture <>(updateChildren (update ));
242+ }
243+
196244 private Task <Void > updateChildrenInternal (
197245 final Map <String , Object > update , final CompletionListener optListener ) {
198246 final Map <Path , Node > parsedUpdate = Validation .parseAndValidateUpdate (path , update );
@@ -210,9 +258,10 @@ public void run() {
210258 // Remove
211259
212260 /**
213- * Remove the value at this location when the client disconnects
261+ * Similar to {@link #removeValueAsync()}, but returns a Task.
214262 *
215263 * @return The {@link Task} for this operation.
264+ * @deprecated Use {@link #removeValueAsync()}
216265 */
217266 public Task <Void > removeValue () {
218267 return setValue (null );
@@ -227,12 +276,22 @@ public void removeValue(CompletionListener listener) {
227276 setValue (null , listener );
228277 }
229278
279+ /**
280+ * Remove the value at this location when the client disconnects
281+ *
282+ * @return The ApiFuture for this operation.
283+ */
284+ public ApiFuture <Void > removeValueAsync () {
285+ return new TaskToApiFuture <>(removeValue ());
286+ }
287+
230288 // Cancel the operation
231289
232290 /**
233- * Cancel any disconnect operations that are queued up at this location
291+ * Similar to {@link #cancelAsync()} ()}, but returns a Task.
234292 *
235293 * @return The {@link Task} for this operation.
294+ * @deprecated Use {@link #cancelAsync()}.
236295 */
237296 public Task <Void > cancel () {
238297 return cancelInternal (null );
@@ -247,6 +306,15 @@ public void cancel(final CompletionListener listener) {
247306 cancelInternal (listener );
248307 }
249308
309+ /**
310+ * Cancel any disconnect operations that are queued up at this location
311+ *
312+ * @return The ApiFuture for this operation.
313+ */
314+ public ApiFuture <Void > cancelAsync () {
315+ return new TaskToApiFuture <>(cancel ());
316+ }
317+
250318 private Task <Void > cancelInternal (final CompletionListener optListener ) {
251319 final Pair <Task <Void >, CompletionListener > wrapped = Utilities .wrapOnComplete (optListener );
252320 repo .scheduleNow (
0 commit comments