@@ -112,8 +112,8 @@ this.waitForAppTask(taskID, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIM
112
112
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
113
113
*/
114
114
public GetApiKeyResponse waitForApiKey(
115
- ApiKeyOperation operation,
116
115
String key,
116
+ ApiKeyOperation operation,
117
117
ApiKey apiKey,
118
118
int maxRetries,
119
119
IntUnaryOperator timeout,
@@ -146,28 +146,26 @@ public GetApiKeyResponse waitForApiKey(
146
146
);
147
147
}
148
148
149
- // bypass lambda restriction to modify final object
150
- final GetApiKeyResponse[] addedKey = new GetApiKeyResponse[] { null } ;
151
-
152
- // check the status of the getApiKey method
153
- TaskUtils.retryUntil(
149
+ return TaskUtils.retryUntil(
154
150
() -> {
155
151
try {
156
- addedKey[0] = this.getApiKey(key, requestOptions);
157
- // magic number to signify we found the key
158
- return -2;
152
+ return this.getApiKey(key, requestOptions);
159
153
} catch (AlgoliaApiException e) {
160
- return e.getStatusCode();
154
+ if (e.getStatusCode() == 404) {
155
+ return null;
156
+ }
157
+
158
+ throw e;
161
159
}
162
160
},
163
- (Integer status ) -> {
161
+ (GetApiKeyResponse response ) -> {
164
162
switch (operation) {
165
163
case ADD:
166
- // stop either when the key is created or when we don' t receive 404
167
- return status == -2 || status != 404 ;
164
+ // stop when we don' t receive 404 meaning the key is created
165
+ return response != null ;
168
166
case DELETE:
169
167
// stop when the key is not found
170
- return status == 404 ;
168
+ return response == null ;
171
169
default:
172
170
// continue
173
171
return false;
@@ -176,84 +174,82 @@ public GetApiKeyResponse waitForApiKey(
176
174
maxRetries,
177
175
timeout
178
176
);
179
-
180
- return addedKey[0];
181
177
}
182
178
183
179
/**
184
180
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
185
181
*
186
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
187
182
* @param key The `key` that has been added or deleted.
183
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
188
184
* @param maxRetries The maximum number of retry. 50 by default. (optional)
189
185
* @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
190
186
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
191
187
*/
192
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , int maxRetries, IntUnaryOperator timeout, RequestOptions requestOptions) {
193
- return this.waitForApiKey(operation, key , null, maxRetries, timeout, requestOptions);
188
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , int maxRetries, IntUnaryOperator timeout, RequestOptions requestOptions) {
189
+ return this.waitForApiKey(key, operation , null, maxRetries, timeout, requestOptions);
194
190
}
195
191
/**
196
192
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
197
193
*
198
- * @param operation The `operation` that was done on a `key`.
199
194
* @param key The `key` that has been added, deleted or updated.
195
+ * @param operation The `operation` that was done on a `key`.
200
196
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
201
197
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
202
198
*/
203
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , ApiKey apiKey, RequestOptions requestOptions) {
204
- return this.waitForApiKey(operation, key , apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
199
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , ApiKey apiKey, RequestOptions requestOptions) {
200
+ return this.waitForApiKey(key, operation , apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
205
201
}
206
202
/**
207
203
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
208
204
*
209
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
210
205
* @param key The `key` that has been added or deleted.
206
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
211
207
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
212
208
*/
213
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , RequestOptions requestOptions) {
214
- return this.waitForApiKey(operation, key , null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
209
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , RequestOptions requestOptions) {
210
+ return this.waitForApiKey(key, operation , null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
215
211
}
216
212
/**
217
213
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
218
214
*
219
- * @param operation The `operation` that was done on a `key`.
220
215
* @param key The `key` that has been added, deleted or updated.
216
+ * @param operation The `operation` that was done on a `key`.
221
217
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
222
218
* @param maxRetries The maximum number of retry. 50 by default. (optional)
223
219
* @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
224
220
*/
225
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , ApiKey apiKey, int maxRetries, IntUnaryOperator timeout) {
226
- return this.waitForApiKey(operation, key , apiKey, maxRetries, timeout, null);
221
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , ApiKey apiKey, int maxRetries, IntUnaryOperator timeout) {
222
+ return this.waitForApiKey(key, operation , apiKey, maxRetries, timeout, null);
227
223
}
228
224
/**
229
225
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
230
226
*
231
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
232
227
* @param key The `key` that has been added or deleted.
228
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
233
229
* @param maxRetries The maximum number of retry. 50 by default. (optional)
234
230
* @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
235
231
*/
236
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , int maxRetries, IntUnaryOperator timeout) {
237
- return this.waitForApiKey(operation, key , null, maxRetries, timeout, null);
232
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , int maxRetries, IntUnaryOperator timeout) {
233
+ return this.waitForApiKey(key, operation , null, maxRetries, timeout, null);
238
234
}
239
235
/**
240
236
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
241
237
*
242
- * @param operation The `operation` that was done on a `key`.
243
238
* @param key The `key` that has been added, deleted or updated.
239
+ * @param operation The `operation` that was done on a `key`.
244
240
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
245
241
*/
246
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key , ApiKey apiKey) {
247
- return this.waitForApiKey(operation, key , apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
242
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation , ApiKey apiKey) {
243
+ return this.waitForApiKey(key, operation , apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
248
244
}
249
245
/**
250
246
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
251
247
*
252
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
253
248
* @param key The `key` that has been added or deleted.
249
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
254
250
*/
255
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key ) {
256
- return this.waitForApiKey(operation, key , null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
251
+ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation ) {
252
+ return this.waitForApiKey(key, operation , null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
257
253
}
258
254
259
255
/**
0 commit comments