[ https://issues.apache.org/jira/browse/SCB-149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16307740#comment-16307740 ]
ASF GitHub Bot commented on SCB-149: ------------------------------------ seanyinx commented on a change in pull request #95: [SCB-149] service aware callback URL: https://github.com/apache/incubator-servicecomb-saga/pull/95#discussion_r159180404 ########## File path: alpha/alpha-core/src/main/java/io/servicecomb/saga/alpha/core/CompositeOmegaCallback.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 io.servicecomb.saga.alpha.core; + +import java.util.Map; + +public class CompositeOmegaCallback implements OmegaCallback { + private final Map<String, Map<String, OmegaCallback>> callbacks; + + public CompositeOmegaCallback(Map<String, Map<String, OmegaCallback>> callbacks) { + this.callbacks = callbacks; + } + + @Override + public void compensate(TxEvent event) { + Map<String, OmegaCallback> serviceCallbacks = callbacks.get(event.serviceName()); + + if (serviceCallbacks.isEmpty()) { + throw new AlphaException("No such omega callback found for service " + event.serviceName()); + } + + OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); + if (omegaCallback == null) { + serviceCallbacks.values().iterator().next().compensate(event); Review comment: there are multiple instances of the same service stored in the map, we just choose the first instance, if the matching instance is unreachable and removed from the map ---------------------------------------------------------------- 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] service/instance aware omega callback > -------------------------------------------- > > Key: SCB-149 > URL: https://issues.apache.org/jira/browse/SCB-149 > Project: Apache ServiceComb > Issue Type: Improvement > Components: Saga > Reporter: Yin Xiang > Assignee: Yin Xiang > > as a user, i want to compensate the service instance which initiated the > sub-transaction, if it's reachable from alpha, so that i can have stateful > service. > if that service instance is not reachable, other service instances are > allowed. -- This message was sent by Atlassian JIRA (v6.4.14#64029)