Example usage for org.aspectj.lang ProceedingJoinPoint getTarget

List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getTarget.

Prototype

Object getTarget();

Source Link

Document

Returns the target object.

Usage

From source file:org.fishwife.jrugged.aspects.PerformanceMonitorAspect.java

License:Apache License

/**
 * Wraps a method annotated with the {@link org.fishwife.jrugged.PerformanceMonitor} annotation
 * with a {@link org.fishwife.jrugged.PerformanceMonitor}.
 * //  w ww  .  ja v a2 s.c  o m
 * @param pjp Represents the method that is being executed.
 * @param performanceMonitorAnnotation The PerformanceMonitor annotation
 * associated with the method being execute.
 * @return Value returned by the method that is being wrapped.
 * @throws Throwable Whatever the wrapped method throws will be thrown by
 * this method.
 */
@Around("@annotation(performanceMonitorAnnotation)")
public Object monitor(final ProceedingJoinPoint pjp, PerformanceMonitor performanceMonitorAnnotation)
        throws Throwable {
    String monitorName = performanceMonitorAnnotation.value();

    if (logger.isDebugEnabled()) {
        logger.debug(
                "Have @PerformanceMonitor method with monitor name {}, "
                        + "wrapping call on method {} of target object {}",
                new Object[] { monitorName, pjp.getSignature().getName(), pjp.getTarget() });
    }

    org.fishwife.jrugged.PerformanceMonitor performanceMonitor = performanceMonitorFactory
            .findPerformanceMonitor(monitorName);

    if (performanceMonitor == null) {
        performanceMonitor = performanceMonitorFactory.createPerformanceMonitor(monitorName);
    }

    return performanceMonitor.invoke(new Callable<Object>() {
        public Object call() throws Exception {
            Object retval;
            try {
                retval = pjp.proceed();
            } catch (Throwable e) {
                if (e instanceof Exception) {
                    throw (Exception) e;
                } else {
                    throw (Error) e;
                }
            }
            return retval;
        }
    });
}

From source file:org.fishwife.jrugged.aspects.RetryableAspect.java

License:Apache License

/**
 * Runs a method call with retries./*from w w w  .j  a  v  a 2s  .  co m*/
 * @param pjp a {@link ProceedingJoinPoint} representing an annotated
 *            method call.
 * @param retryableAnnotation the {@link org.fishwife.jrugged.aspects.Retryable}
 *                            annotation that wrapped the method.
 * @throws Throwable if the method invocation itself throws one during execution.
 * @return The return value from the method call.
 */
@Around("@annotation(retryableAnnotation)")
public Object call(final ProceedingJoinPoint pjp, Retryable retryableAnnotation) throws Throwable {
    final int maxTries = retryableAnnotation.maxTries();
    final int retryDelayMillies = retryableAnnotation.retryDelayMillis();
    final Class<? extends Throwable>[] retryOn = retryableAnnotation.retryOn();
    final boolean doubleDelay = retryableAnnotation.doubleDelay();
    final boolean throwCauseException = retryableAnnotation.throwCauseException();

    if (logger.isDebugEnabled()) {
        logger.debug("Have @Retryable method wrapping call on method {} of target object {}",
                new Object[] { pjp.getSignature().getName(), pjp.getTarget() });
    }

    ServiceRetrier serviceRetrier = new ServiceRetrier(retryDelayMillies, maxTries, doubleDelay,
            throwCauseException, retryOn);

    return serviceRetrier.invoke(new Callable<Object>() {
        public Object call() throws Exception {
            try {
                return pjp.proceed();
            } catch (Exception e) {
                throw e;
            } catch (Error e) {
                throw e;
            } catch (Throwable t) {
                throw new RuntimeException(t);
            }
        }
    });
}

From source file:org.fishwife.jrugged.aspects.TestCircuitBreakerAspect.java

License:Apache License

private static ProceedingJoinPoint createPjpMock(Signature mockSignature, int times) {
    ProceedingJoinPoint mockPjp = createMock(ProceedingJoinPoint.class);
    // XXX: the following two interactions are for logging, so they may happen
    //      0 or n times, pending logging configuration
    expect(mockPjp.getTarget()).andReturn("Target").times(0, times);
    expect(mockPjp.getSignature()).andReturn(mockSignature).times(0, times);
    return mockPjp;
}

From source file:org.fishwife.jrugged.aspects.TestRetryableAspect.java

License:Apache License

private static ProceedingJoinPoint createPjpMock(Signature mockSignature) {
    ProceedingJoinPoint mockPjp = createMock(ProceedingJoinPoint.class);
    // XXX: the following two interactions are for logging, so they may happen
    //      0 or n times, pending logging configuration
    expect(mockPjp.getTarget()).andReturn("Target").times(0, 1);
    expect(mockPjp.getSignature()).andReturn(mockSignature).times(0, 1);
    return mockPjp;
}

From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifyAspectJAspect.java

License:Open Source License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//from w  w  w .  j  a  v a2 s . co m
 *
 * @param joinPnt Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass",
        "unchecked" })
@Around("execution(@org.gridgain.grid.compute.gridify.Gridify * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable {
    Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod();

    Gridify ann = mtd.getAnnotation(Gridify.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED)
        throw new GridException("Grid is not locally started: " + gridName);

    // Initialize defaults.
    GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getParameterTypes(), joinPnt.getArgs(), joinPnt.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg))
            return joinPnt.proceed();
    }

    if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) {
        throw new GridException("Gridify annotation must specify either Gridify.taskName() or "
                + "Gridify.taskClass(), but not both: " + ann);
    }

    try {
        Grid grid = G.grid(gridName);

        // If task class was specified.
        if (!ann.taskClass().equals(GridifyDefaultTask.class)) {
            return grid.compute().withTimeout(ann.timeout())
                    .execute((Class<? extends GridComputeTask<GridifyArgument, Object>>) ann.taskClass(), arg)
                    .get();
        }

        // If task name was not specified.
        if (ann.taskName().isEmpty()) {
            return grid.compute().withTimeout(ann.timeout())
                    .execute(new GridifyDefaultTask(joinPnt.getSignature().getDeclaringType()), arg).get();
        }

        // If task name was specified.
        return grid.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg).get();
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass()))
                    throw cause;

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass()))
                throw e;
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}

From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java

License:Open Source License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes./*from  w  w  w . j ava2  s.  c om*/
 *
 * @param joinPnt Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" })
@Around("execution(@org.gridgain.grid.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable {
    Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod();

    GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED)
        throw new GridException("Grid is not locally started: " + gridName);

    GridifyNodeFilter nodeFilter = null;

    if (!ann.nodeFilter().equals(GridifyNodeFilter.class))
        nodeFilter = ann.nodeFilter().newInstance();

    // Check method return type.
    checkMethodSignature(mtd);

    GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder();

    // Creates task argument.
    GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPnt.getArgs(),
            joinPnt.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg))
            return joinPnt.proceed();
    }

    // Proceed locally for negative threshold parameter.
    if (ann.threshold() < 0)
        return joinPnt.proceed();

    // Analyse where to execute method (remotely or locally).
    if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold())
        return joinPnt.proceed();

    // Check is split to jobs allowed for input method argument with declared splitSize.
    checkIsSplitToJobsAllowed(arg, ann);

    try {
        Grid grid = G.grid(gridName);

        return execute(grid, joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(),
                ann.splitSize(), ann.timeout());
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass()))
                    throw cause;

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass()))
                throw e;
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}

From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java

License:Open Source License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//ww  w.ja v  a 2s .  c om
 *
 * @param joinPnt Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" })
@Around("execution(@org.gridgain.grid.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable {
    Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod();

    GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED)
        throw new GridException("Grid is not locally started: " + gridName);

    GridifyNodeFilter nodeFilter = null;

    if (!ann.nodeFilter().equals(GridifyNodeFilter.class))
        nodeFilter = ann.nodeFilter().newInstance();

    // Check is method allowed for gridify.
    checkMethodSignature(mtd);

    GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder();

    // Creates task argument.
    GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPnt.getArgs(),
            joinPnt.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg))
            return joinPnt.proceed();
    }

    // Proceed locally for negative threshold parameter.
    if (ann.threshold() < 0)
        return joinPnt.proceed();

    // Analyse where to execute method (remotely or locally).
    if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold())
        return joinPnt.proceed();

    // Check is split to jobs allowed for input method argument with declared splitSize.
    checkIsSplitToJobsAllowed(arg, ann);

    try {
        Grid grid = G.grid(gridName);

        return execute(mtd, grid, joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(),
                ann.splitSize(), ann.timeout());
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass()))
                    throw cause;

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass()))
                throw e;
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}

From source file:org.gridgain.grid.gridify.aop.aspectj.GridifyAspectJAspect.java

License:GNU General Public License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes./*from ww  w . ja  va 2s. c o m*/
 *
 * @param joinPoint Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass",
        "unchecked" })
@Around("execution(@org.gridgain.grid.gridify.Gridify * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable {
    Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod();

    Gridify ann = mtd.getAnnotation(Gridify.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED) {
        throw new GridException("Grid is not locally started: " + gridName);
    }

    // Initialize defaults.
    GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getParameterTypes(), joinPoint.getArgs(), joinPoint.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg)) {
            return joinPoint.proceed();
        }
    }

    if (!ann.taskClass().equals(GridifyDefaultTask.class) && ann.taskName().length() > 0) {
        throw new GridException("Gridify annotation must specify either Gridify.taskName() or "
                + "Gridify.taskClass(), but not both: " + ann);
    }

    try {
        Grid grid = G.grid(gridName);

        // If task class was specified.
        if (!ann.taskClass().equals(GridifyDefaultTask.class)) {
            return grid.execute((Class<? extends GridTask<GridifyArgument, Object>>) ann.taskClass(), arg,
                    ann.timeout()).get();
        }

        // If task name was not specified.
        if (ann.taskName().length() == 0) {
            return grid.execute(new GridifyDefaultTask(joinPoint.getSignature().getDeclaringType()), arg,
                    ann.timeout()).get();
        }

        // If task name was specified.
        return grid.execute(ann.taskName(), arg, ann.timeout()).get();
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass())) {
                    throw cause;
                }

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass())) {
                throw e;
            }
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}

From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java

License:GNU General Public License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//from   w  w w.ja v a  2  s .  co  m
 *
 * @param joinPoint Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" })
@Around("execution(@org.gridgain.grid.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable {
    Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod();

    GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED)
        throw new GridException("Grid is not locally started: " + gridName);

    GridifyNodeFilter nodeFilter = null;

    if (!ann.nodeFilter().equals(GridifyNodeFilter.class))
        nodeFilter = ann.nodeFilter().newInstance();

    // Check method return type.
    checkMethodSignature(mtd);

    GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder();

    // Creates task argument.
    GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(),
            joinPoint.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg))
            return joinPoint.proceed();
    }

    // Proceed locally for negative threshold parameter.
    if (ann.threshold() < 0)
        return joinPoint.proceed();

    // Analyse where to execute method (remotely or locally).
    if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold())
        return joinPoint.proceed();

    // Check is split to jobs allowed for input method argument with declared splitSize.
    checkIsSplitToJobsAllowed(arg, ann);

    try {
        Grid grid = G.grid(gridName);

        return execute(grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(),
                ann.splitSize(), ann.timeout());
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass()))
                    throw cause;

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass()))
                throw e;
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}

From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java

License:GNU General Public License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//from  w ww. ja v a  2  s . c  om
 *
 * @param joinPoint Join point provided by AspectJ AOP.
 * @return Method execution result.
 * @throws Throwable If execution failed.
 */
@SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" })
@Around("execution(@org.gridgain.grid.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))")
public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable {
    Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod();

    GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class);

    assert ann != null : "Intercepted method does not have gridify annotation.";

    // Since annotations in Java don't allow 'null' as default value
    // we have accept an empty string and convert it here.
    // NOTE: there's unintended behavior when user specifies an empty
    // string as intended grid name.
    // NOTE: the 'ann.gridName() == null' check is added to mitigate
    // annotation bugs in some scripting languages (e.g. Groovy).
    String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName();

    if (G.state(gridName) != STARTED)
        throw new GridException("Grid is not locally started: " + gridName);

    GridifyNodeFilter nodeFilter = null;

    if (!ann.nodeFilter().equals(GridifyNodeFilter.class))
        nodeFilter = ann.nodeFilter().newInstance();

    // Check is method allowed for gridify.
    checkMethodSignature(mtd);

    GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder();

    // Creates task argument.
    GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(),
            mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(),
            joinPoint.getTarget());

    if (!ann.interceptor().equals(GridifyInterceptor.class)) {
        // Check interceptor first.
        if (!ann.interceptor().newInstance().isGridify(ann, arg)) {
            return joinPoint.proceed();
        }
    }

    // Proceed locally for negative threshold parameter.
    if (ann.threshold() < 0)
        return joinPoint.proceed();

    // Analyse where to execute method (remotely or locally).
    if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold())
        return joinPoint.proceed();

    // Check is split to jobs allowed for input method argument with declared splitSize.
    checkIsSplitToJobsAllowed(arg, ann);

    try {
        Grid grid = G.grid(gridName);

        return execute(mtd, grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(),
                ann.splitSize(), ann.timeout());
    } catch (Throwable e) {
        for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) {
            // Descend all levels down.
            Throwable cause = e.getCause();

            while (cause != null) {
                if (ex.isAssignableFrom(cause.getClass()))
                    throw cause;

                cause = cause.getCause();
            }

            if (ex.isAssignableFrom(e.getClass()))
                throw e;
        }

        throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e);
    }
}