Example usage for java.util.concurrent CompletableFuture join

List of usage examples for java.util.concurrent CompletableFuture join

Introduction

In this page you can find the example usage for java.util.concurrent CompletableFuture join.

Prototype

@SuppressWarnings("unchecked")
public T join() 

Source Link

Document

Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.

Usage

From source file:org.apache.hadoop.hbase.client.TestAsyncAdminBase.java

protected void createTableWithDefaultConf(TableName tableName, int regionReplication, byte[][] splitKeys,
        byte[]... families) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName)
            .setRegionReplication(regionReplication);
    for (byte[] family : families) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }//from  w w w.jav  a2s.c  o  m
    CompletableFuture<Void> future = splitKeys == null ? admin.createTable(builder.build())
            : admin.createTable(builder.build(), splitKeys);
    future.join();
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
}

From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageDAOTest.java

private MessageWithoutAttachment toMessage(
        CompletableFuture<Stream<CassandraMessageDAO.MessageResult>> readOptional)
        throws InterruptedException, java.util.concurrent.ExecutionException {
    return readOptional.join().map(CassandraMessageDAO.MessageResult::message).map(Pair::getLeft).findAny()
            .orElseThrow(() -> new IllegalStateException("Collection is not supposed to be empty"));
}

From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper.java

@Override
public MessageMetaData add(Mailbox mailbox, MailboxMessage message) throws MailboxException {
    CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();

    CompletableFuture<Optional<MessageUid>> uidFuture = uidProvider.nextUid(mailboxId);
    CompletableFuture<Optional<Long>> modseqFuture = modSeqProvider.nextModSeq(mailboxId);
    CompletableFuture.allOf(uidFuture, modseqFuture).join();

    message.setUid(uidFuture.join().orElseThrow(() -> new MailboxException(
            "Can not find a UID to save " + message.getMessageId() + " in " + mailboxId)));
    message.setModSeq(modseqFuture.join().orElseThrow(() -> new MailboxException(
            "Can not find a MODSEQ to save " + message.getMessageId() + " in " + mailboxId)));

    save(mailbox, message).thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
            .join();//from w ww  . java 2  s  .  c o m
    return new SimpleMessageMetaData(message);
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

private void throwOnOverQuota(String user, CompletableFuture<Long> sizeDifference)
        throws QuotaExceededException, StorageException {
    CompletableFuture<Optional<Long>> userQuotaFuture = cassandraSieveDAO.getQuota(user);
    CompletableFuture<Optional<Long>> globalQuotaFuture = cassandraSieveDAO.getQuota();
    CompletableFuture<Long> spaceUsedFuture = cassandraSieveDAO.spaceUsedBy(user);

    new SieveQuota(spaceUsedFuture.join(), limitToUse(userQuotaFuture, globalQuotaFuture))
            .checkOverQuotaUponModification(sizeDifference.join());
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

private Optional<Long> limitToUse(CompletableFuture<Optional<Long>> userQuota,
        CompletableFuture<Optional<Long>> globalQuota) {
    if (userQuota.join().isPresent()) {
        return userQuota.join();
    }//from w  ww.j  av  a  2 s  .com
    return globalQuota.join();
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

@Override
public void putScript(String user, String name, String content)
        throws QuotaExceededException, StorageException {
    CompletableFuture<Long> spaceUsed = spaceThatWillBeUsedByNewScript(user, name, content.length());
    throwOnOverQuota(user, spaceUsed);//from  www.j av a2  s . co  m

    CompletableFuture.allOf(updateSpaceUsed(user, spaceUsed.join()),
            cassandraSieveDAO.insertScript(user, name, content, false)).join();
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

@Override
public void setActive(String user, String name) throws ScriptNotFoundException {
    CompletableFuture<Void> unactivateOldScriptFuture = unactivateOldScript(user);
    CompletableFuture<Boolean> activateNewScript = updateScriptActivation(user, name, true);

    unactivateOldScriptFuture.join();
    if (!activateNewScript.join()) {
        throw new ScriptNotFoundException();
    }/*from  w  ww.  ja v a 2s .  co  m*/
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

@Override
public void renameScript(String user, String oldName, String newName)
        throws ScriptNotFoundException, DuplicateException {
    CompletableFuture<Boolean> scriptExistsFuture = cassandraSieveDAO.scriptExists(user, newName);
    CompletableFuture<Optional<ScriptContentAndActivation>> oldScriptFuture = cassandraSieveDAO
            .getScriptContentAndActivation(user, oldName);

    oldScriptFuture.join();
    if (scriptExistsFuture.join()) {
        throw new DuplicateException();
    }/*from  w  w w .  ja v  a  2s  .c o m*/

    performScriptRename(user, oldName, newName,
            oldScriptFuture.join().orElseThrow(ScriptNotFoundException::new));
}

From source file:org.apache.james.sieve.cassandra.CassandraSieveRepository.java

@Override
public boolean hasQuota(String user) {
    CompletableFuture<Boolean> userQuotaIsPresent = cassandraSieveDAO.getQuota(user)
            .thenApply(Optional::isPresent);
    CompletableFuture<Boolean> globalQuotaIsPresent = cassandraSieveDAO.getQuota()
            .thenApply(Optional::isPresent);
    CompletableFuture.allOf(userQuotaIsPresent, globalQuotaIsPresent).join();

    return userQuotaIsPresent.join() || globalQuotaIsPresent.join();
}

From source file:org.apache.pulsar.broker.service.persistent.PersistentTopic.java

public synchronized LongRunningProcessStatus compactionStatus() {
    final CompletableFuture<Long> current;
    synchronized (this) {
        current = currentCompaction;//from  ww w  .j av a2  s . co m
    }
    if (!current.isDone()) {
        return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.RUNNING);
    } else {
        try {
            if (current.join() == COMPACTION_NEVER_RUN) {
                return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.NOT_RUN);
            } else {
                return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.SUCCESS);
            }
        } catch (CancellationException | CompletionException e) {
            return LongRunningProcessStatus.forError(e.getMessage());
        }
    }
}