Example usage for java.util.concurrent CompletableFuture hashCode

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:ai.grakn.client.LoaderClient.java

private void unblock(CompletableFuture<Json> status) {
    blocker.release();
    futures.remove(status.hashCode());
}

From source file:ai.grakn.client.LoaderClient.java

/**
 * Send a collection of insert queries to the TasksController, blocking until
 * there is availability to send.//from  ww w  . j a  v a2s.c om
 *
 * Release the semaphore when a task completes.
 * If there was an error communicating with the host to get the status, throw an exception.
 *
 * @param queries Queries to be inserted
 */
private void sendQueriesToLoader(Collection<InsertQuery> queries) {
    try {
        blocker.acquire();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

    try {
        String taskId = executePost(getConfiguration(queries, batchNumber.incrementAndGet()));

        CompletableFuture<Json> status = makeTaskCompletionFuture(taskId);

        // Add this status to the set of completable futures
        futures.put(status.hashCode(), status);

        // Function to execute when the task completes
        status.whenComplete((result, error) -> {
            unblock(status);

            if (error != null) {
                LOG.error(getFullStackTrace(error));
            }

            onCompletionOfTask.accept(result);
        });
    } catch (Throwable throwable) {
        LOG.error(getFullStackTrace(throwable));
        blocker.release();
    }
}