Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

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

Introduction

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

Prototype

Object[] getArgs();

Source Link

Usage

From source file:$.LogAspect.java

License:Apache License

/**
     * ?? ProceedingJoinPoint ?. /*from  w w  w .j  av a  2  s  .  c om*/
     * ??: ProceedingJoinPoint ???.
     * , ?
     */

    @Around("pointcutExpression()")
    public Object aroundMethod(ProceedingJoinPoint pjd) {

        Object result = null;
        String methodName = pjd.getSignature().getName();

        try {
            //?
            System.out.println("The method " + methodName + " begins with " + Arrays.asList(pjd.getArgs()));
            //
            result = pjd.proceed();
            //
            System.out.println("The method " + methodName + " ends with " + result);
        } catch (Throwable e) {
            //
            System.out.println("The method " + methodName + " occurs exception:" + e);
            throw new RuntimeException(e);
        }
        //?
        System.out.println("The method " + methodName + " ends");

        return result;
    }

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local (@at.ac.tuwien.infosys.jcloudscale.annotations.CloudObject *).new(..))")
public Object createNewCloudObject(ProceedingJoinPoint jp) throws Throwable {
    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext())
        return jp.proceed();

    Class<?> coType = jp.getSignature().getDeclaringType();
    Constructor<?> constructor = ((ConstructorSignature) jp.getSignature()).getConstructor();

    // check if this is already a CGLib modified class
    // TODO: it would be more efficient to add this to the pointcut def above
    if (CgLibUtil.isCGLibEnhancedClass(coType))
        return jp.proceed();

    return deployCloudObject(coType, jp.getArgs(), constructor);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Constructor.newInstance(..)) && target(constructor)")
public Object createNewCloudObjectViaReflection(ProceedingJoinPoint pjp, Object constructor) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    Constructor<?> constr = (Constructor<?>) constructor;
    Class<?> coType = constr.getDeclaringClass();

    // check if we are constructing some other object
    if (!coType.isAnnotationPresent(CloudObject.class))
        return pjp.proceed();

    // check if this is already a CGLib modified class
    if (CgLibUtil.isCGLibEnhancedClass(coType))
        return pjp.proceed();

    // everything checked, we should intercept this reflection call
    return deployCloudObject(coType, pjp.getArgs(), constr);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Field.get(..)) && target(field)")
public Object getCloudObjectFieldViaReflection(ProceedingJoinPoint pjp, Field field) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    // check if this field is @local
    if (field.getAnnotation(Local.class) != null)
        return pjp.proceed();

    Field theField = field;//w  w w .  j a v a  2 s .  c o  m
    Object arg = pjp.getArgs()[0];

    if (arg == null) {
        // we are getting a static field
        return pjp.proceed();
    }

    UUID id = CloudObjects.getId(arg);

    // check if we are intercepting a class we are not interested in
    if (!isCloudObjectOrParent(theField.getDeclaringClass()))
        return pjp.proceed();

    return getFieldValue(id, theField);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Field.set(..)) && target(field)")
public void setCloudObjectFieldViaReflection(ProceedingJoinPoint pjp, Field field) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext()) {
        pjp.proceed();//from  ww w.  j ava  2  s .  c o  m
        return;
    }

    Field theField = field;

    // check if this field is @local
    if (field.getAnnotation(Local.class) != null) {
        pjp.proceed();
        return;
    }

    // check if we are intercepting a class we are not interested in
    if (!isCloudObjectOrParent(theField.getDeclaringClass())) {
        pjp.proceed();
        return;
    }

    Object arg = pjp.getArgs()[0];
    Object val = pjp.getArgs()[1];

    if (arg == null) {
        // we are setting a static field
        pjp.proceed();
        return;
    }

    UUID id = CloudObjects.getId(arg);

    setFieldValue(id, theField, val);

}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("call(void at.ac.tuwien.infosys.jcloudscale.management.CloudManager.destructCloudObject(..)) && target(manager)")
public void logObjectDestructed(ProceedingJoinPoint jp, CloudManager manager) throws Throwable {

    UUID coId = (UUID) jp.getArgs()[0];
    String address = manager.getHost(coId).getIpAddress();

    jp.proceed();/*from  w  w  w  .j  a v a 2s  .co  m*/

    log.info(String.format(
            "Destructed cloud object with id %s on host %s. We now manage %d cloud objects on %d hosts.",
            coId.toString(), address, manager.countCloudObjects(), manager.countVirtualMachines()));

}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("execution(Object at.ac.tuwien.infosys.jcloudscale.management.CloudManager.invokeCloudObject(..)) && target(manager) && args(*, method, *, *)")
public Object logInvokedCloudObject(ProceedingJoinPoint jp, CloudManager manager, Method method)
        throws Throwable {

    UUID coId = (UUID) jp.getArgs()[0];
    //      Object[] args = (Object[])jp.getArgs()[2];
    String address = coId == null ? null : manager.getHost(coId).getIpAddress();
    String methodName = method.getName();

    long before = System.currentTimeMillis();
    Object ret = jp.proceed();/*from ww w .  j a  v a  2s .co m*/
    long after = System.currentTimeMillis();

    //      log.info(String.format("Invoked method %s of cloud object %s with parameters %s on host %s. Result= %s Invocation took %d ms.",
    //            methodName,
    //            coId.toString(),
    //            Arrays.toString(args),
    //            address,
    //            ret,
    //            (after - before)
    //      ));

    log.info(String.format("Invoked method %s of cloud object %s on host %s. Invocation took %d ms.",
            methodName, coId, address, (after - before)));

    return ret;
}

From source file:at.ac.tuwien.infosys.jcloudscale.server.aspects.eventing.ObjectLifecycleEventAspect.java

License:Apache License

@Around("execution(public void at.ac.tuwien.infosys.jcloudscale.server.JCloudScaleServer.destroyCloudObject(..))")
public void matchObjectDestroyed(ProceedingJoinPoint pjp) throws Throwable {

    Class<?> cloudObjectType = null;
    JCloudScaleServer server = null;//from www . j a v a2s. co  m
    UUID cloudObjectId = null;
    try {
        server = (JCloudScaleServer) pjp.getThis();
        cloudObjectId = UUID.fromString((String) (pjp.getArgs()[0]));

        Object cloudObject = server.getCloudObject(cloudObjectId);
        if (cloudObject != null)
            cloudObjectType = cloudObject.getClass();
    } catch (Exception e) {
        e.printStackTrace();
        log.severe("Error while triggering ObjectDestroyedEvent: " + e.getMessage());
    }

    pjp.proceed();

    try {
        ObjectDestroyedEvent event = new ObjectDestroyedEvent();
        initializeBaseEventProperties(event);
        // XXX AbstractJCloudScaleServerRunner
        // UUID serverId = JCloudScaleServerRunner.getInstance().getId();
        UUID serverId = AbstractJCloudScaleServerRunner.getInstance().getId();
        event.setHostId(serverId);
        event.setObjectId(cloudObjectId);
        event.setObjectType(cloudObjectType);
        getMqHelper().sendEvent(event);
        log.finer("Sent object destroyed for object " + cloudObjectId);
    } catch (Exception e) {
        e.printStackTrace();
        log.severe("Error while triggering ObjectDestroyedEvent: " + e.getMessage());
    }

}

From source file:be.nille.jwt.aspect.JWTAspect.java

private String replacePlaceholdersInExpression(final ProceedingJoinPoint joinPoint, String expression) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    Object[] args = joinPoint.getArgs();
    final Annotation[][] parameterAnnotations = method.getParameterAnnotations();

    for (int i = 0; i < parameterAnnotations.length; i++) {
        final Annotation[] annotations = parameterAnnotations[i];
        AnnotationService annotationService = new AnnotationServiceImpl();
        final ClaimValue claimAnnotation = annotationService.getAnnotationByType(annotations, ClaimValue.class);

        if (claimAnnotation != null) {
            String claimValue = claimAnnotation.value();
            String argument = (String) args[i];
            expression = expression.replace("#" + claimValue, argument);
            log.debug(claimValue);/*from w  w  w . j av  a  2  s .c o m*/
            break;
        }
    }
    return expression;
}

From source file:cn.com.xl.core.aop.BeforeAop.java

License:Apache License

@Around("cutBefore()")
public Object doBefore(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = HttpKit.getRequest();
    MethodSignature ms = (MethodSignature) point.getSignature();
    Method method = ms.getMethod();
    Object[] args = point.getArgs();
    Class<?> clazz = point.getTarget().getClass();
    Before before = method.getAnnotation(Before.class);
    Interceptor ic = before.value().newInstance();
    Object result = ic.intercept(new Invocation(clazz, method, args, request));
    if (null == result) {
        return point.proceed();
    } else {/*from   w  w  w . ja va  2 s .  c  om*/
        return result;
    }
}