You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/07/08 08:48:29 UTC

[GitHub] [dubbo] JooKS-me opened a new pull request, #10290: Support dubbo reactive stream with project reactor

JooKS-me opened a new pull request, #10290:
URL: https://github.com/apache/dubbo/pull/10290

   ## What is the purpose of the change
   
   Ref #10288 
   
   Support dubbo reactive stream with project reactor
   
   still working~
   
   ## Brief changelog
   
   
   ## Verifying this change
   
   
   <!-- Follow this checklist to help us incorporate your contribution quickly and easily: -->
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
   - [ ] Each commit in the pull request should have a meaningful subject line and body.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
   - [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [ ] Add some description to [dubbo-website](https://github.com/apache/dubbo-website) project if you are requesting to add a feature.
   - [ ] GitHub Actions works fine on your own branch.
   - [ ] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: [WIP] Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r916812473


##########
dubbo-rpc/dubbo-rpc-triple/pom.xml:
##########
@@ -30,9 +30,20 @@
     <properties>
         <skip_maven_deploy>false</skip_maven_deploy>
         <dubbo.compiler.version>0.0.4.1-SNAPSHOT</dubbo.compiler.version>
-
+        <reactive.version>1.0.4</reactive.version>
+        <reactor.version>3.4.19</reactor.version>
     </properties>
     <dependencies>
+        <dependency>
+            <groupId>org.reactivestreams</groupId>
+            <artifactId>reactive-streams</artifactId>
+            <version>${reactive.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-core</artifactId>
+            <version>${reactor.version}</version>

Review Comment:
   I think `Implemented in a separate module` is better, so I create a `dubbo-rpc-triple-reactive` module?
   Like this:
   ---dubbo-rpc
   -------dubbo-rpc-triple
   -------dubbo-rpc-triple-reactive



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on pull request #10290: [WIP] Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#issuecomment-1179513963

   > Greate PR , this project may be helpful https://github.com/salesforce/reactive-grpc
   
   Thanks, get it~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] EarthChen commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
EarthChen commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r934158637


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -195,26 +200,15 @@ AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocat
 
         RequestMetadata request = createRequest(methodDescriptor, invocation, timeout);
 
+        ClientCall.Listener callListener;
+
         final Object pureArgument;
-        if (methodDescriptor.getParameterClasses().length == 2
-            && methodDescriptor.getParameterClasses()[1].isAssignableFrom(
-            StreamObserver.class)) {
+        if (invocation.getArguments() != null && invocation.getArguments().length == 2 && invocation.getArguments()[1] instanceof StreamObserver) {
             StreamObserver<Object> observer = (StreamObserver<Object>) invocation.getArguments()[1];
-            future.whenComplete((r, t) -> {

Review Comment:
   why del?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -195,26 +200,15 @@ AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocat
 
         RequestMetadata request = createRequest(methodDescriptor, invocation, timeout);
 
+        ClientCall.Listener callListener;
+
         final Object pureArgument;
-        if (methodDescriptor.getParameterClasses().length == 2
-            && methodDescriptor.getParameterClasses()[1].isAssignableFrom(
-            StreamObserver.class)) {
+        if (invocation.getArguments() != null && invocation.getArguments().length == 2 && invocation.getArguments()[1] instanceof StreamObserver) {

Review Comment:
   Why did I change this?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();

Review Comment:
   Does it feel better to abstract into a unified api?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -181,7 +182,11 @@ StreamObserver<Object> streamCall(ClientCall call,
         }
         ObserverToClientCallListenerAdapter listener = new ObserverToClientCallListenerAdapter(
             responseObserver);
-        return call.start(metadata, listener);
+        StreamObserver<Object> streamObserver = call.start(metadata, listener);
+        if (responseObserver instanceof ClientResponseObserver) {

Review Comment:
   Whether ClientResponseObserver and CancellationContext can merge? 



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =

Review Comment:
   Is it possible not to use the updater?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/ServerTripleReactorSubscriber.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.CancellationContext;
+import org.apache.dubbo.rpc.protocol.tri.CancelableStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+
+/**
+ * The Subscriber in server to passing the data produced by user publisher to responseStream.
+ */
+public class ServerTripleReactorSubscriber<T> extends AbstractTripleReactorSubscriber<T>{
+
+    @Override
+    public void subscribe(CallStreamObserver<T> downstream) {
+        super.subscribe(downstream);
+        if (downstream instanceof CancelableStreamObserver) {
+            CancelableStreamObserver<?> observer = (CancelableStreamObserver<?>) downstream;
+            final CancellationContext context;
+            if (observer.getCancellationContext() == null) {

Review Comment:
   In what scenario is it null?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();
+            } else if (subscription instanceof ServerStreamObserver<?>) {
+                ((ServerStreamObserver<?>) subscription).disableAutoInboundFlowControl();
+            }
+            if (onSubscribe != null) {
+                onSubscribe.accept(subscription);
+            }
+            return;
+        }
+
+        throw new IllegalStateException(getClass().getSimpleName() + " supports only a single subscription");
+    }
+
+    @Override
+    public void onNext(T data) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onNext(data);
+    }
+
+    @Override
+    public void onError(Throwable throwable) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onError(throwable);
+        isDone = true;
+        doPostShutdown();
+    }
+
+    @Override
+    public void onCompleted() {
+        if (isDone || isCancelled) {
+            return;
+        }
+        isDone = true;
+        downstream.onComplete();
+        doPostShutdown();
+    }
+
+    private void doPostShutdown() {
+        Runnable r = shutdownHook;
+        // CAS to confirm shutdownHook will be run only once.
+        if (r != null && SHUTDOWN_HOOK.compareAndSet(this, r, null)) {
+            r.run();
+        }
+    }
+
+    @Override
+    public void subscribe(Subscriber<? super T> subscriber) {
+        if (subscriber == null) {
+            throw new NullPointerException();
+        }
+
+        if (SUBSCRIBED.compareAndSet(false, true)) {
+            subscriber.onSubscribe(this);
+            this.downstream = subscriber;
+            if (isCancelled) {
+                this.downstream = null;
+            }
+        } else {
+            subscriber.onSubscribe(EMPTY_SUBSCRIPTION);

Review Comment:
   I think it's better to discard silently here



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -224,8 +218,8 @@ AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocat
             result = new AsyncRpcResult(future, invocation);
             result.setExecutor(callbackExecutor);
             FutureContext.getContext().setCompatibleFuture(future);
+            callListener = new UnaryClientCallListener(future);

Review Comment:
   Why did I change this?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorSubscriber.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+import reactor.core.CoreSubscriber;
+import reactor.util.annotation.NonNull;
+
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <br>
+ * Passing the data from Reactive producer to CallStreamObserver.
+ */
+public abstract class AbstractTripleReactorSubscriber<T> implements Subscriber<T>, CoreSubscriber<T> {
+
+    private static final Subscription CANCELLED_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {}
+        @Override
+        public void request(long n) {}
+    };
+
+    protected volatile CallStreamObserver<T> downstream;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorSubscriber, CallStreamObserver> DOWNSTREAM =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorSubscriber.class, CallStreamObserver.class, "downstream");
+
+    private volatile Subscription subscription;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorSubscriber, Subscription> SUBSCRIPTION =

Review Comment:
   Is it possible not to use the updater?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();
+            } else if (subscription instanceof ServerStreamObserver<?>) {
+                ((ServerStreamObserver<?>) subscription).disableAutoInboundFlowControl();
+            }
+            if (onSubscribe != null) {
+                onSubscribe.accept(subscription);
+            }
+            return;
+        }
+
+        throw new IllegalStateException(getClass().getSimpleName() + " supports only a single subscription");
+    }
+
+    @Override
+    public void onNext(T data) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onNext(data);
+    }
+
+    @Override
+    public void onError(Throwable throwable) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onError(throwable);
+        isDone = true;
+        doPostShutdown();
+    }
+
+    @Override
+    public void onCompleted() {
+        if (isDone || isCancelled) {
+            return;
+        }
+        isDone = true;
+        downstream.onComplete();
+        doPostShutdown();
+    }
+
+    private void doPostShutdown() {
+        Runnable r = shutdownHook;
+        // CAS to confirm shutdownHook will be run only once.
+        if (r != null && SHUTDOWN_HOOK.compareAndSet(this, r, null)) {
+            r.run();
+        }
+    }
+
+    @Override
+    public void subscribe(Subscriber<? super T> subscriber) {
+        if (subscriber == null) {
+            throw new NullPointerException();
+        }
+
+        if (SUBSCRIBED.compareAndSet(false, true)) {
+            subscriber.onSubscribe(this);
+            this.downstream = subscriber;
+            if (isCancelled) {
+                this.downstream = null;
+            }
+        } else {
+            subscriber.onSubscribe(EMPTY_SUBSCRIPTION);
+            subscriber.onError(new IllegalStateException(getClass().getSimpleName() + " can't be subscribed repeatedly"));
+        }
+    }
+
+    @Override
+    public void request(long l) {
+        if (SUBSCRIBED.get() && CAN_REQUEST.get()) {
+            subscription.request(l >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l);
+        } else {
+            REQUESTED.getAndAdd(this, l);
+        }
+    }
+
+    @Override
+    public void startRequest() {
+        if (CAN_REQUEST.compareAndSet(false, true)) {
+            long count = requested;

Review Comment:
   Is it possible to call request directly?



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java:
##########
@@ -54,5 +55,9 @@ public void onStart(ClientCall call) {
         if (call.isAutoRequest()) {
             call.request(1);
         }
+
+        if (delegate instanceof SafeRequestObserver) {

Review Comment:
   Why not just replace the delegate?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936215760


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();
+            } else if (subscription instanceof ServerStreamObserver<?>) {
+                ((ServerStreamObserver<?>) subscription).disableAutoInboundFlowControl();
+            }
+            if (onSubscribe != null) {
+                onSubscribe.accept(subscription);
+            }
+            return;
+        }
+
+        throw new IllegalStateException(getClass().getSimpleName() + " supports only a single subscription");
+    }
+
+    @Override
+    public void onNext(T data) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onNext(data);
+    }
+
+    @Override
+    public void onError(Throwable throwable) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onError(throwable);
+        isDone = true;
+        doPostShutdown();
+    }
+
+    @Override
+    public void onCompleted() {
+        if (isDone || isCancelled) {
+            return;
+        }
+        isDone = true;
+        downstream.onComplete();
+        doPostShutdown();
+    }
+
+    private void doPostShutdown() {
+        Runnable r = shutdownHook;
+        // CAS to confirm shutdownHook will be run only once.
+        if (r != null && SHUTDOWN_HOOK.compareAndSet(this, r, null)) {
+            r.run();
+        }
+    }
+
+    @Override
+    public void subscribe(Subscriber<? super T> subscriber) {
+        if (subscriber == null) {
+            throw new NullPointerException();
+        }
+
+        if (SUBSCRIBED.compareAndSet(false, true)) {
+            subscriber.onSubscribe(this);
+            this.downstream = subscriber;
+            if (isCancelled) {
+                this.downstream = null;
+            }
+        } else {
+            subscriber.onSubscribe(EMPTY_SUBSCRIPTION);

Review Comment:
   ok



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] guohao commented on pull request #10290: [WIP] Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
guohao commented on PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#issuecomment-1179513354

   Greate PR , this project may be helpful https://github.com/salesforce/reactive-grpc


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ merged pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
AlbumenJ merged PR #10290:
URL: https://github.com/apache/dubbo/pull/10290


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r937765477


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();

Review Comment:
   Resolved in #10406



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936184975


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -195,26 +200,15 @@ AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocat
 
         RequestMetadata request = createRequest(methodDescriptor, invocation, timeout);
 
+        ClientCall.Listener callListener;
+
         final Object pureArgument;
-        if (methodDescriptor.getParameterClasses().length == 2
-            && methodDescriptor.getParameterClasses()[1].isAssignableFrom(
-            StreamObserver.class)) {
+        if (invocation.getArguments() != null && invocation.getArguments().length == 2 && invocation.getArguments()[1] instanceof StreamObserver) {

Review Comment:
   Handle in #10398



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936197084


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/ServerTripleReactorSubscriber.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.CancellationContext;
+import org.apache.dubbo.rpc.protocol.tri.CancelableStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+
+/**
+ * The Subscriber in server to passing the data produced by user publisher to responseStream.
+ */
+public class ServerTripleReactorSubscriber<T> extends AbstractTripleReactorSubscriber<T>{
+
+    @Override
+    public void subscribe(CallStreamObserver<T> downstream) {
+        super.subscribe(downstream);
+        if (downstream instanceof CancelableStreamObserver) {
+            CancelableStreamObserver<?> observer = (CancelableStreamObserver<?>) downstream;
+            final CancellationContext context;
+            if (observer.getCancellationContext() == null) {

Review Comment:
   This is to prevent possible changes later, it cannot be null at present.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936205718


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();
+            } else if (subscription instanceof ServerStreamObserver<?>) {
+                ((ServerStreamObserver<?>) subscription).disableAutoInboundFlowControl();
+            }
+            if (onSubscribe != null) {
+                onSubscribe.accept(subscription);
+            }
+            return;
+        }
+
+        throw new IllegalStateException(getClass().getSimpleName() + " supports only a single subscription");
+    }
+
+    @Override
+    public void onNext(T data) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onNext(data);
+    }
+
+    @Override
+    public void onError(Throwable throwable) {
+        if (isDone || isCancelled) {
+            return;
+        }
+        downstream.onError(throwable);
+        isDone = true;
+        doPostShutdown();
+    }
+
+    @Override
+    public void onCompleted() {
+        if (isDone || isCancelled) {
+            return;
+        }
+        isDone = true;
+        downstream.onComplete();
+        doPostShutdown();
+    }
+
+    private void doPostShutdown() {
+        Runnable r = shutdownHook;
+        // CAS to confirm shutdownHook will be run only once.
+        if (r != null && SHUTDOWN_HOOK.compareAndSet(this, r, null)) {
+            r.run();
+        }
+    }
+
+    @Override
+    public void subscribe(Subscriber<? super T> subscriber) {
+        if (subscriber == null) {
+            throw new NullPointerException();
+        }
+
+        if (SUBSCRIBED.compareAndSet(false, true)) {
+            subscriber.onSubscribe(this);
+            this.downstream = subscriber;
+            if (isCancelled) {
+                this.downstream = null;
+            }
+        } else {
+            subscriber.onSubscribe(EMPTY_SUBSCRIPTION);
+            subscriber.onError(new IllegalStateException(getClass().getSimpleName() + " can't be subscribed repeatedly"));
+        }
+    }
+
+    @Override
+    public void request(long l) {
+        if (SUBSCRIBED.get() && CAN_REQUEST.get()) {
+            subscription.request(l >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l);
+        } else {
+            REQUESTED.getAndAdd(this, l);
+        }
+    }
+
+    @Override
+    public void startRequest() {
+        if (CAN_REQUEST.compareAndSet(false, true)) {
+            long count = requested;

Review Comment:
   No, in the scenario where the client uses serverStream, the request can only be made after ObserverToClientCallListenerAdapter#onStart is called, otherwise the NPE of TripleClientStream#request will be triggered, because the deframer of TripleClientStream has not been initialized.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936213810


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorPublisher.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.ClientStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.SafeRequestObserver;
+import org.apache.dubbo.rpc.protocol.tri.ServerStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Publisher;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Consumer;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <p>
+ * 1. passing the data received by CallStreamObserver to Reactive consumer <br>
+ * 2. passing the request of Reactive API to CallStreamObserver
+ */
+public abstract class AbstractTripleReactorPublisher<T> implements Publisher<T>, SafeRequestObserver<T>, Subscription {
+
+    private static final Subscription EMPTY_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {
+        }
+        @Override
+        public void request(long n) {
+        }
+    };
+
+    private volatile long requested;
+
+    private static final AtomicLongFieldUpdater<AbstractTripleReactorPublisher> REQUESTED =
+        AtomicLongFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, "requested");
+
+    // weather CallStreamObserver#request can be called
+    private final AtomicBoolean CAN_REQUEST = new AtomicBoolean();
+
+    // weather publisher has been subscribed
+    private final AtomicBoolean SUBSCRIBED = new AtomicBoolean();
+
+    private volatile Subscriber<? super T> downstream;
+
+    protected volatile CallStreamObserver<?> subscription;
+
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, CallStreamObserver> SUBSCRIPTION =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, CallStreamObserver.class, "subscription");
+
+    // cancel status
+    private volatile boolean isCancelled;
+
+    // complete status
+    private volatile boolean isDone;
+
+    // to help bind TripleSubscriber
+    private volatile Consumer<CallStreamObserver<?>> onSubscribe;
+
+    private volatile Runnable shutdownHook;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorPublisher, Runnable> SHUTDOWN_HOOK =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorPublisher.class, Runnable.class, "shutdownHook");
+
+    public AbstractTripleReactorPublisher() {
+    }
+
+    public AbstractTripleReactorPublisher(Consumer<CallStreamObserver<?>> onSubscribe, Runnable shutdownHook) {
+        this.onSubscribe = onSubscribe;
+        this.shutdownHook = shutdownHook;
+    }
+
+    protected void onSubscribe(final CallStreamObserver<?> subscription) {
+        if (subscription != null && SUBSCRIPTION.compareAndSet(this, null, subscription)) {
+            this.subscription = subscription;
+            if (subscription instanceof ClientStreamObserver<?>) {
+                ((ClientStreamObserver<?>) subscription).disableAutoRequest();

Review Comment:
   How about let's merge disableAutoRequest into CallStreamObserver?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] codecov-commenter commented on pull request #10290: [WIP] Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#issuecomment-1193062052

   # [Codecov](https://codecov.io/gh/apache/dubbo/pull/10290?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10290](https://codecov.io/gh/apache/dubbo/pull/10290?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (be6c99a) into [3.1](https://codecov.io/gh/apache/dubbo/commit/6597a24cc3022af29279142d3af75ce925697184?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6597a24) will **decrease** coverage by `0.68%`.
   > The diff coverage is `1.44%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##                3.1   #10290      +/-   ##
   ============================================
   - Coverage     65.59%   64.91%   -0.69%     
   + Complexity      318      317       -1     
   ============================================
     Files          1248     1260      +12     
     Lines         54254    54412     +158     
     Branches       8190     8169      -21     
   ============================================
   - Hits          35589    35322     -267     
   - Misses        14806    15201     +395     
   - Partials       3859     3889      +30     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dubbo/pull/10290?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../tri/call/ObserverToClientCallListenerAdapter.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvY2FsbC9PYnNlcnZlclRvQ2xpZW50Q2FsbExpc3RlbmVyQWRhcHRlci5qYXZh) | `64.70% <0.00%> (-8.63%)` | :arrow_down: |
   | [...ocol/tri/observer/ServerCallToObserverAdapter.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvb2JzZXJ2ZXIvU2VydmVyQ2FsbFRvT2JzZXJ2ZXJBZGFwdGVyLmphdmE=) | `63.15% <ø> (ø)` | |
   | [...l/tri/reactive/AbstractTripleReactorPublisher.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvQWJzdHJhY3RUcmlwbGVSZWFjdG9yUHVibGlzaGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [.../tri/reactive/AbstractTripleReactorSubscriber.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvQWJzdHJhY3RUcmlwbGVSZWFjdG9yU3Vic2NyaWJlci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...col/tri/reactive/ClientTripleReactorPublisher.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvQ2xpZW50VHJpcGxlUmVhY3RvclB1Ymxpc2hlci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ol/tri/reactive/ClientTripleReactorSubscriber.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvQ2xpZW50VHJpcGxlUmVhY3RvclN1YnNjcmliZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...col/tri/reactive/ServerTripleReactorPublisher.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvU2VydmVyVHJpcGxlUmVhY3RvclB1Ymxpc2hlci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ol/tri/reactive/ServerTripleReactorSubscriber.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvU2VydmVyVHJpcGxlUmVhY3RvclN1YnNjcmliZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...rotocol/tri/reactive/calls/ReactorClientCalls.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvY2FsbHMvUmVhY3RvckNsaWVudENhbGxzLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...rotocol/tri/reactive/calls/ReactorServerCalls.java](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy10cmlwbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC90cmkvcmVhY3RpdmUvY2FsbHMvUmVhY3RvclNlcnZlckNhbGxzLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | ... and [81 more](https://codecov.io/gh/apache/dubbo/pull/10290/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936188646


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java:
##########
@@ -181,7 +182,11 @@ StreamObserver<Object> streamCall(ClientCall call,
         }
         ObserverToClientCallListenerAdapter listener = new ObserverToClientCallListenerAdapter(
             responseObserver);
-        return call.start(metadata, listener);
+        StreamObserver<Object> streamObserver = call.start(metadata, listener);
+        if (responseObserver instanceof ClientResponseObserver) {

Review Comment:
   good idea



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#issuecomment-1209514537

   Sample and IT in https://github.com/apache/dubbo-samples/pull/491


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] EarthChen commented on a diff in pull request #10290: [WIP] Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
EarthChen commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r916792463


##########
dubbo-rpc/dubbo-rpc-triple/pom.xml:
##########
@@ -30,9 +30,20 @@
     <properties>
         <skip_maven_deploy>false</skip_maven_deploy>
         <dubbo.compiler.version>0.0.4.1-SNAPSHOT</dubbo.compiler.version>
-
+        <reactive.version>1.0.4</reactive.version>
+        <reactor.version>3.4.19</reactor.version>
     </properties>
     <dependencies>
+        <dependency>
+            <groupId>org.reactivestreams</groupId>
+            <artifactId>reactive-streams</artifactId>
+            <version>${reactive.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-core</artifactId>
+            <version>${reactor.version}</version>

Review Comment:
   set scope=`provide` or Implemented in a separate module is better?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936200760


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/ServerTripleReactorSubscriber.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.CancellationContext;
+import org.apache.dubbo.rpc.protocol.tri.CancelableStreamObserver;
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+
+/**
+ * The Subscriber in server to passing the data produced by user publisher to responseStream.
+ */
+public class ServerTripleReactorSubscriber<T> extends AbstractTripleReactorSubscriber<T>{
+
+    @Override
+    public void subscribe(CallStreamObserver<T> downstream) {
+        super.subscribe(downstream);
+        if (downstream instanceof CancelableStreamObserver) {
+            CancelableStreamObserver<?> observer = (CancelableStreamObserver<?>) downstream;
+            final CancellationContext context;
+            if (observer.getCancellationContext() == null) {

Review Comment:
   At present, this place is always `null`, and it is additionally judged that it is `not null` to defend against possible changes later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] JooKS-me commented on a diff in pull request #10290: Support dubbo reactive stream with project reactor

Posted by GitBox <gi...@apache.org>.
JooKS-me commented on code in PR #10290:
URL: https://github.com/apache/dubbo/pull/10290#discussion_r936360184


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/reactive/AbstractTripleReactorSubscriber.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.dubbo.rpc.protocol.tri.reactive;
+
+import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+import reactor.core.CoreSubscriber;
+import reactor.util.annotation.NonNull;
+
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+/**
+ * The middle layer between {@link org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver} and Reactive API. <br>
+ * Passing the data from Reactive producer to CallStreamObserver.
+ */
+public abstract class AbstractTripleReactorSubscriber<T> implements Subscriber<T>, CoreSubscriber<T> {
+
+    private static final Subscription CANCELLED_SUBSCRIPTION = new Subscription() {
+        @Override
+        public void cancel() {}
+        @Override
+        public void request(long n) {}
+    };
+
+    protected volatile CallStreamObserver<T> downstream;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorSubscriber, CallStreamObserver> DOWNSTREAM =
+        AtomicReferenceFieldUpdater.newUpdater(AbstractTripleReactorSubscriber.class, CallStreamObserver.class, "downstream");
+
+    private volatile Subscription subscription;
+
+    @SuppressWarnings("rawtypes")
+    private static final AtomicReferenceFieldUpdater<AbstractTripleReactorSubscriber, Subscription> SUBSCRIPTION =

Review Comment:
   removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org