Commit b0ec2071 authored by 吴晟's avatar 吴晟
Browse files

Merge branch 'master' into 5.x

parents 3afe0215 a99733bf
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -35,7 +35,20 @@ public class HystrixConcurrencyStrategyInterceptor implements InstanceMethodsAro
    @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                              Object ret) throws Throwable {
        return new SWHystrixConcurrencyStrategyWrapper((HystrixConcurrencyStrategy)ret);
        SWHystrixPluginsWrapperCache wrapperCache = (SWHystrixPluginsWrapperCache) objInst.getSkyWalkingDynamicField();
        if (wrapperCache == null || wrapperCache.getSwHystrixConcurrencyStrategyWrapper() == null) {
            synchronized (objInst) {
                if (wrapperCache == null) {
                    wrapperCache = new SWHystrixPluginsWrapperCache();
                    objInst.setSkyWalkingDynamicField(wrapperCache);
                }
                if (wrapperCache.getSwHystrixConcurrencyStrategyWrapper() == null) {
                    wrapperCache.setSwHystrixConcurrencyStrategyWrapper(new SWHystrixConcurrencyStrategyWrapper((HystrixConcurrencyStrategy) ret));
                }
            }
        }

        return wrapperCache.getSwHystrixConcurrencyStrategyWrapper();
    }

    @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+14 −1
Original line number Diff line number Diff line
@@ -40,7 +40,20 @@ public class HystrixPluginsInterceptor implements InstanceMethodsAroundIntercept
    @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret) throws Throwable {
        return new SWExecutionHookWrapper((HystrixCommandExecutionHook)ret);
        SWHystrixPluginsWrapperCache wrapperCache = (SWHystrixPluginsWrapperCache) objInst.getSkyWalkingDynamicField();
        if (wrapperCache == null || wrapperCache.getSwExecutionHookWrapper() == null) {
            synchronized (objInst) {
                if (wrapperCache == null) {
                    wrapperCache = new SWHystrixPluginsWrapperCache();
                    objInst.setSkyWalkingDynamicField(wrapperCache);
                }
                if (wrapperCache.getSwExecutionHookWrapper() == null) {
                    wrapperCache.setSwExecutionHookWrapper(new SWExecutionHookWrapper((HystrixCommandExecutionHook) ret));
                }
            }
        }

        return wrapperCache.getSwExecutionHookWrapper();
    }

    @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+4 −1
Original line number Diff line number Diff line
@@ -36,7 +36,10 @@ public class SWHystrixConcurrencyStrategyWrapper extends HystrixConcurrencyStrat

    @Override
    public <T> Callable<T> wrapCallable(Callable<T> callable) {
        return new WrappedCallable<T>(ContextManager.getRuntimeContext().capture(), super.wrapCallable(callable));
        Callable<T> delegateCallable = delegate != null
                ? delegate.wrapCallable(callable)
                : super.wrapCallable(callable);
        return new WrappedCallable<T>(ContextManager.getRuntimeContext().capture(), delegateCallable);
    }

    static class WrappedCallable<T> implements Callable<T> {
+46 −0
Original line number Diff line number Diff line
/*
 * 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.skywalking.apm.plugin.hystrix.v1;

/**
 * {@link SWHystrixPluginsWrapperCache} record the {@link SWExecutionHookWrapper} and {@link SWHystrixConcurrencyStrategyWrapper} object for
 * storing in EnhancedInstance#dynamicField together.
 *
 * @author chenpengfei
 */
public class SWHystrixPluginsWrapperCache {
    private volatile SWExecutionHookWrapper swExecutionHookWrapper;
    private volatile SWHystrixConcurrencyStrategyWrapper swHystrixConcurrencyStrategyWrapper;

    public SWExecutionHookWrapper getSwExecutionHookWrapper() {
        return swExecutionHookWrapper;
    }

    public void setSwExecutionHookWrapper(SWExecutionHookWrapper swExecutionHookWrapper) {
        this.swExecutionHookWrapper = swExecutionHookWrapper;
    }

    public SWHystrixConcurrencyStrategyWrapper getSwHystrixConcurrencyStrategyWrapper() {
        return swHystrixConcurrencyStrategyWrapper;
    }

    public void setSwHystrixConcurrencyStrategyWrapper(SWHystrixConcurrencyStrategyWrapper swHystrixConcurrencyStrategyWrapper) {
        this.swHystrixConcurrencyStrategyWrapper = swHystrixConcurrencyStrategyWrapper;
    }
}