diff --git a/core/src/main/java/org/glassfish/tyrus/core/TyrusFuture.java b/core/src/main/java/org/glassfish/tyrus/core/TyrusFuture.java index 483b6f78..8db53e98 100644 --- a/core/src/main/java/org/glassfish/tyrus/core/TyrusFuture.java +++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusFuture.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,60 +16,13 @@ package org.glassfish.tyrus.core; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; /** - * Simple {@link Future} implementation. - * - * @author Stepan Kopriva + * Tyrus {@link Future} implementation. */ -public class TyrusFuture implements Future { - - private volatile T result; - private volatile Throwable throwable = null; - private final CountDownLatch latch = new CountDownLatch(1); - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return (latch.getCount() == 0); - } - - @Override - public T get() throws InterruptedException, ExecutionException { - latch.await(); - - if (throwable != null) { - throw new ExecutionException(throwable); - } - - return result; - } - - @Override - public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - if (latch.await(timeout, unit)) { - if (throwable != null) { - throw new ExecutionException(throwable); - } - return result; - } - - throw new TimeoutException(); - } +public class TyrusFuture extends CompletableFuture { /** * Sets the result of the message writing process. @@ -77,10 +30,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution * @param result result */ public void setResult(T result) { - if (latch.getCount() == 1) { - this.result = result; - latch.countDown(); - } + complete(result); } /** @@ -89,9 +39,6 @@ public void setResult(T result) { * @param throwable throwable. */ public void setFailure(Throwable throwable) { - if (latch.getCount() == 1) { - this.throwable = throwable; - latch.countDown(); - } + completeExceptionally(throwable); } } diff --git a/pom.xml b/pom.xml index 88980b45..62a1196f 100644 --- a/pom.xml +++ b/pom.xml @@ -101,18 +101,18 @@ - 2.1.0 + 2.1.1 2.1.1 4.0.1 4.0.1 4.0.0 - 7.0.1 - 2.1.1 - 1.1.1 - 4.0.0 - 4.0.1 + 7.0.9 + 2.1.2 + 1.1.4 + 4.0.1 + 4.0.3 3.3.1 6.0.0 2.6.7