[ https://issues.apache.org/jira/browse/CXF-7535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239146#comment-16239146 ]
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_r148937715 ########## 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 org.apache.cxf.jaxrs.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; +import reactor.core.scheduler.Schedulers; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import static org.apache.cxf.jaxrs.reactor.client.ReactorUtils.toCompletableFuture; + +public class FluxRxInvokerImpl implements FluxRxInvoker { + private static final String TRACE = "TRACE"; + private final WebClient webClient; + private final Scheduler scheduler; + + FluxRxInvokerImpl(WebClient webClient, ExecutorService executorService) { + this.webClient = webClient; + this.scheduler = executorService == null ? null : Schedulers.fromExecutorService(executorService); + } + + @Override + public Flux 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))); Review comment: This part concerns. I would suggest to not use `scheduler` but pass `executor` directly to `toCompletableFuture` (so the `supplyAsync` call would be done outside of common `ForkJoin` pool). Otherwise we have too many pools and threads involved for no real reason. Regarding the desired behavior, we would certainly want the subscription to be invoked on the separate thread (this is what `subscribeOn` does now). However, because we create `Flux` from `CompletableFuture`, intuitively the completion callback would be invoked from another thread, either the one from common `ForkJoin` pool or the provided one (unless then value is available immediately). Thoughts? ---------------------------------------------------------------- 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 > Priority: Major > > 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)