This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#13] Automatic retry of selected calls using asyn-retry library
- Loading branch information
1 parent
6491abe
commit 67154ad
Showing
18 changed files
with
229 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...e/src/main/groovy/com/ofg/infrastructure/web/resttemplate/fluent/SyncRetryExecutor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.ofg.infrastructure.web.resttemplate.fluent | ||
|
||
import com.google.common.util.concurrent.Futures | ||
import com.google.common.util.concurrent.ListenableFuture | ||
import com.nurkiewicz.asyncretry.AsyncRetryContext | ||
import com.nurkiewicz.asyncretry.RetryExecutor | ||
import com.nurkiewicz.asyncretry.function.RetryCallable | ||
import com.nurkiewicz.asyncretry.function.RetryRunnable | ||
import com.nurkiewicz.asyncretry.policy.RetryPolicy | ||
|
||
import java.util.concurrent.Callable | ||
|
||
/** | ||
* TODO Move to async-retry library itself | ||
*/ | ||
class SyncRetryExecutor implements RetryExecutor { | ||
|
||
private static final AsyncRetryContext RETRY_CONTEXT = new AsyncRetryContext(RetryPolicy.DEFAULT) | ||
|
||
private SyncRetryExecutor() { | ||
} | ||
|
||
public static SyncRetryExecutor INSTANCE = new SyncRetryExecutor() | ||
|
||
@Override | ||
ListenableFuture<Void> doWithRetry(RetryRunnable action) { | ||
action.run(RETRY_CONTEXT) | ||
return Futures.immediateFuture(null) | ||
} | ||
|
||
@Override | ||
def <V> ListenableFuture<V> getWithRetry(Callable<V> task) { | ||
V result = task.call() | ||
return Futures.immediateFuture(result) | ||
} | ||
|
||
@Override | ||
def <V> ListenableFuture<V> getWithRetry(RetryCallable<V> task) { | ||
V result = task.call(RETRY_CONTEXT) | ||
return Futures.immediateFuture(result) | ||
} | ||
|
||
@Override | ||
def <V> ListenableFuture<V> getFutureWithRetry(RetryCallable<ListenableFuture<V>> task) { | ||
return Futures.immediateFuture(task.call(RETRY_CONTEXT).get()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
...ofg/infrastructure/web/resttemplate/fluent/common/response/receive/ObjectReceiving.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive | ||
|
||
import com.google.common.util.concurrent.ListenableFuture | ||
|
||
|
||
/** | ||
* Interface that defines what is the type of the received response. | ||
* It will return an object of provided class. | ||
*/ | ||
interface ObjectReceiving { | ||
abstract class ObjectReceiving { | ||
|
||
public <T> T ofType(Class<T> responseType) | ||
public <T> T ofType(Class<T> responseType) { | ||
return ofTypeAsync(responseType).get() | ||
} | ||
|
||
public abstract <T> ListenableFuture<T> ofTypeAsync(Class<T> responseType) | ||
} |
8 changes: 6 additions & 2 deletions
8
...astructure/web/resttemplate/fluent/common/response/receive/ResponseEntityReceiving.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive | ||
|
||
import com.google.common.util.concurrent.ListenableFuture | ||
import org.springframework.http.ResponseEntity | ||
|
||
/** | ||
* Interface that defines what is the type of the received response. | ||
* It will return a {@link ResponseEntity} of the provided class. | ||
*/ | ||
interface ResponseEntityReceiving { | ||
public <T> ResponseEntity<T> ofType(Class<T> responseType) | ||
abstract class ResponseEntityReceiving { | ||
public abstract <T> ListenableFuture<ResponseEntity<T>> ofTypeAsync(Class<T> responseType) | ||
public <T> ResponseEntity<T> ofType(Class<T> responseType) { | ||
return ofTypeAsync(responseType).get() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.