All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.util.CompletableFutures Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 34.0.0.Final
Show newest version
package org.jgroups.util;

import java.util.concurrent.*;
import java.util.function.Consumer;

/**
 * Utility class with {@link CompletableFuture} and {@link CompletionStage} useful methods.
 *
 * @author Pedro Ruivo
 * @since 5.2
 */
public enum CompletableFutures {
    INSTANCE;

    private static final CompletableFuture NULL = CompletableFuture.completedFuture(null);
    private static final Consumer VOID_CONSUMER = o -> {
    };

    /**
     * Same as {@link #join(CompletableFuture)} but it receives a {@link CompletionStage} as parameter.
     *
     * @see #join(CompletableFuture)
     */
    public static  T join(CompletionStage cs) {
        return join(cs.toCompletableFuture());
    }

    /**
     * Waits for the {@link CompletableFuture} to complete.
     * 

* Any non {@link RuntimeException} thrown is converted to a {@link RuntimeException}. * * @param cf The {@link CompletableFuture} * @param The value type. * @return The value of the completed {@link CompletableFuture}. */ public static T join(CompletableFuture cf) { try { return cf.join(); } catch (CompletionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } throw new RuntimeException(e.getCause()); } } /** * A {@code null} completed {@link CompletableFuture}. * * @param The value type. * @return The {@link CompletableFuture}. */ public static CompletableFuture completedNull() { //noinspection unchecked return (CompletableFuture) NULL; } /** * Consumes any value and return a {@link Void}. * * @param The value type. * @return The {@link Consumer}. */ public static Consumer voidConsumer() { //noinspection unchecked return (Consumer) VOID_CONSUMER; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy