[ 
https://issues.apache.org/jira/browse/CXF-7535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16241368#comment-16241368
 ] 

ASF GitHub Bot commented on CXF-7535:
-------------------------------------

reta commented on a change in pull request #331: [CXF-7535] Adding client & 
server support for Project Reactor
URL: https://github.com/apache/cxf/pull/331#discussion_r149259533
 
 

 ##########
 File path: 
rt/rs/extensions/reactor/src/main/java/org/apache/cxf/jaxrs/reactor/client/FluxRxInvokerImpl.java
 ##########
 @@ -0,0 +1,178 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.reactor.client;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+import org.apache.cxf.jaxrs.client.WebClient;
+import static 
org.apache.cxf.jaxrs.reactor.client.ReactorUtils.toCompletableFuture;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Scheduler;
+import reactor.core.scheduler.Schedulers;
+
+public class FluxRxInvokerImpl implements FluxRxInvoker {
+    private static final String TRACE = "TRACE";
+    private final WebClient webClient;
+    private final Scheduler scheduler;
+    private final ExecutorService executorService;
+
+    FluxRxInvokerImpl(WebClient webClient, ExecutorService executorService) {
+        this.webClient = webClient;
+        this.executorService = executorService;
+        this.scheduler = executorService == null ? null : 
Schedulers.fromExecutorService(executorService);
+    }
+
+    @Override
+    public Flux<Response> get() {
+        return method(HttpMethod.GET);
+    }
+
+    @Override
+    public <R> Flux<R> get(Class<R> responseType) {
+        return method(HttpMethod.GET, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> get(GenericType<R> genericType) {
+        return method(HttpMethod.GET, genericType);
+    }
+
+    @Override
+    public Flux<Response> put(Entity<?> entity) {
+        return method(HttpMethod.PUT, entity);
+    }
+
+    @Override
+    public <R> Flux<R> put(Entity<?> entity, Class<R> responseType) {
+        return method(HttpMethod.PUT, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> put(Entity<?> entity, GenericType<R> genericType) {
+        return method(HttpMethod.PUT, entity, genericType);
+    }
+
+    @Override
+    public Flux<Response> post(Entity<?> entity) {
+        return method(HttpMethod.POST, entity);
+    }
+
+    @Override
+    public <R> Flux<R> post(Entity<?> entity, Class<R> responseType) {
+        return method(HttpMethod.POST, entity, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> post(Entity<?> entity, GenericType<R> genericType) {
+        return method(HttpMethod.POST, entity, genericType);
+    }
+
+    @Override
+    public Flux<Response> delete() {
+        return method(HttpMethod.DELETE);
+    }
+
+    @Override
+    public <R> Flux<R> delete(Class<R> responseType) {
+        return method(HttpMethod.DELETE, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> delete(GenericType<R> genericType) {
+        return method(HttpMethod.DELETE, genericType);
+    }
+
+    @Override
+    public Flux<Response> head() {
+        return method(HttpMethod.HEAD);
+    }
+
+    @Override
+    public Flux<Response> options() {
+        return method(HttpMethod.OPTIONS);
+    }
+
+    @Override
+    public <R> Flux<R> options(Class<R> responseType) {
+        return method(HttpMethod.OPTIONS, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> options(GenericType<R> genericType) {
+        return method(HttpMethod.OPTIONS, genericType);
+    }
+
+    @Override
+    public Flux<Response> trace() {
+        return method(TRACE);
+    }
+
+    @Override
+    public <R> Flux<R> trace(Class<R> responseType) {
+        return method(TRACE, responseType);
+    }
+
+    @Override
+    public <R> Flux<R> trace(GenericType<R> genericType) {
+        return method(TRACE, genericType);
+    }
+
+    @Override
+    public Flux<Response> method(String name) {
+        return method(name, Response.class);
+    }
+
+    @Override
+    public <R> Flux<R> method(String name, Class<R> responseType) {
+        return flux(webClient.async().method(name, responseType));
+    }
+
+    @Override
+    public <R> Flux<R> method(String name, GenericType<R> genericType) {
+        return flux(webClient.async().method(name, genericType));
+    }
+
+    @Override
+    public Flux<Response> method(String name, Entity<?> entity) {
+        return method(name, entity, Response.class);
+    }
+
+    @Override
+    public <R> Flux<R> method(String name, Entity<?> entity, Class<R> 
responseType) {
+        return flux(webClient.async().method(name, entity, responseType));
+    }
+
+    @Override
+    public <R> Flux<R> method(String name, Entity<?> entity, GenericType<R> 
genericType) {
+        return flux(webClient.async().method(name, entity, genericType));
+    }
+
+    private <R> Flux<R> flux(Future<R> future) {
+        Flux<R> flux = Flux.from(Mono.fromFuture(toCompletableFuture(future, 
executorService)));
+        if (scheduler != null) {
 
 Review comment:
   @johnament Thanks for passing the `executorService` to 
`toCompletableFuture`. The `scheduler` and  this snippet:
   ```
   if (scheduler != null) {
               flux = flux.subscribeOn(scheduler);
   }
   ```
   are not needed. The reason is that the completion callback for 
`Mono.fromFuture` will be called in one of the `executorService` threads or 
`ForkJoin` pool (you could easily trace it). Moreover, we could run into issues 
with this code because it uses two threads from the same pool for 
`toCompletableFuture` and subscription, exposing ourselves for likelihood of 
livelocks. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support for Project Reactor as rx()
> -----------------------------------
>
>                 Key: CXF-7535
>                 URL: https://issues.apache.org/jira/browse/CXF-7535
>             Project: CXF
>          Issue Type: New Feature
>          Components: JAX-RS
>    Affects Versions: 3.2.0
>            Reporter: John D. Ament
>
> It would be good if Project Reactor was supported as an rx() type in CXF.  
> https://github.com/apache/cxf/tree/master/rt/rs/extensions/rx - only shows rx 
> java and rx java 2.  project reactor/reactor core seem like the v3's of this 
> api stack.
> https://projectreactor.io/



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to