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 14d012fd..f4d1a4fa 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - 2.1.0 + 2.1.1 4.0.1 4.0.1 4.0.0 - 7.0.0-M1 - 2.1.0 - 1.1.0 - 4.0.0 - 4.0.0 + 7.0.9 + 2.1.2 + 1.1.4 + 4.0.1 + 4.0.3 3.3.1 6.0.0 2.6.7 diff --git a/tests/servlet/embedded-glassfish-test/pom.xml b/tests/servlet/embedded-glassfish-test/pom.xml index 0601c179..d40a16ac 100644 --- a/tests/servlet/embedded-glassfish-test/pom.xml +++ b/tests/servlet/embedded-glassfish-test/pom.xml @@ -1,6 +1,6 @@ - 7.0.0-M1 + ${glassfish.version} 5.7.2