eric-lee-ltk commented on a change in pull request #109: [WIP]SCB-173 mark start of saga URL: https://github.com/apache/incubator-servicecomb-saga/pull/109#discussion_r160354710
########## File path: omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAnnotationProcessor.java ########## @@ -0,0 +1,50 @@ +/* + * 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.transaction; + +import org.apache.servicecomb.saga.omega.context.OmegaContext; + +public class SagaStartAnnotationProcessor { + + private final OmegaContext omegaContext; + + private final MessageSender sender; + + SagaStartAnnotationProcessor(OmegaContext omegaContext, MessageSender sender) { + this.omegaContext = omegaContext; + this.sender = sender; + } + + void preIntercept() { + String globalTxId = initChildContext(); + // reuse the globalTxId as localTxId to differ localTxId in SagaStartedEvent and the first TxStartedEvent + sender.send(new SagaStartedEvent(globalTxId, globalTxId)); + } + + void postIntercept() { + String globalTxId = omegaContext.globalTxId(); + sender.send(new SagaEndedEvent(globalTxId, globalTxId)); + } + + private String initChildContext() { + String globalTxId = omegaContext.newGlobalTxId(); + omegaContext.newLocalTxId(); + omegaContext.setParentTxId(globalTxId); Review comment: If you see it as a child context, it maybe less weird.... ---------------------------------------------------------------- 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] With regards, Apache Git Services
