List of usage examples for java.util.concurrent CompletableFuture completedFuture
public static <U> CompletableFuture<U> completedFuture(U value)
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMailboxMapper.java
private CompletableFuture<Boolean> trySave(SimpleMailbox cassandraMailbox, CassandraId cassandraId) { return mailboxPathDAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId).thenCompose(result -> { if (result) { return mailboxDAO .retrieveMailbox(/*w w w. j av a2 s . com*/ cassandraId) .thenCompose(optional -> CompletableFuture.allOf(optional .map(storedMailbox -> mailboxPathDAO.delete(storedMailbox.generateAssociatedPath())) .orElse(CompletableFuture.completedFuture(null)), mailboxDAO.save(cassandraMailbox)) .thenApply(any -> result)); } return CompletableFuture.completedFuture(result); }); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageIdMapper.java
private Function<Pair<CassandraMessageDAO.MessageWithoutAttachment, Stream<CassandraMessageDAO.MessageAttachmentRepresentation>>, CompletableFuture<Pair<CassandraMessageDAO.MessageWithoutAttachment, Stream<MessageAttachment>>>> loadAttachments( FetchType fetchType) {// w ww .j ava 2s . com if (fetchType == FetchType.Full || fetchType == FetchType.Body) { return pair -> attachmentLoader.getAttachments(pair.getRight().collect(Guavate.toImmutableList())) .thenApply(attachments -> Pair.of(pair.getLeft(), attachments.stream())); } else { return pair -> CompletableFuture.completedFuture(Pair.of(pair.getLeft(), Stream.of())); } }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageIdMapper.java
@Override public void delete(MessageId messageId, List<MailboxId> mailboxIds) { CassandraMessageId cassandraMessageId = (CassandraMessageId) messageId; mailboxIds.stream()//from www.j a v a 2s .c o m .map(mailboxId -> retrieveAndDeleteIndices(cassandraMessageId, Optional.of((CassandraId) mailboxId))) .reduce((f1, f2) -> CompletableFuture.allOf(f1, f2)).orElse(CompletableFuture.completedFuture(null)) .join(); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageIdMapper.java
private CompletableFuture<Void> retrieveAndDeleteIndices(CassandraMessageId messageId, Optional<CassandraId> mailboxId) { return imapUidDAO.retrieve(messageId, mailboxId) .thenCompose(composedMessageIds -> composedMessageIds.map(this::deleteIds) .reduce((f1, f2) -> CompletableFuture.allOf(f1, f2)) .orElse(CompletableFuture.completedFuture(null))); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageIdMapper.java
private Optional<Pair<Flags, ComposedMessageIdWithMetaData>> updateFlags( ComposedMessageIdWithMetaData oldComposedId, ComposedMessageIdWithMetaData newComposedId) { return imapUidDAO.updateMetadata(newComposedId, oldComposedId.getModSeq()) .thenCompose(updateSuccess -> Optional.of(updateSuccess).filter(b -> b).map( (Boolean any) -> messageIdDAO.updateMetadata(newComposedId).thenApply(v -> updateSuccess)) .orElse(CompletableFuture.completedFuture(updateSuccess))) .thenApply(success -> Optional.of(success).filter(b -> b) .map(any -> Pair.of(oldComposedId.getFlags(), newComposedId))) .join();//w ww. ja va 2 s . c o m }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper.java
private CompletableFuture<Void> deleteAsFuture(MailboxMessage message, CassandraId mailboxId) { return messageIdDAO.retrieve(mailboxId, message.getUid()).thenCompose(optional -> optional .map(this::deleteUsingMailboxId).orElse(CompletableFuture.completedFuture(null))); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper.java
@Override public MessageMetaData move(Mailbox destinationMailbox, MailboxMessage original) throws MailboxException { CassandraId originalMailboxId = (CassandraId) original.getMailboxId(); MessageMetaData messageMetaData = copy(destinationMailbox, original); retrieveMessageId(originalMailboxId, original).thenCompose(optional -> optional .map(this::deleteUsingMailboxId).orElse(CompletableFuture.completedFuture(null))).join(); return messageMetaData; }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper.java
private boolean updateFlags(MailboxMessage message, long oldModSeq) { ComposedMessageIdWithMetaData composedMessageIdWithMetaData = ComposedMessageIdWithMetaData.builder() .composedMessageId(//from w w w.j a va2 s . c om new ComposedMessageId(message.getMailboxId(), message.getMessageId(), message.getUid())) .modSeq(message.getModSeq()).flags(message.createFlags()).build(); return imapUidDAO.updateMetadata(composedMessageIdWithMetaData, oldModSeq) .thenCompose(success -> Optional.of(success).filter(b -> b) .map((Boolean any) -> messageIdDAO.updateMetadata(composedMessageIdWithMetaData) .thenApply(v -> success)) .orElse(CompletableFuture.completedFuture(success))) .join(); }
From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java
public CompletableFuture<Void> updateSpaceUsed(String user, long spaceUsed) { if (spaceUsed == 0) { return CompletableFuture.completedFuture(null); }//from w w w . j a v a 2 s . co m return cassandraSieveDAO.updateSpaceUsed(user, spaceUsed); }
From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java
private CompletableFuture<Void> unactivateOldScript(String user) { return cassandraSieveDAO.getActiveName(user) .thenCompose(scriptNameOptional -> scriptNameOptional.map( scriptName -> updateScriptActivation(user, scriptName, false).<Void>thenApply(any -> null)) .orElse(CompletableFuture.completedFuture(null))); }