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 rc...@apache.org on 2020/06/11 02:58:30 UTC
[james-project] branch master updated: JAMES-3201 Vavr Either
adoption
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new 9b9a07f JAMES-3201 Vavr Either adoption
9b9a07f is described below
commit 9b9a07fa66645664a1fe4cdf4926b74a52994467
Author: LanKhuat <kh...@gmail.com>
AuthorDate: Tue Jun 9 14:24:43 2020 +0700
JAMES-3201 Vavr Either adoption
---
mailbox/tools/indexer/pom.xml | 9 ++++----
.../mailbox/tools/indexer/ReIndexerPerformer.java | 24 +++++++++++-----------
pom.xml | 5 +++++
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/mailbox/tools/indexer/pom.xml b/mailbox/tools/indexer/pom.xml
index e572be5..5e8b498 100644
--- a/mailbox/tools/indexer/pom.xml
+++ b/mailbox/tools/indexer/pom.xml
@@ -115,6 +115,10 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>io.vavr</groupId>
+ <artifactId>vavr</artifactId>
+ </dependency>
+ <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
@@ -124,11 +128,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.functionaljava</groupId>
- <artifactId>functionaljava-java8</artifactId>
- <version>4.8.1</version>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index f9e2c5e..60b47b0 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
-import fj.data.Either;
+import io.vavr.control.Either;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -189,7 +189,7 @@ public class ReIndexerPerformer {
.findMailboxByIdReactive(mailboxId)
.flatMap(mailbox -> fullyReadMessage(mailboxSession, mailbox, uid)
.map(message -> Either.<Failure, ReIndexingEntry>right(new ReIndexingEntry(mailbox, mailboxSession, message)))
- .flatMap(entryOrFailure -> reIndexMessage(entryOrFailure, reprocessingContext)))
+ .flatMap(entryOrFailure -> reIndex(entryOrFailure, reprocessingContext)))
.switchIfEmpty(Mono.just(Result.COMPLETED));
}
@@ -278,21 +278,21 @@ public class ReIndexerPerformer {
private Mono<Task.Result> reIndexMessages(Flux<Either<Failure, ReIndexingEntry>> entriesToIndex, RunningOptions runningOptions, ReprocessingContext reprocessingContext) {
return ReactorUtils.Throttler.<Either<Failure, ReIndexingEntry>, Task.Result>forOperation(
- entry -> reIndexMessage(entry, reprocessingContext))
+ entry -> reIndex(entry, reprocessingContext))
.window(runningOptions.getMessagesPerSecond(), Duration.ofSeconds(1))
.throttle(entriesToIndex)
.reduce(Task::combine)
.switchIfEmpty(Mono.just(Result.COMPLETED));
}
- private Mono<Task.Result> reIndexMessage(Either<Failure, ReIndexingEntry> entryOrFailure, ReprocessingContext reprocessingContext) {
- return toMono(entryOrFailure.right().map(this::index))
- .map(this::flapMapRight)
- .map(either -> recordIndexingResult(reprocessingContext, either));
+ private Mono<Task.Result> reIndex(Either<Failure, ReIndexingEntry> failureOrEntry, ReprocessingContext reprocessingContext) {
+ return toMono(failureOrEntry.map(this::index))
+ .map(this::flatten)
+ .map(failureOrTaskResult -> recordIndexingResult(failureOrTaskResult, reprocessingContext));
}
- private Result recordIndexingResult(ReprocessingContext reprocessingContext, Either<Failure, Result> either) {
- return either.either(
+ private Result recordIndexingResult(Either<Failure, Result> failureOrTaskResult, ReprocessingContext reprocessingContext) {
+ return failureOrTaskResult.fold(
failure -> {
failure.recordFailure(reprocessingContext);
return Result.PARTIAL;
@@ -309,11 +309,11 @@ public class ReIndexerPerformer {
});
}
- private <X, Y> Either<X, Y> flapMapRight(Either<X, Either<X, Y>> nestedEither) {
- return nestedEither.right().bind(either -> either);
+ private <X, Y> Either<X, Y> flatten(Either<X, Either<X, Y>> nestedEither) {
+ return nestedEither.getOrElseGet(Either::left);
}
private <X, Y> Mono<Either<X, Y>> toMono(Either<X, Mono<Y>> either) {
- return either.either(x -> Mono.just(Either.left(x)), yMono -> yMono.map(Either::right));
+ return either.fold(x -> Mono.just(Either.left(x)), yMono -> yMono.map(Either::right));
}
}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0e87aae..bea0a41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2202,6 +2202,11 @@
<version>${netty.version}</version>
</dependency>
<dependency>
+ <groupId>io.vavr</groupId>
+ <artifactId>vavr</artifactId>
+ <version>0.9.0</version>
+ </dependency>
+ <dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${javax-activation.version}</version>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org