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.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.flockdata.spring.annotations.FlockDataAspect.java

License:Open Source License

@Around(value = "@annotation(annotation)")
public void createEntity(final ProceedingJoinPoint joinPoint, final FlockEntity annotation) throws Throwable {
    try {//from   w  w  w. ja v a 2 s .c  o  m
        logger.debug("createEntity() is running!");
        logger.debug("hijacked method : {}", joinPoint.getSignature().getName());
        logger.debug("hijacked arguments : {}", Arrays.toString(joinPoint.getArgs()));
        joinPoint.proceed();
        logger.debug("Around before is running!\r\n");
        joinPoint.proceed(); //continue on the intercepted method
    } finally {
        logger.info("Around after is running!");
    }
}

From source file:org.flockdata.spring.annotations.FlockDataAspect.java

License:Open Source License

@Around(value = "@annotation(annotation)")
public void createEntityLog(final ProceedingJoinPoint joinPoint, final FlockLog annotation) throws Throwable {
    try {/*from  w  ww  .  j  a v a  2 s .c  o  m*/
        logger.debug("createAuditLog() is running!");
        logger.debug("hijacked method : {}", joinPoint.getSignature().getName());
        logger.debug("hijacked arguments : {}", Arrays.toString(joinPoint.getArgs()));
        joinPoint.proceed();
        logger.debug("Around before is running!\r\n");
        joinPoint.proceed(); //continue on the intercepted method
    } finally {
        logger.debug("Around after is running!");
    }
}

From source file:org.geosdi.geoplatform.cas.aop.SecurityCASAOP.java

License:Open Source License

@Around("execution(* it.geosolutions.geoserver.rest.GeoServerRESTReader.*(..))")
public Object adviceGeoServerRestReader(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    logger.info("#########################AOP GeoServerRESTReader.*(..) is running...");
    Assertion receivedAssertion = this.retrieveAssertion();
    Object[] parameters = proceedingJoinPoint.getArgs();
    Class[] types = new Class[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        Object object = parameters[i];
        types[i] = object.getClass();/*w  w w  . j  a v a  2 s .c o m*/
        logger.info("##########################Parameter type: {}\n", object.getClass());
    }
    casRestReader.setCasAssertion(receivedAssertion);
    try {
        Method method = GeoServerCASRESTReader.class.getMethod(proceedingJoinPoint.getSignature().getName(),
                types);
        method.setAccessible(Boolean.TRUE);
        return method.invoke(this.casRestReader, proceedingJoinPoint.getArgs());
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException(e.getMessage());
    }
}

From source file:org.geosdi.geoplatform.cas.aop.SecurityCASAOP.java

License:Open Source License

@Around("execution(* it.geosolutions.geoserver.rest.GeoServerRESTPublisher.*(..))")
public Object adviceGeoServerRESTPublisher(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    logger.info("AOP GeoServerRESTPublisher.*(..) is running...");
    Assertion receivedAssertion = this.retrieveAssertion();
    CASHTTPUtils.setCasAssertion(receivedAssertion);
    Object[] parameters = proceedingJoinPoint.getArgs();
    Class[] types = new Class[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        Object object = parameters[i];
        types[i] = object.getClass();/*from ww w .  j a  va  2 s  . c  om*/
        logger.info("Parameter type: " + object.getClass());
    }

    try {
        Method method = GeoServerCASRESTPublisher.class.getMethod(proceedingJoinPoint.getSignature().getName(),
                types);
        method.setAccessible(Boolean.TRUE);
        return method.invoke(this.casRestPublisher, proceedingJoinPoint.getArgs());
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException(e.getMessage());
    }
}

From source file:org.geosdi.geoplatform.cas.aop.SecurityCASAOP.java

License:Open Source License

@Around("execution(* it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager.*(..))")
public Object adviceGeoServerRESTStoreManager(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    logger.info("AOP GeoServerRESTStoreManager.*(..) is running...");
    Assertion receivedAssertion = this.retrieveAssertion();
    CASHTTPUtils.setCasAssertion(receivedAssertion);
    Object[] parameters = proceedingJoinPoint.getArgs();
    Class[] types = new Class[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        Object object = parameters[i];
        types[i] = object.getClass();/*ww  w. j  a va 2s.c om*/
        logger.debug("REST Store Parameter type: " + object.getClass());
    }

    try {
        Method method = GeoServerCASRESTStoreManager.class
                .getMethod(proceedingJoinPoint.getSignature().getName(), types);
        method.setAccessible(Boolean.TRUE);
        logger.info("After REST Store Manager Method");
        return method.invoke(this.casRestStoreManager, proceedingJoinPoint.getArgs());
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException(e.getMessage());
    }
}

From source file:org.grazy.experimental.graspectj.MethodLogger.java

License:Apache License

@Around("execution(* *(..)) && @annotation(Loggable)")
public Object around(ProceedingJoinPoint point) {
    long start = System.currentTimeMillis();
    Object result;//from ww  w.  ja v  a 2s. c o  m
    try {
        result = point.proceed();

        logger.log(Level.INFO, "source location: {0}", point.getSourceLocation().toString());
        logger.log(Level.INFO, "#%s(%s): %s in %[msec]s{0}{1}{2}{3}",
                new Object[] { MethodSignature.class.cast(point.getSignature()).getMethod().getName(),
                        point.getArgs(), result, System.currentTimeMillis() - start });
        return result;
    } catch (Throwable ex) {
        Logger.getLogger(MethodLogger.class.getName()).log(Level.SEVERE, null, ex);
    }
    throw new RuntimeException("ma non scassare la minchia");
}

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.//w w  w  . j  a v  a 2 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./* www. ja v a 2  s  . com*/
 *
 * @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./*w w  w  . j a  v  a2s.c o  m*/
 *
 * @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);
    }
}