Example usage for java.util.concurrent CompletionException CompletionException

List of usage examples for java.util.concurrent CompletionException CompletionException

Introduction

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

Prototype

public CompletionException(Throwable cause) 

Source Link

Document

Constructs a CompletionException with the specified cause.

Usage

From source file:edu.berkeley.ground.postgres.controllers.GraphController.java

public final CompletionStage<Result> getGraph(String sourceKey) {
    return CompletableFuture.supplyAsync(() -> {
        try {//from   www.j av  a  2s  . co  m
            return this.cache.getOrElse("graphs",
                    () -> Json.toJson(this.postgresGraphDao.retrieveFromDatabase(sourceKey)),
                    Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::ok)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.StructureController.java

public final CompletionStage<Result> getStructure(String sourceKey) {
    return CompletableFuture.supplyAsync(() -> {
        try {//from www .  ja v  a2  s  .com
            return this.cache.getOrElse("structures",
                    () -> Json.toJson(this.postgresStructureDao.retrieveFromDatabase(sourceKey)),
                    Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::ok)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.GraphController.java

public final CompletionStage<Result> getGraphVersion(Long id) {
    return CompletableFuture.supplyAsync(() -> {
        try {//  www .  j a va 2s.c o m
            return this.cache.getOrElse("graph_versions",
                    () -> Json.toJson(this.postgresGraphVersionDao.retrieveFromDatabase(id)),
                    Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::ok)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.StructureController.java

public final CompletionStage<Result> getStructureVersion(Long id) {
    return CompletableFuture.supplyAsync(() -> {
        try {//from   w w w. j  av  a 2s  .  c o m
            return this.cache.getOrElse("structure_versions",
                    () -> Json.toJson(this.postgresStructureVersionDao.retrieveFromDatabase(id)),
                    Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::ok)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.GraphController.java

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraph() {
    return CompletableFuture.supplyAsync(() -> {
        JsonNode json = request().body().asJson();
        Graph graph = Json.fromJson(json, Graph.class);

        try {/*from  ww w  .j  a v a  2s.  com*/
            graph = this.postgresGraphDao.create(graph);
        } catch (GroundException e) {
            throw new CompletionException(e);
        }

        return Json.toJson(graph);
    }, PostgresUtils.getDbSourceHttpContext(actorSystem)).thenApply(Results::created)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.StructureController.java

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructure() {
    return CompletableFuture.supplyAsync(() -> {
        JsonNode json = request().body().asJson();
        Structure structure = Json.fromJson(json, Structure.class);

        try {/*ww  w.  ja  v a2 s  .  c  om*/
            structure = this.postgresStructureDao.create(structure);
        } catch (GroundException e) {
            throw new CompletionException(e);
        }
        return Json.toJson(structure);
    },

            PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::created)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:io.pravega.test.integration.selftest.Producer.java

/**
 * Executes one iteration of the Producer.
 * 1. Requests a new ProducerOperation from the DataSource.
 * 2. Executes it.//w  w w .  j a  v a2 s  .  co  m
 * 3. Completes the ProducerOperation with either success or failure based on the outcome step #2.
 */
private CompletableFuture<Void> runOneIteration() {
    this.iterationCount.incrementAndGet();

    val futures = new ArrayList<CompletableFuture<Void>>();
    for (int i = 0; i < this.config.getProducerParallelism(); i++) {
        ProducerOperation op = this.dataSource.nextOperation();
        if (op == null) {
            // Nothing more to do.
            this.canContinue.set(false);
            break;
        }

        CompletableFuture<Void> result;
        try {
            CompletableFuture<Void> waitOn = op.getWaitOn();
            if (waitOn != null) {
                result = waitOn.exceptionally(ex -> null).thenComposeAsync(v -> executeOperation(op),
                        this.executorService);
            } else {
                result = executeOperation(op);
            }
        } catch (Throwable ex) {
            // Catch and handle sync errors.
            op.completed(-1);
            if (handleOperationError(ex, op)) {
                // Exception handled; skip this iteration since there's nothing more we can do.
                continue;
            } else {
                result = Futures.failedFuture(ex);
            }
        }

        futures.add(result.exceptionally(ex -> {
            // Catch and handle async errors.
            if (handleOperationError(ex, op)) {
                return null;
            }

            throw new CompletionException(ex);
        }));
    }

    return Futures.allOf(futures);
}

From source file:edu.berkeley.ground.postgres.controllers.GraphController.java

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraphVersion() {
    return CompletableFuture.supplyAsync(() -> {
        JsonNode json = request().body().asJson();
        List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
        ((ObjectNode) json).remove("parentIds");
        GraphVersion graphVersion = Json.fromJson(json, GraphVersion.class);

        try {/*from  ww  w. j  a  v a  2 s  .  c  o m*/
            graphVersion = this.postgresGraphVersionDao.create(graphVersion, parentIds);
        } catch (GroundException e) {
            throw new CompletionException(e);
        }
        return Json.toJson(graphVersion);
    }, PostgresUtils.getDbSourceHttpContext(actorSystem)).thenApply(Results::ok)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:edu.berkeley.ground.postgres.controllers.StructureController.java

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructureVersion() {
    return CompletableFuture.supplyAsync(() -> {
        JsonNode json = request().body().asJson();

        List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
        ((ObjectNode) json).remove("parentIds");

        StructureVersion structureVersion = Json.fromJson(json, StructureVersion.class);

        try {/*from  w  ww .  ja  v a2s  . c o m*/
            structureVersion = this.postgresStructureVersionDao.create(structureVersion, parentIds);
        } catch (GroundException e) {
            throw new CompletionException(e);
        }
        return Json.toJson(structureVersion);
    }, PostgresUtils.getDbSourceHttpContext(this.actorSystem)).thenApply(Results::created)
            .exceptionally(e -> GroundUtils.handleException(e, request()));
}

From source file:io.pravega.controller.server.eventProcessor.ControllerEventProcessors.java

@Override
public CompletableFuture<Void> handleFailedProcess(String process) {
    List<CompletableFuture<Void>> futures = new ArrayList<>();

    if (commitEventProcessors != null) {
        futures.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
            try {
                commitEventProcessors.notifyProcessFailure(process);
            } catch (CheckpointStoreException e) {
                throw new CompletionException(e);
            }//ww  w. j  a  v a  2 s . co m
        }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor));
    }

    if (abortEventProcessors != null) {
        futures.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
            try {
                abortEventProcessors.notifyProcessFailure(process);
            } catch (CheckpointStoreException e) {
                throw new CompletionException(e);
            }
        }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor));
    }
    if (requestEventProcessors != null) {
        futures.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
            try {
                requestEventProcessors.notifyProcessFailure(process);
            } catch (CheckpointStoreException e) {
                throw new CompletionException(e);
            }
        }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor));
    }
    return FutureHelpers.allOf(futures);
}