Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

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

Introduction

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

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:org.apache.falcon.aspect.AbstractFalconAspect.java

License:Apache License

@Around("@annotation(org.apache.falcon.monitors.Monitored)")
public Object logAroundMonitored(ProceedingJoinPoint joinPoint) throws Throwable {

    String methodName = joinPoint.getSignature().getName();
    Object[] args = joinPoint.getArgs();
    Object result;//  w w  w . jav  a 2 s .c o  m
    ResourceMessage.Status status;

    long startTime = System.nanoTime();
    long endTime;
    try {
        result = joinPoint.proceed();
    } catch (Exception e) {
        endTime = System.nanoTime();
        status = ResourceMessage.Status.FAILED;
        publishMessage(getResourceMessage(
                joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName, args, status,
                endTime - startTime));
        throw e;
    }
    endTime = System.nanoTime();
    status = ResourceMessage.Status.SUCCEEDED;
    publishMessage(
            getResourceMessage(joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName,
                    args, status, endTime - startTime));
    return result;
}

From source file:org.apache.falcon.aspect.AbstractFalconAspect.java

License:Apache License

@Around("@annotation(org.apache.falcon.monitors.Alert)")
public Object logAroundAlert(ProceedingJoinPoint joinPoint) throws Throwable {

    String methodName = joinPoint.getSignature().getName();
    String event = ResourcesReflectionUtil.getResourceMonitorName(
            joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName);
    Object[] args = joinPoint.getArgs();
    Object result;/*from   w  w  w  .  j  a v  a 2 s .c o  m*/

    try {
        result = joinPoint.proceed();
    } finally {
        AlertMessage alertMessage = new AlertMessage(event, args[0].toString(), args[1].toString());
        publishAlert(alertMessage);
    }

    return result;
}

From source file:org.apache.ignite.compute.gridify.aop.aspectj.GridifyAspectJAspect.java

License:Apache License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//from w ww  .j  ava 2  s  .  c o  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.apache.ignite.compute.gridify.Gridify * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))")
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 IgniteCheckedException("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 IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or "
                + "Gridify.taskClass(), but not both: " + ann);
    }

    try {
        Ignite ignite = G.ignite(gridName);

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

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

        // If task name was specified.
        return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg);
    } 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.apache.ignite.compute.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java

License:Apache License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes.//w  ww . j  a va 2 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.apache.ignite.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))")
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 IgniteCheckedException("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 {
        Ignite ignite = G.ignite(gridName);

        return execute(ignite.compute(), 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.apache.ignite.compute.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java

License:Apache License

/**
 * Aspect implementation which executes grid-enabled methods on remote
 * nodes./*from   w  w w.ja  v a2s.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.apache.ignite.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))")
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 IgniteCheckedException("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 {
        Ignite ignite = G.ignite(gridName);

        return execute(mtd, ignite.compute(), 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.apache.ivory.aspect.AbstractIvoryAspect.java

License:Apache License

@Around("@annotation(org.apache.ivory.monitors.Monitored)")
public Object LogAround(ProceedingJoinPoint joinPoint) throws Throwable {

    String methodName = joinPoint.getSignature().getName();
    Object[] args = joinPoint.getArgs();
    Object result = null;// ww w. j  a v  a  2s . c  om
    ResourceMessage.Status status;

    long startTime = System.nanoTime();
    long endTime;
    try {
        result = joinPoint.proceed();
    } catch (Exception e) {
        endTime = System.nanoTime();
        status = ResourceMessage.Status.FAILED;
        publishMessage(getResourceMessage(
                joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName, args, status,
                endTime - startTime));
        throw e;
    }
    endTime = System.nanoTime();
    status = ResourceMessage.Status.SUCCEEDED;
    publishMessage(
            getResourceMessage(joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName,
                    args, status, endTime - startTime));
    return result;
}

From source file:org.apache.nifi.aop.MethodProfiler.java

License:Apache License

public Object profileMethod(final ProceedingJoinPoint call) throws Throwable {
    final long startTime = System.nanoTime();
    try {//w ww  .j a v a 2 s . c om
        return call.proceed();
    } finally {
        if (logger.isDebugEnabled()) {
            final long endTime = System.nanoTime();
            final long durationMilliseconds = (endTime - startTime) / 1000000;
            final String methodCall = call.getSignature().toLongString();
            logger.debug("'" + methodCall + "' Time to complete call (ms): " + durationMilliseconds);
        }
    }
}

From source file:org.apache.nifi.web.NiFiServiceFacadeLock.java

License:Apache License

private Object proceedWithReadLock(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final long beforeLock = System.nanoTime();
    long afterLock = 0L;

    readLock.lock();/*from w  w w.  j a va  2 s .  c o m*/
    try {
        afterLock = System.nanoTime();
        return proceedingJoinPoint.proceed();
    } finally {
        readLock.unlock();

        final long afterProcedure = System.nanoTime();
        final String procedure = proceedingJoinPoint.getSignature().toLongString();
        logger.debug(
                "In order to perform procedure {}, it took {} nanos to obtain the Read Lock {} and {} nanos to invoke the method",
                procedure, afterLock - beforeLock, readLock, afterProcedure - afterLock);
    }
}

From source file:org.apache.nifi.web.NiFiServiceFacadeLock.java

License:Apache License

private Object proceedWithWriteLock(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final long beforeLock = System.nanoTime();
    long afterLock = 0L;

    writeLock.lock();/*from   w  w w.  j  a  v a 2s  . c  om*/
    try {
        afterLock = System.nanoTime();
        return proceedingJoinPoint.proceed();
    } finally {
        writeLock.unlock();

        final long afterProcedure = System.nanoTime();
        final String procedure = proceedingJoinPoint.getSignature().toLongString();
        logger.debug(
                "In order to perform procedure {}, it took {} nanos to obtain the Write Lock {} and {} nanos to invoke the method",
                procedure, afterLock - beforeLock, writeLock, afterProcedure - afterLock);
    }
}

From source file:org.apache.rave.synchronization.SynchronizingAspect.java

License:Apache License

@Around("synchronizePointcut()")
public Object synchronizeInvocation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
    Method method = methodSignature.getMethod();
    Object target = proceedingJoinPoint.getTarget();
    Object[] args = proceedingJoinPoint.getArgs();
    Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
    Synchronized annotation = getAnnotation(targetClass, method);
    Validate.notNull(annotation, "Could not find @Synchronized annotation!");

    Lock lock = getLock(targetClass, method, args, annotation);
    if (lock == null) {
        logger.debug(/*from  ww  w  .j a va  2 s .  c  om*/
                "No lock obtained for call [{}] on targetClass [{}] - proceeding without synchronization on "
                        + "thread {}",
                new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() });
        return proceedingJoinPoint.proceed();
    } else {
        try {
            logger.debug(
                    "Lock obtained for call [{}] on targetClass [{}] - proceeding with synchronization on thread {}",
                    new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() });
            lock.lock();
            return proceedingJoinPoint.proceed();
        } finally {
            lock.unlock();
            lockService.returnLock(lock);
        }
    }
}