16
16
package com .google .firebase .projectmanagement ;
17
17
18
18
import static com .google .common .base .Preconditions .checkArgument ;
19
+ import static com .google .common .base .Preconditions .checkNotNull ;
19
20
20
21
import com .google .api .client .http .HttpResponseInterceptor ;
21
22
import com .google .api .client .util .Base64 ;
22
23
import com .google .api .client .util .Key ;
24
+ import com .google .api .client .util .Sleeper ;
23
25
import com .google .api .core .ApiAsyncFunction ;
24
26
import com .google .api .core .ApiFunction ;
25
27
import com .google .api .core .ApiFuture ;
@@ -51,6 +53,8 @@ class FirebaseProjectManagementServiceImpl implements AndroidAppService, IosAppS
51
53
private static final String IOS_NAMESPACE_PROPERTY = "bundle_id" ;
52
54
53
55
private final FirebaseApp app ;
56
+ private final Sleeper sleeper ;
57
+ private final Scheduler scheduler ;
54
58
private final HttpHelper httpHelper ;
55
59
56
60
private final CreateAndroidAppFromAppIdFunction createAndroidAppFromAppIdFunction =
@@ -59,7 +63,13 @@ class FirebaseProjectManagementServiceImpl implements AndroidAppService, IosAppS
59
63
new CreateIosAppFromAppIdFunction ();
60
64
61
65
FirebaseProjectManagementServiceImpl (FirebaseApp app ) {
62
- this .app = app ;
66
+ this (app , Sleeper .DEFAULT , new FirebaseAppScheduler (app ));
67
+ }
68
+
69
+ FirebaseProjectManagementServiceImpl (FirebaseApp app , Sleeper sleeper , Scheduler scheduler ) {
70
+ this .app = checkNotNull (app );
71
+ this .sleeper = checkNotNull (sleeper );
72
+ this .scheduler = checkNotNull (scheduler );
63
73
this .httpHelper = new HttpHelper (
64
74
app .getOptions ().getJsonFactory (),
65
75
app .getOptions ().getHttpTransport ().createRequestFactory (
@@ -187,7 +197,7 @@ protected List<T> execute() throws FirebaseProjectManagementException {
187
197
projectId ,
188
198
platformResourceName ,
189
199
MAXIMUM_LIST_APPS_PAGE_SIZE );
190
- ImmutableList .Builder <T > builder = ImmutableList .< T > builder ();
200
+ ImmutableList .Builder <T > builder = ImmutableList .builder ();
191
201
ListAppsResponse parsedResponse ;
192
202
do {
193
203
parsedResponse = new ListAppsResponse ();
@@ -361,10 +371,9 @@ private WaitOperationFunction(String projectId) {
361
371
* or an exception if an error occurred during polling.
362
372
*/
363
373
@ Override
364
- public ApiFuture <String > apply (String operationName ) throws FirebaseProjectManagementException {
365
- SettableApiFuture <String > settableFuture = SettableApiFuture .<String >create ();
366
- ImplFirebaseTrampolines .schedule (
367
- app ,
374
+ public ApiFuture <String > apply (String operationName ) {
375
+ SettableApiFuture <String > settableFuture = SettableApiFuture .create ();
376
+ scheduler .schedule (
368
377
new WaitOperationRunnable (
369
378
/* numberOfPreviousPolls= */ 0 ,
370
379
operationName ,
@@ -417,8 +426,7 @@ public void run() {
417
426
long delayMillis = (long ) (
418
427
POLL_BASE_WAIT_TIME_MILLIS
419
428
* Math .pow (POLL_EXPONENTIAL_BACKOFF_FACTOR , numberOfPreviousPolls + 1 ));
420
- ImplFirebaseTrampolines .schedule (
421
- app ,
429
+ scheduler .schedule (
422
430
new WaitOperationRunnable (
423
431
numberOfPreviousPolls + 1 ,
424
432
operationName ,
@@ -725,12 +733,26 @@ public static class ShaCertificateResponse {
725
733
private String certType ;
726
734
}
727
735
736
+ private static class FirebaseAppScheduler implements Scheduler {
737
+
738
+ private final FirebaseApp app ;
739
+
740
+ FirebaseAppScheduler (FirebaseApp app ) {
741
+ this .app = checkNotNull (app );
742
+ }
743
+
744
+ @ Override
745
+ public void schedule (Runnable runnable , long delayMillis ) {
746
+ ImplFirebaseTrampolines .schedule (app , runnable , delayMillis );
747
+ }
748
+ }
749
+
728
750
/* Helper methods. */
729
751
730
752
private void sleepOrThrow (String projectId , long delayMillis )
731
753
throws FirebaseProjectManagementException {
732
754
try {
733
- Thread .sleep (delayMillis );
755
+ sleeper .sleep (delayMillis );
734
756
} catch (InterruptedException e ) {
735
757
throw HttpHelper .createFirebaseProjectManagementException (
736
758
projectId ,
0 commit comments