Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependencies and use CompletableFuture by TyrusFuture internally #849

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 6 additions & 59 deletions core/src/main/java/org/glassfish/tyrus/core/TyrusFuture.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,71 +16,21 @@

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<T> implements Future<T> {

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<T> extends CompletableFuture<T> {

/**
* Sets the result of the message writing process.
*
* @param result result
*/
public void setResult(T result) {
if (latch.getCount() == 1) {
this.result = result;
latch.countDown();
}
complete(result);
}

/**
Expand All @@ -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);
}
}
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@
</contributors>

<properties>
<websocket-api.version>2.1.0</websocket-api.version>
<websocket-api.version>2.1.1</websocket-api.version>
<!--<websocket.api.build_number>18</websocket.api.build_number>-->

<annotation-api.version>2.1.1</annotation-api.version>
<cdi-api.version>4.0.1</cdi-api.version>
<ejb-api.version>4.0.1</ejb-api.version>
<grizzly.version>4.0.0</grizzly.version>
<glassfish.version>7.0.1</glassfish.version>
<json-api.version>2.1.1</json-api.version>
<json-impl.version>1.1.1</json-impl.version>
<jaxb.api.version>4.0.0</jaxb.api.version>
<jaxb.ri.version>4.0.1</jaxb.ri.version>
<glassfish.version>7.0.9</glassfish.version>
<json-api.version>2.1.2</json-api.version>
<json-impl.version>1.1.4</json-impl.version>
<jaxb.api.version>4.0.1</jaxb.api.version>
<jaxb.ri.version>4.0.3</jaxb.ri.version>
<maven-javadoc-plugin.version>3.3.1</maven-javadoc-plugin.version>
<servlet.api.version>6.0.0</servlet.api.version>
<spring.boot.version>2.6.7</spring.boot.version>
Expand Down
Loading