Skip to content

Commit 0249d9c

Browse files
committed
Enable to use AsyncInvoker in Rx client
Signed-off-by: Jan Supol <jan.supol@oracle.com>
1 parent 584664c commit 0249d9c

File tree

8 files changed

+431
-368
lines changed

8 files changed

+431
-368
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.client;
18+
19+
import org.glassfish.jersey.client.internal.LocalizationMessages;
20+
21+
import javax.ws.rs.client.AsyncInvoker;
22+
import javax.ws.rs.client.Entity;
23+
import javax.ws.rs.client.SyncInvoker;
24+
import javax.ws.rs.core.GenericType;
25+
26+
/* package */ abstract class AbstractNonSyncInvoker<T> {
27+
private final SyncInvoker invocationBuilder;
28+
29+
protected AbstractNonSyncInvoker(SyncInvoker invocationBuilder) {
30+
if (invocationBuilder == null) {
31+
throw new IllegalArgumentException(LocalizationMessages.NULL_INVOCATION_BUILDER());
32+
}
33+
this.invocationBuilder = invocationBuilder;
34+
}
35+
36+
/**
37+
* Return invocation builder this reactive invoker was initialized with.
38+
*
39+
* @return non-null invocation builder.
40+
*/
41+
protected SyncInvoker getSyncInvoker() {
42+
return invocationBuilder;
43+
}
44+
45+
public T get() {
46+
return method("GET");
47+
}
48+
49+
public <R> T get(final Class<R> responseType) {
50+
return method("GET", responseType);
51+
}
52+
53+
public <R> T get(final GenericType<R> responseType) {
54+
return method("GET", responseType);
55+
}
56+
57+
public T put(final Entity<?> entity) {
58+
return method("PUT", entity);
59+
}
60+
61+
public <R> T put(final Entity<?> entity, final Class<R> clazz) {
62+
return method("PUT", entity, clazz);
63+
}
64+
65+
public <R> T put(final Entity<?> entity, final GenericType<R> type) {
66+
return method("PUT", entity, type);
67+
}
68+
69+
public T post(final Entity<?> entity) {
70+
return method("POST", entity);
71+
}
72+
73+
public <R> T post(final Entity<?> entity, final Class<R> clazz) {
74+
return method("POST", entity, clazz);
75+
}
76+
77+
public <R> T post(final Entity<?> entity, final GenericType<R> type) {
78+
return method("POST", entity, type);
79+
}
80+
81+
public T delete() {
82+
return method("DELETE");
83+
}
84+
85+
public <R> T delete(final Class<R> responseType) {
86+
return method("DELETE", responseType);
87+
}
88+
89+
public <R> T delete(final GenericType<R> responseType) {
90+
return method("DELETE", responseType);
91+
}
92+
93+
public T head() {
94+
return method("HEAD");
95+
}
96+
97+
public T options() {
98+
return method("OPTIONS");
99+
}
100+
101+
public <R> T options(final Class<R> responseType) {
102+
return method("OPTIONS", responseType);
103+
}
104+
105+
public <R> T options(final GenericType<R> responseType) {
106+
return method("OPTIONS", responseType);
107+
}
108+
109+
public T trace() {
110+
return method("TRACE");
111+
}
112+
113+
public <R> T trace(final Class<R> responseType) {
114+
return method("TRACE", responseType);
115+
}
116+
117+
public <R> T trace(final GenericType<R> responseType) {
118+
return method("TRACE", responseType);
119+
}
120+
121+
public abstract T method(final String name);
122+
123+
public abstract <R> T method(final String name, final Class<R> responseType);
124+
125+
public abstract <R> T method(final String name, final GenericType<R> responseType);
126+
127+
public abstract T method(final String name, final Entity<?> entity);
128+
129+
public abstract <R> T method(final String name, final Entity<?> entity, final Class<R> responseType);
130+
131+
public abstract <R> T method(final String name, final Entity<?> entity, final GenericType<R> responseType);
132+
}
Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -25,7 +25,7 @@
2525
import javax.ws.rs.core.Response;
2626

2727
/**
28-
* Default implementation of {@link javax.ws.rs.client.rx.RxInvoker reactive invoker}. Extensions of this class are
28+
* Default implementation of {@link javax.ws.rs.client.RxInvoker reactive invoker}. Extensions of this class are
2929
* supposed to implement {@link #method(String, Entity, Class)} and
3030
* {@link #method(String, Entity, GenericType)} methods to which implementations of the rest
3131
* of the methods from the contract delegate to.
@@ -35,29 +35,15 @@
3535
* @author Michal Gajdos
3636
* @since 2.26
3737
*/
38-
public abstract class AbstractRxInvoker<T> implements RxInvoker<T> {
38+
public abstract class AbstractRxInvoker<T> extends AbstractNonSyncInvoker<T> implements RxInvoker<T> {
3939

40-
private final SyncInvoker syncInvoker;
4140
private final ExecutorService executorService;
4241

4342
public AbstractRxInvoker(final SyncInvoker syncInvoker, final ExecutorService executor) {
44-
if (syncInvoker == null) {
45-
throw new IllegalArgumentException("Invocation builder cannot be null.");
46-
}
47-
48-
this.syncInvoker = syncInvoker;
43+
super(syncInvoker);
4944
this.executorService = executor;
5045
}
5146

52-
/**
53-
* Return invocation builder this reactive invoker was initialized with.
54-
*
55-
* @return non-null invocation builder.
56-
*/
57-
protected SyncInvoker getSyncInvoker() {
58-
return syncInvoker;
59-
}
60-
6147
/**
6248
* Return executorService service this reactive invoker was initialized with.
6349
*
@@ -67,118 +53,20 @@ protected ExecutorService getExecutorService() {
6753
return executorService;
6854
}
6955

70-
@Override
71-
public T get() {
72-
return method("GET");
73-
}
74-
75-
@Override
76-
public <R> T get(final Class<R> responseType) {
77-
return method("GET", responseType);
78-
}
79-
80-
@Override
81-
public <R> T get(final GenericType<R> responseType) {
82-
return method("GET", responseType);
83-
}
84-
85-
@Override
86-
public T put(final Entity<?> entity) {
87-
return method("PUT", entity);
88-
}
89-
90-
@Override
91-
public <R> T put(final Entity<?> entity, final Class<R> clazz) {
92-
return method("PUT", entity, clazz);
93-
}
94-
95-
@Override
96-
public <R> T put(final Entity<?> entity, final GenericType<R> type) {
97-
return method("PUT", entity, type);
98-
}
99-
100-
@Override
101-
public T post(final Entity<?> entity) {
102-
return method("POST", entity);
103-
}
104-
105-
@Override
106-
public <R> T post(final Entity<?> entity, final Class<R> clazz) {
107-
return method("POST", entity, clazz);
108-
}
109-
110-
@Override
111-
public <R> T post(final Entity<?> entity, final GenericType<R> type) {
112-
return method("POST", entity, type);
113-
}
114-
115-
@Override
116-
public T delete() {
117-
return method("DELETE");
118-
}
119-
120-
@Override
121-
public <R> T delete(final Class<R> responseType) {
122-
return method("DELETE", responseType);
123-
}
124-
125-
@Override
126-
public <R> T delete(final GenericType<R> responseType) {
127-
return method("DELETE", responseType);
128-
}
129-
130-
@Override
131-
public T head() {
132-
return method("HEAD");
133-
}
134-
135-
@Override
136-
public T options() {
137-
return method("OPTIONS");
138-
}
139-
140-
@Override
141-
public <R> T options(final Class<R> responseType) {
142-
return method("OPTIONS", responseType);
143-
}
144-
145-
@Override
146-
public <R> T options(final GenericType<R> responseType) {
147-
return method("OPTIONS", responseType);
148-
}
149-
150-
@Override
151-
public T trace() {
152-
return method("TRACE");
153-
}
154-
155-
@Override
156-
public <R> T trace(final Class<R> responseType) {
157-
return method("TRACE", responseType);
158-
}
159-
160-
@Override
161-
public <R> T trace(final GenericType<R> responseType) {
162-
return method("TRACE", responseType);
163-
}
164-
165-
@Override
16656
public T method(final String name) {
16757
return method(name, Response.class);
16858
}
16959

170-
@Override
17160
public <R> T method(final String name, final Class<R> responseType) {
17261
return method(name, null, responseType);
17362
}
17463

175-
@Override
17664
public <R> T method(final String name, final GenericType<R> responseType) {
17765
return method(name, null, responseType);
17866
}
17967

180-
@Override
18168
public T method(final String name, final Entity<?> entity) {
18269
return method(name, entity, Response.class);
18370
}
71+
18472
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.client;
18+
19+
import javax.ws.rs.client.AsyncInvoker;
20+
import javax.ws.rs.client.Entity;
21+
import javax.ws.rs.client.InvocationCallback;
22+
import javax.ws.rs.core.GenericType;
23+
import javax.ws.rs.core.Response;
24+
import java.util.concurrent.CompletableFuture;
25+
26+
/*package*/ abstract class CompletableFutureAsyncInvoker
27+
extends AbstractNonSyncInvoker<CompletableFuture> implements AsyncInvoker {
28+
29+
protected CompletableFutureAsyncInvoker(JerseyInvocation.Builder invocationBuilder) {
30+
super(invocationBuilder);
31+
}
32+
33+
@Override
34+
public <T> CompletableFuture<T> get(InvocationCallback<T> callback) {
35+
return method("GET", callback);
36+
}
37+
38+
@Override
39+
public <T> CompletableFuture<T> put(Entity<?> entity, InvocationCallback<T> callback) {
40+
return method("PUT", callback);
41+
}
42+
43+
@Override
44+
public <T> CompletableFuture<T> post(Entity<?> entity, InvocationCallback<T> callback) {
45+
return method("POST", callback);
46+
}
47+
48+
@Override
49+
public <T> CompletableFuture<T> delete(InvocationCallback<T> callback) {
50+
return method("DELETE", callback);
51+
}
52+
53+
@Override
54+
public CompletableFuture<Response> head(InvocationCallback<Response> callback) {
55+
return method("HEAD", callback);
56+
}
57+
58+
@Override
59+
public <T> CompletableFuture<T> options(InvocationCallback<T> callback) {
60+
return method("OPTIONS", callback);
61+
}
62+
63+
@Override
64+
public <T> CompletableFuture<T> trace(InvocationCallback<T> callback) {
65+
return method("TRACE", callback);
66+
}
67+
68+
@Override
69+
public abstract <T> CompletableFuture<T> method(String name, InvocationCallback<T> callback);
70+
71+
@Override
72+
public abstract <T> CompletableFuture<T> method(String name, Entity<?> entity, InvocationCallback<T> callback);
73+
74+
@Override
75+
public abstract <R> CompletableFuture method(String name, Entity<?> entity, Class<R> responseType);
76+
77+
@Override
78+
public abstract <R> CompletableFuture method(String name, Entity<?> entity, GenericType<R> responseType);
79+
}

0 commit comments

Comments
 (0)