You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/29 01:15:01 UTC

[james-project] 27/27: JAMES-3153 use reactor.Retry insteaf of reactor-extra version

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b4de77a1e58708d380f8d7b669fd75f93970125c
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Fri Apr 24 12:14:20 2020 +0200

    JAMES-3153 use reactor.Retry insteaf of reactor-extra version
---
 server/blob/blob-objectstorage/pom.xml                |  4 ----
 .../objectstorage/StreamCompatibleBlobPutter.java     | 19 +++++++++----------
 .../blob/objectstorage/aws/AwsS3ObjectStorage.java    | 11 +++++------
 3 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/server/blob/blob-objectstorage/pom.xml b/server/blob/blob-objectstorage/pom.xml
index 4d2f297..5729d35 100644
--- a/server/blob/blob-objectstorage/pom.xml
+++ b/server/blob/blob-objectstorage/pom.xml
@@ -87,10 +87,6 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
-            <groupId>io.projectreactor.addons</groupId>
-            <artifactId>reactor-extra</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.jclouds.api</groupId>
             <artifactId>openstack-swift</artifactId>
             <version>${jclouds.version}</version>
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java
index 46d1d2e..35da9c8 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java
@@ -34,7 +34,7 @@ import org.jclouds.http.HttpResponseException;
 
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
-import reactor.retry.Retry;
+import reactor.util.retry.Retry;
 
 public class StreamCompatibleBlobPutter implements BlobPutter {
 
@@ -54,15 +54,14 @@ public class StreamCompatibleBlobPutter implements BlobPutter {
     public Mono<Void> putDirectly(ObjectStorageBucketName bucketName, Blob blob) {
         return Mono.fromRunnable(() -> blobStore.putBlob(bucketName.asString(), blob))
             .publishOn(Schedulers.elastic())
-            .retryWhen(Retry.onlyIf(retryContext -> needToCreateBucket(retryContext.exception(), bucketName))
-                .exponentialBackoff(FIRST_BACK_OFF, FOREVER)
-                .withBackoffScheduler(Schedulers.elastic())
-                .retryMax(MAX_RETRIES)
-                .doOnRetry(retryContext -> blobStore.createContainerInLocation(DEFAULT_LOCATION, bucketName.asString())))
-            .retryWhen(Retry.onlyIf(RetryContext -> isPutMethod(RetryContext.exception()))
-                .withBackoffScheduler(Schedulers.elastic())
-                .exponentialBackoff(FIRST_BACK_OFF, FOREVER)
-                .retryMax(RETRY_ONE_LAST_TIME_ON_CONCURRENT_SAVING))
+            .retryWhen(Retry
+                .backoff(MAX_RETRIES, FIRST_BACK_OFF)
+                .filter(throwable -> needToCreateBucket(throwable, bucketName))
+                .doBeforeRetry(retryContext -> blobStore.createContainerInLocation(DEFAULT_LOCATION, bucketName.asString())))
+            .retryWhen(Retry
+                    .backoff(RETRY_ONE_LAST_TIME_ON_CONCURRENT_SAVING, FIRST_BACK_OFF)
+                    .filter(this::isPutMethod)
+                    .scheduler(Schedulers.elastic()))
             .then();
     }
 
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
index fa58add..8cf22da 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
@@ -65,7 +65,7 @@ import com.google.inject.Module;
 
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
-import reactor.retry.Retry;
+import reactor.util.retry.Retry;
 
 public class AwsS3ObjectStorage {
 
@@ -180,11 +180,10 @@ public class AwsS3ObjectStorage {
             return Mono.<Void>fromRunnable(puttingAttempt)
                 .publishOn(Schedulers.elastic())
                 .retryWhen(Retry
-                    .<Void>onlyIf(retryContext -> needToCreateBucket(retryContext.exception()))
-                    .exponentialBackoff(FIRST_BACK_OFF, FOREVER)
-                    .withBackoffScheduler(Schedulers.elastic())
-                    .retryMax(MAX_RETRY_ON_EXCEPTION)
-                    .doOnRetry(retryContext -> s3Client.createBucket(bucketName.asString())));
+                    .backoff(MAX_RETRY_ON_EXCEPTION, FIRST_BACK_OFF)
+                    .filter(throwable -> needToCreateBucket(throwable))
+                    .doBeforeRetry(retryContext -> s3Client.createBucket(bucketName.asString()))
+                    .scheduler(Schedulers.elastic()));
         }
 
         private void uploadByFile(ObjectStorageBucketName bucketName, BlobId blobId, File file) throws InterruptedException {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org