[ https://issues.apache.org/jira/browse/SCB-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16310836#comment-16310836 ]
ASF GitHub Bot commented on SCB-100: ------------------------------------ WillemJiang commented on a change in pull request #100: [SCB-100] async support URL: https://github.com/apache/incubator-servicecomb-saga/pull/100#discussion_r159586912 ########## File path: omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/ExecutorFieldCallback.java ########## @@ -0,0 +1,167 @@ +/* + * 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.spring; + +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Collection; +import java.util.concurrent.Callable; +import java.util.concurrent.Executor; +import java.util.stream.Collectors; + +import org.apache.servicecomb.saga.omega.context.OmegaContext; +import org.apache.servicecomb.saga.omega.transaction.spring.annotations.OmegaContextAware; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ReflectionUtils; +import org.springframework.util.ReflectionUtils.FieldCallback; + +class ExecutorFieldCallback implements FieldCallback { + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private final OmegaContext omegaContext; + private final Object bean; + + ExecutorFieldCallback(Object bean, OmegaContext omegaContext) { + this.omegaContext = omegaContext; + this.bean = bean; + } + + @Override + public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { + if (!field.isAnnotationPresent(OmegaContextAware.class)) { + return; + } + + ReflectionUtils.makeAccessible(field); + + Class<?> generic = field.getType(); + + if (!Executor.class.isAssignableFrom(generic)) { + throw new IllegalArgumentException( + "Only Executor, ExecutorService, and ScheduledExecutorService are supported for @" + + OmegaContextAware.class.getSimpleName()); + } + + field.set(bean, ExecutorProxy.newInstance(field.get(bean), field.getType(), omegaContext)); + } + + private static class RunnableProxy implements InvocationHandler { + + private final String globalTxId; + private final String localTxId; + private final String parentTxId; + private final Object runnable; Review comment: If it is Runnable, we can just treat it as Runnable. ---------------------------------------------------------------- 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] async transaction support > -------------------------------- > > Key: SCB-100 > URL: https://issues.apache.org/jira/browse/SCB-100 > Project: Apache ServiceComb > Issue Type: New Feature > Components: Saga > Reporter: Yin Xiang > Assignee: Yin Xiang > Fix For: saga-0.1.0 > > > as a dev, i want to be able to execute sub-transaction in a separate thread, > so that my service call is not blocked. -- This message was sent by Atlassian JIRA (v6.4.14#64029)