You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2018/02/01 09:42:39 UTC
aries-jax-rs-whiteboard git commit: Improve the scalability of the
PromiseRxInvokerImpl by using native CXF API
Repository: aries-jax-rs-whiteboard
Updated Branches:
refs/heads/master 496200f0e -> c62794dfa
Improve the scalability of the PromiseRxInvokerImpl by using native CXF API
Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/c62794df
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/c62794df
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/c62794df
Branch: refs/heads/master
Commit: c62794dfaf5fab8e95e03815c6176bdcf9fa763e
Parents: 496200f
Author: Tim Ward <ti...@apache.org>
Authored: Thu Feb 1 09:42:29 2018 +0000
Committer: Tim Ward <ti...@apache.org>
Committed: Thu Feb 1 09:42:29 2018 +0000
----------------------------------------------------------------------
.../internal/client/ClientBuilderFactory.java | 1 +
.../internal/client/PromiseRxInvokerImpl.java | 172 ---------------
.../client/PromiseRxInvokerProviderImpl.java | 52 -----
.../cxf/jaxrs/client/PromiseRxInvokerImpl.java | 207 +++++++++++++++++++
.../client/PromiseRxInvokerProviderImpl.java | 54 +++++
5 files changed, 262 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/c62794df/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/ClientBuilderFactory.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/ClientBuilderFactory.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/ClientBuilderFactory.java
index d98dc24..90ccb62 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/ClientBuilderFactory.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/ClientBuilderFactory.java
@@ -19,6 +19,7 @@ package org.apache.aries.jax.rs.whiteboard.internal.client;
import javax.ws.rs.client.ClientBuilder;
+import org.apache.cxf.jaxrs.client.PromiseRxInvokerProviderImpl;
import org.apache.cxf.jaxrs.client.spec.ClientBuilderImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.PrototypeServiceFactory;
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/c62794df/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerImpl.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerImpl.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerImpl.java
deleted file mode 100644
index b1ab900..0000000
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerImpl.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.aries.jax.rs.whiteboard.internal.client;
-
-import org.osgi.service.jaxrs.client.PromiseRxInvoker;
-import org.osgi.util.promise.Promise;
-import org.osgi.util.promise.PromiseFactory;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.SyncInvoker;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.Response;
-
-class PromiseRxInvokerImpl implements PromiseRxInvoker {
-
- public PromiseRxInvokerImpl(
- SyncInvoker syncInvoker, PromiseFactory promiseFactory) {
-
- _syncInvoker = syncInvoker;
- _promiseFactory = promiseFactory;
- }
-
- @Override
- public Promise<Response> delete() {
- return method(HttpMethod.DELETE);
- }
-
- @Override
- public <R> Promise<R> delete(Class<R> aClass) {
- return method(HttpMethod.DELETE, aClass);
- }
-
- @Override
- public <R> Promise<R> delete(GenericType<R> genericType) {
- return method(HttpMethod.DELETE, genericType);
- }
-
- @Override
- public Promise<Response> get() {
- return method(HttpMethod.GET);
- }
-
- @Override
- public <R> Promise<R> get(Class<R> aClass) {
- return method(HttpMethod.GET, aClass);
- }
-
- @Override
- public <R> Promise<R> get(GenericType<R> genericType) {
- return method(HttpMethod.GET, genericType);
- }
-
- @Override
- public Promise<Response> head() {
- return method(HttpMethod.HEAD);
- }
-
- @Override
- public <R> Promise<R> method(String s, Class<R> aClass) {
- return _promiseFactory.submit(() -> _syncInvoker.method(s, aClass));
- }
-
- @Override
- public <R> Promise<R> method(String s, Entity<?> entity, Class<R> aClass) {
- return _promiseFactory.submit(
- () -> _syncInvoker.method(s, entity, aClass));
- }
-
- @Override
- public <R> Promise<R> method(
- String s, Entity<?> entity, GenericType<R> genericType) {
-
- return _promiseFactory.submit(
- () -> _syncInvoker.method(s, entity, genericType));
- }
-
- @Override
- public Promise<Response> method(String s, Entity<?> entity) {
- return _promiseFactory.submit(() -> _syncInvoker.method(s, entity));
- }
-
- @Override
- public <R> Promise<R> method(String s, GenericType<R> genericType) {
- return _promiseFactory.submit(
- () -> _syncInvoker.method(s, genericType));
- }
-
- @Override
- public Promise<Response> method(String s) {
- return _promiseFactory.submit(() -> _syncInvoker.method(s));
- }
-
- @Override
- public Promise<Response> options() {
- return method(HttpMethod.OPTIONS);
- }
-
- @Override
- public <R> Promise<R> options(Class<R> aClass) {
- return method(HttpMethod.OPTIONS, aClass);
- }
-
- @Override
- public <R> Promise<R> options(GenericType<R> genericType) {
- return method(HttpMethod.OPTIONS, genericType);
- }
-
- @Override
- public <R> Promise<R> post(Entity<?> entity, Class<R> aClass) {
- return method(HttpMethod.POST, entity, aClass);
- }
-
- @Override
- public <R> Promise<R> post(Entity<?> entity, GenericType<R> genericType) {
- return method(HttpMethod.POST, entity, genericType);
- }
-
- @Override
- public Promise<Response> post(Entity<?> entity) {
- return method(HttpMethod.POST, entity);
- }
-
- @Override
- public <R> Promise<R> put(Entity<?> entity, Class<R> aClass) {
- return method(HttpMethod.PUT, entity, aClass);
- }
-
- @Override
- public <R> Promise<R> put(Entity<?> entity, GenericType<R> genericType) {
- return method(HttpMethod.PUT, entity, genericType);
- }
-
- @Override
- public Promise<Response> put(Entity<?> entity) {
- return method(HttpMethod.PUT, entity);
- }
-
- @Override
- public Promise<Response> trace() {
- return method("TRACE", Response.class);
- }
-
- @Override
- public <R> Promise<R> trace(Class<R> aClass) {
- return method("TRACE", aClass);
- }
-
- @Override
- public <R> Promise<R> trace(GenericType<R> genericType) {
- return method("TRACE", genericType);
- }
-
- private final PromiseFactory _promiseFactory;
- private final SyncInvoker _syncInvoker;
-
-}
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/c62794df/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerProviderImpl.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerProviderImpl.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerProviderImpl.java
deleted file mode 100644
index c8b36d1..0000000
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/client/PromiseRxInvokerProviderImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.aries.jax.rs.whiteboard.internal.client;
-
-import org.osgi.service.jaxrs.client.PromiseRxInvoker;
-import org.osgi.util.promise.PromiseFactory;
-
-import javax.ws.rs.client.RxInvokerProvider;
-import javax.ws.rs.client.SyncInvoker;
-import java.util.concurrent.ExecutorService;
-
-public class PromiseRxInvokerProviderImpl
- implements RxInvokerProvider<PromiseRxInvoker> {
-
- @Override
- public boolean isProviderFor(Class<?> clazz) {
- return clazz == PromiseRxInvoker.class;
- }
-
- @Override
- public PromiseRxInvoker getRxInvoker(
- SyncInvoker syncInvoker, ExecutorService executorService) {
-
- PromiseFactory promiseFactory;
-
- if (executorService != null) {
- promiseFactory = new PromiseFactory(executorService);
- }
- else {
- promiseFactory = new PromiseFactory(
- PromiseFactory.inlineExecutor());
- }
-
- return new PromiseRxInvokerImpl(syncInvoker, promiseFactory);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/c62794df/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerImpl.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerImpl.java b/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerImpl.java
new file mode 100644
index 0000000..9b83261
--- /dev/null
+++ b/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerImpl.java
@@ -0,0 +1,207 @@
+/*
+ * 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.client;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.InvocationCallback;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+
+import org.osgi.service.jaxrs.client.PromiseRxInvoker;
+import org.osgi.util.promise.Deferred;
+import org.osgi.util.promise.Promise;
+import org.osgi.util.promise.PromiseFactory;
+
+class PromiseRxInvokerImpl implements PromiseRxInvoker {
+
+ private static final class DeferredHandler<R> implements InvocationCallback<R> {
+ private final Deferred<R> deferred;
+
+ private DeferredHandler(Deferred<R> deferred) {
+ this.deferred = deferred;
+ }
+
+ @Override
+ public void completed(R response) {
+ deferred.resolve(response);
+ }
+
+ @Override
+ public void failed(Throwable throwable) {
+ deferred.fail(throwable);
+ }
+ }
+ public PromiseRxInvokerImpl(
+ WebClient webClient, PromiseFactory promiseFactory) {
+ _webClient = webClient;
+ _promiseFactory = promiseFactory;
+ }
+
+ @Override
+ public Promise<Response> delete() {
+ return method(HttpMethod.DELETE);
+ }
+
+ @Override
+ public <R> Promise<R> delete(Class<R> aClass) {
+ return method(HttpMethod.DELETE, aClass);
+ }
+
+ @Override
+ public <R> Promise<R> delete(GenericType<R> genericType) {
+ return method(HttpMethod.DELETE, genericType);
+ }
+
+ @Override
+ public Promise<Response> get() {
+ return method(HttpMethod.GET);
+ }
+
+ @Override
+ public <R> Promise<R> get(Class<R> aClass) {
+ return method(HttpMethod.GET, aClass);
+ }
+
+ @Override
+ public <R> Promise<R> get(GenericType<R> genericType) {
+ return method(HttpMethod.GET, genericType);
+ }
+
+ @Override
+ public Promise<Response> head() {
+ return method(HttpMethod.HEAD);
+ }
+
+ @Override
+ public <R> Promise<R> method(String s, Class<R> responseType) {
+
+ Deferred<R> deferred = _promiseFactory.deferred();
+
+ _webClient.doInvokeAsync(s, null, null, null, responseType, responseType,
+ new DeferredHandler<R>(deferred));
+
+ return deferred.getPromise();
+ }
+
+ @Override
+ public <R> Promise<R> method(String s, Entity<?> entity, Class<R> responseType) {
+
+ Deferred<R> deferred = _promiseFactory.deferred();
+
+ _webClient.doInvokeAsync(s, entity, null, null, responseType, responseType,
+ new DeferredHandler<R>(deferred));
+
+ return deferred.getPromise();
+ }
+
+ @Override
+ public <R> Promise<R> method(
+ String s, Entity<?> entity, GenericType<R> genericType) {
+
+ Deferred<R> deferred = _promiseFactory.deferred();
+
+ _webClient.doInvokeAsync(s, entity, null, null, genericType.getRawType(), genericType.getType(),
+ new DeferredHandler<R>(deferred));
+
+ return deferred.getPromise();
+ }
+
+ @Override
+ public Promise<Response> method(String s, Entity<?> entity) {
+ return method(s, entity, Response.class);
+ }
+
+ @Override
+ public <R> Promise<R> method(String s, GenericType<R> genericType) {
+ Deferred<R> deferred = _promiseFactory.deferred();
+
+ _webClient.doInvokeAsync(s, null, null, null, genericType.getRawType(), genericType.getType(),
+ new DeferredHandler<R>(deferred));
+
+ return deferred.getPromise();
+ }
+
+ @Override
+ public Promise<Response> method(String s) {
+ return method(s, Response.class);
+ }
+
+ @Override
+ public Promise<Response> options() {
+ return method(HttpMethod.OPTIONS);
+ }
+
+ @Override
+ public <R> Promise<R> options(Class<R> aClass) {
+ return method(HttpMethod.OPTIONS, aClass);
+ }
+
+ @Override
+ public <R> Promise<R> options(GenericType<R> genericType) {
+ return method(HttpMethod.OPTIONS, genericType);
+ }
+
+ @Override
+ public <R> Promise<R> post(Entity<?> entity, Class<R> aClass) {
+ return method(HttpMethod.POST, entity, aClass);
+ }
+
+ @Override
+ public <R> Promise<R> post(Entity<?> entity, GenericType<R> genericType) {
+ return method(HttpMethod.POST, entity, genericType);
+ }
+
+ @Override
+ public Promise<Response> post(Entity<?> entity) {
+ return method(HttpMethod.POST, entity);
+ }
+
+ @Override
+ public <R> Promise<R> put(Entity<?> entity, Class<R> aClass) {
+ return method(HttpMethod.PUT, entity, aClass);
+ }
+
+ @Override
+ public <R> Promise<R> put(Entity<?> entity, GenericType<R> genericType) {
+ return method(HttpMethod.PUT, entity, genericType);
+ }
+
+ @Override
+ public Promise<Response> put(Entity<?> entity) {
+ return method(HttpMethod.PUT, entity);
+ }
+
+ @Override
+ public Promise<Response> trace() {
+ return method("TRACE", Response.class);
+ }
+
+ @Override
+ public <R> Promise<R> trace(Class<R> aClass) {
+ return method("TRACE", aClass);
+ }
+
+ @Override
+ public <R> Promise<R> trace(GenericType<R> genericType) {
+ return method("TRACE", genericType);
+ }
+
+ private final PromiseFactory _promiseFactory;
+ private final WebClient _webClient;
+}
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/c62794df/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerProviderImpl.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerProviderImpl.java b/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerProviderImpl.java
new file mode 100644
index 0000000..de420e9
--- /dev/null
+++ b/jax-rs.whiteboard/src/main/java/org/apache/cxf/jaxrs/client/PromiseRxInvokerProviderImpl.java
@@ -0,0 +1,54 @@
+/*
+ * 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.client;
+
+import java.util.concurrent.ExecutorService;
+
+import javax.ws.rs.client.RxInvokerProvider;
+import javax.ws.rs.client.SyncInvoker;
+
+import org.apache.cxf.jaxrs.client.SyncInvokerImpl;
+import org.osgi.service.jaxrs.client.PromiseRxInvoker;
+import org.osgi.util.promise.PromiseFactory;
+
+public class PromiseRxInvokerProviderImpl
+ implements RxInvokerProvider<PromiseRxInvoker> {
+
+ @Override
+ public boolean isProviderFor(Class<?> clazz) {
+ return clazz == PromiseRxInvoker.class;
+ }
+
+ @Override
+ public PromiseRxInvoker getRxInvoker(
+ SyncInvoker syncInvoker, ExecutorService executorService) {
+
+ PromiseFactory promiseFactory;
+
+ if (executorService != null) {
+ promiseFactory = new PromiseFactory(executorService);
+ }
+ else {
+ promiseFactory = new PromiseFactory(
+ PromiseFactory.inlineExecutor());
+ }
+
+ return new PromiseRxInvokerImpl(((SyncInvokerImpl) syncInvoker).getWebClient(), promiseFactory);
+ }
+
+}