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

ASF GitHub Bot commented on SCB-138:
------------------------------------

seanyinx commented on a change in pull request #98: SCB-138 use grpc 
bidirectional streaming to connect alpha and omega
URL: 
https://github.com/apache/incubator-servicecomb-saga/pull/98#discussion_r159568988
 
 

 ##########
 File path: 
alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcTxEventStreamObserver.java
 ##########
 @@ -0,0 +1,127 @@
+/*
+ *
+ * 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.servicecomb.saga.alpha.server;
+
+import static org.apache.servicecomb.saga.alpha.core.EventType.TxStartedEvent;
+
+import java.lang.invoke.MethodHandles;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicecomb.saga.alpha.core.OmegaCallback;
+import org.apache.servicecomb.saga.alpha.core.TxConsistentService;
+import org.apache.servicecomb.saga.alpha.core.TxEvent;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcCompensateCommand;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTxEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.grpc.stub.StreamObserver;
+
+class GrpcTxEventStreamObserver implements StreamObserver<GrpcTxEvent> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private final Map<String, Map<String, OmegaCallback>> omegaCallbacks;
+
+  private final Map<StreamObserver<GrpcCompensateCommand>, Map<String, 
String>> omegaCallbacksReverse;
+
+  private final TxConsistentService txConsistentService;
+
+  private final StreamObserver<GrpcCompensateCommand> responseObserver;
+
+  GrpcTxEventStreamObserver(Map<String, Map<String, OmegaCallback>> 
omegaCallbacks,
+      Map<StreamObserver<GrpcCompensateCommand>, Map<String, String>> 
omegaCallbacksReverse,
+      TxConsistentService txConsistentService, 
StreamObserver<GrpcCompensateCommand> responseObserver) {
+    this.omegaCallbacks = omegaCallbacks;
+    this.omegaCallbacksReverse = omegaCallbacksReverse;
+    this.txConsistentService = txConsistentService;
+    this.responseObserver = responseObserver;
+  }
+
+  @Override
+  public void onNext(GrpcTxEvent message) {
+    // register a callback on started event
+    String serviceName = message.getServiceName();
+    String instanceId = message.getInstanceId();
+    if (message.getType().equals(TxStartedEvent.name())) {
+      Map<String, OmegaCallback> instanceCallback = omegaCallbacks
+          .computeIfAbsent(serviceName, v -> new ConcurrentHashMap<>());
+      instanceCallback.putIfAbsent(instanceId, new 
GrpcOmegaCallback(responseObserver));
 
 Review comment:
   this line creates a new grpc omega callback on every started event...

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


> [pack] omega's callback about transaction state
> -----------------------------------------------
>
>                 Key: SCB-138
>                 URL: https://issues.apache.org/jira/browse/SCB-138
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>          Components: Saga
>            Reporter: Eric Lee
>            Assignee: Eric Lee
>             Fix For: java-chassis-1.0.0-m1
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> as a dev, i want to register callback function in the server side, so the 
> server can send messages back to the client directly instead of establishing 
> a new connection to the exact client with its corresponding uri.



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

Reply via email to