@Override public boolean hasQuota(User user) { return CompletableFutureUtil.combine( cassandraSieveQuotaDAO.getQuota(user).thenApply(Optional::isPresent), cassandraSieveQuotaDAO.getQuota().thenApply(Optional::isPresent), (b1, b2) -> b1 || b2) .join(); }
private CompletableFuture<Optional<SimpleMailbox>> retrieveMailbox(CassandraId mailboxId) { CompletableFuture<MailboxACL> aclCompletableFuture = cassandraACLMapper.getACL(mailboxId); CompletableFuture<Optional<SimpleMailbox>> simpleMailboxFuture = mailboxDAO.retrieveMailbox(mailboxId); return CompletableFutureUtil.combine( aclCompletableFuture, simpleMailboxFuture, this::addAcl); }
private CompletableFuture<byte[]> getFullContent(Row row) { return CompletableFutureUtil.combine( getHeaderContent(row), getBodyContent(row), Bytes::concat); }
private CompletableFuture<Pair<BlobId, BlobId>> saveContent(MailboxMessage message) throws MailboxException { try { byte[] headerContent = IOUtils.toByteArray(message.getHeaderContent()); byte[] bodyContent = IOUtils.toByteArray(message.getBodyContent()); return CompletableFutureUtil.combine( blobStore.save(headerContent), blobStore.save(bodyContent), Pair::of); } catch (IOException e) { throw new MailboxException("Error saving mail content", e); } }
@Test public void combineShouldReturnCombinationOfBothSuppliedFutures() { int value1 = 18; int value2 = 12; assertThat(CompletableFutureUtil.combine( CompletableFuture.completedFuture(value1), CompletableFuture.completedFuture(value2), (a, b) -> 2 * a + b) .join()) .isEqualTo(2 * value1 + value2); }
public CompletableFuture<Void> manageVacation(MailAddress recipient, Mail processedMail, ZonedDateTime processingDate) { AccountId accountId = AccountId.fromString(recipient.toString()); return CompletableFutureUtil.combine( vacationRepository.retrieveVacation(accountId), notificationRegistry.isRegistered( AccountId.fromString(recipient.toString()), RecipientId.fromMailAddress(processedMail.getMaybeSender().get())), (vacation, alreadySent) -> sendNotificationIfRequired(recipient, processedMail, processingDate, vacation, alreadySent)) .thenCompose(Function.identity()); }