[
https://issues.apache.org/jira/browse/SCB-817?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16594431#comment-16594431
]
ASF GitHub Bot commented on SCB-817:
------------------------------------
cherrylzhao commented on a change in pull request #274: SCB-817, SCB-818 TCC
Omega side implemenation
URL:
https://github.com/apache/incubator-servicecomb-saga/pull/274#discussion_r213170272
##########
File path:
omega/omega-connector/omega-connector-grpc/src/main/java/org/apache/servicecomb/saga/omega/connector/grpc/GrpcTccEventService.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.omega.connector.grpc;
+
+import org.apache.servicecomb.saga.omega.context.ServiceConfig;
+import org.apache.servicecomb.saga.omega.transaction.AlphaResponse;
+import org.apache.servicecomb.saga.omega.transaction.tcc.MessageHandler;
+import org.apache.servicecomb.saga.omega.transaction.tcc.TccEventService;
+import
org.apache.servicecomb.saga.omega.transaction.tcc.events.CoordinatedEvent;
+import
org.apache.servicecomb.saga.omega.transaction.tcc.events.ParticipatedEvent;
+import org.apache.servicecomb.saga.omega.transaction.tcc.events.TccEndedEvent;
+import
org.apache.servicecomb.saga.omega.transaction.tcc.events.TccStartedEvent;
+
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcAck;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcServiceConfig;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccCoordinatedEvent;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccParticipatedEvent;
+import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionEndedEvent;
+import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionStartedEvent;
+import org.apache.servicecomb.saga.pack.contract.grpc.TccEventServiceGrpc;
+import
org.apache.servicecomb.saga.pack.contract.grpc.TccEventServiceGrpc.TccEventServiceBlockingStub;
+import
org.apache.servicecomb.saga.pack.contract.grpc.TccEventServiceGrpc.TccEventServiceStub;
+
+import io.grpc.ManagedChannel;
+
+public class GrpcTccEventService implements TccEventService {
+ private final GrpcServiceConfig serviceConfig;
+ private final String target;
+ private final TccEventServiceBlockingStub tccBlockingEventService;
+ private final TccEventServiceStub tccAsyncEventService;
+ private final GrpcCoordinateStreamObserver observer;
+
+ public GrpcTccEventService(ServiceConfig serviceConfig,
+ ManagedChannel channel,
+ String address,
+ MessageHandler handler
+ ) {
+ this.target = address;
+ tccBlockingEventService = TccEventServiceGrpc.newBlockingStub(channel);
+ tccAsyncEventService = TccEventServiceGrpc.newStub(channel);
+ this.serviceConfig = serviceConfig(serviceConfig.serviceName(),
serviceConfig.instanceId());
+ observer = new GrpcCoordinateStreamObserver(handler);
+ }
+
+ @Override
+ public void onConnected() {
+ tccAsyncEventService.onConnected(serviceConfig, observer);
+ }
+
+ @Override
+ public void onDisconnected() {
+ tccBlockingEventService.onDisconnected(serviceConfig);
+ }
+
+ @Override
+ public void close() {
+ // do nothing here
+ }
+
+ @Override
+ public String target() {
+ return target;
+ }
+
+ @Override
+ public AlphaResponse participate(ParticipatedEvent participateEvent) {
+ GrpcAck grpcAck =
tccBlockingEventService.participate(convertTo(participateEvent));
+ return new AlphaResponse(grpcAck.getAborted());
+ }
+
+ @Override
+ public AlphaResponse tccTransactionStart(TccStartedEvent tccStartEvent) {
+ GrpcAck grpcAck =
tccBlockingEventService.onTccTransactionStarted(convertTo(tccStartEvent));
+ return new AlphaResponse(grpcAck.getAborted());
+ }
+
+
+ @Override
+ public AlphaResponse tccTransactionStop(TccEndedEvent tccEndEvent) {
+ GrpcAck grpcAck =
tccBlockingEventService.onTccTransactionEnded(convertTo(tccEndEvent));
+ return new AlphaResponse(grpcAck.getAborted());
+
+ }
+
+ @Override
+ public AlphaResponse coordinate(CoordinatedEvent coordinatedEvent) {
Review comment:
I can't understand coordinate method mean, when sending transactionEndEvent,
alpha will send the cordinateCommand to omega instance asynchronous.
it is why onConnect method has a stream observer.
----------------------------------------------------------------
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:
[email protected]
> Setup the TCC events
> ---------------------
>
> Key: SCB-817
> URL: https://issues.apache.org/jira/browse/SCB-817
> Project: Apache ServiceComb
> Issue Type: Sub-task
> Components: Saga
> Reporter: Willem Jiang
> Assignee: Willem Jiang
> Priority: Major
>
> It could be a challenge for us to reuse the Saga event, so we may create
> another set of event for TCC to use.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)