Search in sources :

Example 1 with InterceptorScopeInvocation

use of com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation in project LinkAgent by shulieTech.

the class ScopedResultInterceptor method getResult.

@Override
public Object getResult(Advice advice) throws Throwable {
    final InterceptorScopeInvocation transaction = getScope(advice).getCurrentInvocation();
    Object result = advice.getReturnObj();
    try {
        final boolean success = transaction.tryEnter(policy);
        if (success) {
            return interceptor.getResult(advice);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("tryAfter() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
            }
        }
    } finally {
        if (transaction.canLeave(policy)) {
            transaction.leave(policy);
        }
    }
    return result;
}
Also used : InterceptorScopeInvocation(com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation)

Example 2 with InterceptorScopeInvocation

use of com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation in project LinkAgent by shulieTech.

the class ScopedAroundInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    final InterceptorScope scope = getScope(advice);
    final InterceptorScopeInvocation transaction = scope.getCurrentInvocation();
    boolean success = transaction.canLeave(policy);
    try {
        if (success) {
            interceptor.doAfter(advice);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("tryAfter() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
            }
        }
    } finally {
        if (success) {
            transaction.leave(policy);
        }
    }
}
Also used : InterceptorScopeInvocation(com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation) InterceptorScope(com.shulie.instrument.simulator.api.scope.InterceptorScope)

Example 3 with InterceptorScopeInvocation

use of com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation in project LinkAgent by shulieTech.

the class ScopedAroundInterceptor method doException.

@Override
public void doException(Advice advice) throws Throwable {
    final InterceptorScopeInvocation transaction = getScope(advice).getCurrentInvocation();
    boolean success = transaction.canLeave(policy);
    try {
        if (success) {
            interceptor.doException(advice);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("doException() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
            }
        }
    } finally {
        if (success) {
            transaction.leave(policy);
        }
    }
}
Also used : InterceptorScopeInvocation(com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation)

Example 4 with InterceptorScopeInvocation

use of com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation in project LinkAgent by shulieTech.

the class ScopedAroundInterceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    final InterceptorScope scope = getScope(advice);
    final InterceptorScopeInvocation transaction = scope.getCurrentInvocation();
    final boolean success = transaction.tryEnter(policy);
    if (success) {
        interceptor.doBefore(advice);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("tryBefore() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
        }
    }
}
Also used : InterceptorScopeInvocation(com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation) InterceptorScope(com.shulie.instrument.simulator.api.scope.InterceptorScope)

Example 5 with InterceptorScopeInvocation

use of com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation in project LinkAgent by shulieTech.

the class ScopedCutoffInterceptor method cutoff.

@Override
public CutOffResult cutoff(Advice advice) throws Throwable {
    final InterceptorScopeInvocation transaction = getScope(advice).getCurrentInvocation();
    CutOffResult result = CutOffResult.passed();
    try {
        final boolean success = transaction.tryEnter(policy);
        if (success) {
            return interceptor.cutoff(advice);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("tryBefore() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
            }
        }
    } finally {
        if (transaction.canLeave(policy)) {
            transaction.leave(policy);
        }
    }
    return result;
}
Also used : InterceptorScopeInvocation(com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation) CutOffResult(com.pamirs.pradar.CutOffResult)

Aggregations

InterceptorScopeInvocation (com.shulie.instrument.simulator.api.scope.InterceptorScopeInvocation)12 InterceptorScope (com.shulie.instrument.simulator.api.scope.InterceptorScope)2 CutOffResult (com.pamirs.pradar.CutOffResult)1 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)1