Skip to content

Commit

Permalink
Updated dependencies & use CompletableFuture by TyrusFuture
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Oct 18, 2023
1 parent 63dc9ae commit 7d6c415
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 68 deletions.
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);
}
}
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2011, 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 Down Expand Up @@ -104,15 +104,15 @@
<websocket-api.version>2.1.0</websocket-api.version>
<!--<websocket.api.build_number>18</websocket.api.build_number>-->

<annotation-api.version>2.1.0</annotation-api.version>
<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.0-M1</glassfish.version>
<json-api.version>2.1.0</json-api.version>
<json-impl.version>1.1.0</json-impl.version>
<jaxb.api.version>4.0.0</jaxb.api.version>
<jaxb.ri.version>4.0.0</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
4 changes: 2 additions & 2 deletions tests/servlet/embedded-glassfish-test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2021, 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 Down Expand Up @@ -34,7 +34,7 @@
<glassfish.home>${project.build.directory}/glassfish7</glassfish.home>
<modules.dir>${glassfish.home}/glassfish/modules</modules.dir>
<!-- <websocket-api.version>2.1.0-SNAPSHOT</websocket-api.version>-->
<glassfish.container.version>7.0.0-M1</glassfish.container.version>
<glassfish.container.version>${glassfish.version}</glassfish.container.version>
<junit.jupiter.version>5.7.2</junit.jupiter.version>
</properties>

Expand Down

0 comments on commit 7d6c415

Please sign in to comment.