You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/06/03 06:09:56 UTC
[james-project] 04/06: JAMES-3773 Improve slightly random storing
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 4105bdd1d05cf54c9ec32d0b75f482a4f28c1857
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sat May 28 15:41:12 2022 +0700
JAMES-3773 Improve slightly random storing
---
.../org/apache/james/transport/mailets/RandomStoring.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
index b356b4e0ae..e0f24aed8c 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
@@ -26,8 +26,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
import java.util.function.Supplier;
-import java.util.stream.Stream;
import javax.inject.Inject;
import javax.mail.MessagingException;
@@ -50,6 +50,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
@@ -71,7 +72,7 @@ public class RandomStoring extends GenericMailet {
this.usersRepository = usersRepository;
this.mailboxManager = mailboxManager;
this.randomRecipientsNumbers = () -> ThreadLocalRandom.current().nextInt(MIN_NUMBER_OF_RECIPIENTS, MAX_NUMBER_OF_RECIPIENTS + 1);
- this.reroutingInfos = Mono.fromCallable(this::retrieveReroutingInfos).cache(CACHE_DURATION);
+ this.reroutingInfos = Mono.fromCallable(this::retrieveReroutingInfos).flatMap(Function.identity()).cache(CACHE_DURATION);
}
@Override
@@ -109,18 +110,17 @@ public class RandomStoring extends GenericMailet {
.collect(ImmutableSet.toImmutableSet());
}
- private List<ReroutingInfos> retrieveReroutingInfos() throws UsersRepositoryException {
- return Iterators.toStream(usersRepository.list())
+ private Mono<List<ReroutingInfos>> retrieveReroutingInfos() throws UsersRepositoryException {
+ return Iterators.toFlux(usersRepository.list())
.flatMap(this::buildReRoutingInfos)
.collect(ImmutableList.toImmutableList());
}
- private Stream<ReroutingInfos> buildReRoutingInfos(Username username) {
+ private Flux<ReroutingInfos> buildReRoutingInfos(Username username) {
try {
MailboxSession session = mailboxManager.createSystemSession(username);
return mailboxManager
.search(MailboxQuery.privateMailboxesBuilder(session).build(), Minimal, session)
- .toStream()
.map(metaData -> new ReroutingInfos(metaData.getPath().getName(), username));
} catch (Exception e) {
throw new RuntimeException(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org