Skip to content

Commit 9150240

Browse files
author
Stephane Landelle
committed
Add new extra module shipping Guava Future adapter, port fix for AsyncHttpClient#240
1 parent cb897e8 commit 9150240

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

extras/guava/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<groupId>com.ning</groupId>
6+
<artifactId>async-http-client-extras-parent</artifactId>
7+
<version>1.8.0-SNAPSHOT</version>
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
<groupId>com.ning</groupId>
11+
<artifactId>async-http-client-extras-guava</artifactId>
12+
<name>Asynchronous Http Client Guava Extras</name>
13+
<version>1.8.0-SNAPSHOT</version>
14+
<packaging>jar</packaging>
15+
<description>
16+
The Async Http Client Guava Extras.
17+
</description>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.guava</groupId>
22+
<artifactId>guava</artifactId>
23+
<version>11.0.2</version>
24+
</dependency>
25+
</dependencies>
26+
</project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
package com.ning.http.client.extra;
14+
15+
import java.util.concurrent.ExecutionException;
16+
import java.util.concurrent.Executor;
17+
import java.util.concurrent.TimeUnit;
18+
import java.util.concurrent.TimeoutException;
19+
20+
import com.ning.http.client.ListenableFuture;
21+
22+
public final class ListenableFutureAdapter {
23+
24+
/**
25+
* @param future an AHC ListenableFuture
26+
* @return a Guava ListenableFuture
27+
*/
28+
public static <V> com.google.common.util.concurrent.ListenableFuture<V> asGuavaFuture(final ListenableFuture<V> future) {
29+
30+
return new com.google.common.util.concurrent.ListenableFuture<V>() {
31+
32+
public boolean cancel(boolean mayInterruptIfRunning) {
33+
return future.cancel(mayInterruptIfRunning);
34+
}
35+
36+
public V get() throws InterruptedException, ExecutionException {
37+
return future.get();
38+
}
39+
40+
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
41+
return future.get(timeout, unit);
42+
}
43+
44+
public boolean isCancelled() {
45+
return future.isCancelled();
46+
}
47+
48+
public boolean isDone() {
49+
return future.isDone();
50+
}
51+
52+
public void addListener(final Runnable runnable, final Executor executor) {
53+
future.addListener(runnable, executor);
54+
}
55+
};
56+
}
57+
}

extras/pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<groupId>com.ning</groupId>
6+
<artifactId>async-http-client-project</artifactId>
7+
<version>1.8.0-SNAPSHOT</version>
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
<groupId>com.ning</groupId>
11+
<artifactId>async-http-client-extras-parent</artifactId>
12+
<name>Asynchronous Http Client Extras Parent</name>
13+
<version>1.8.0-SNAPSHOT</version>
14+
<packaging>pom</packaging>
15+
<description>
16+
The Async Http Client extras library parent.
17+
</description>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.felix</groupId>
23+
<artifactId>maven-bundle-plugin</artifactId>
24+
<version>2.3.4</version>
25+
<extensions>true</extensions>
26+
<configuration>
27+
<manifestLocation>META-INF</manifestLocation>
28+
<instructions>
29+
<Bundle-Version>
30+
$(replace;$(project.version);-SNAPSHOT;.$(tstamp;yyyyMMdd-HHmm))
31+
</Bundle-Version>
32+
<Bundle-Vendor>Sonatype</Bundle-Vendor>
33+
</instructions>
34+
</configuration>
35+
<executions>
36+
<execution>
37+
<id>osgi-bundle</id>
38+
<phase>package</phase>
39+
<goals>
40+
<goal>bundle</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
48+
<modules>
49+
<module>guava</module>
50+
</modules>
51+
52+
<dependencies>
53+
<dependency>
54+
<groupId>com.ning</groupId>
55+
<artifactId>async-http-client-api</artifactId>
56+
<version>${project.version}</version>
57+
</dependency>
58+
</dependencies>
59+
</project>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<name>Ryan Lubke</name>
7575
<email>[email protected]</email>
7676
</developer>
77+
<developer>
78+
<id>slandelle</id>
79+
<name>Stephane Landelle</name>
80+
<email>[email protected]</email>
81+
</developer>
7782
</developers>
7883
<contributors>
7984
<contributor>
@@ -490,6 +495,7 @@
490495
<modules>
491496
<module>api</module>
492497
<module>providers</module>
498+
<module>extras</module>
493499
<module>site</module>
494500
</modules>
495501
<dependencies>

0 commit comments

Comments
 (0)