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:$.BizAspect.java

License:Open Source License

/**
     * .//from  w w  w.ja  va 2s  .c om
     * 
     * @param jionpoint
     * @return
     * @throws Throwable
     */
    @Around("bizPointcut() &&  @annotation(aspectLogger)")
    public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
        /*
         * .
         */
        long l1 = System.currentTimeMillis();

        /*
         * ??.
         */
        String desc = aspectLogger.value();
        /*
         * ??.
         */
        //boolean discover = aspectLogger.discover();

        /*
         * ???.  
         */
        String targetMethodName = jionpoint.getSignature().getName();
        /*
         * ???.
         */
        String targetClassName = jionpoint.getTarget().getClass().getName();
        /*
         * ?.
         */
        Object o = jionpoint.proceed();
        /*
         * ?.
         */
        long l2 = System.currentTimeMillis();
        /*
         * ?.
         */
        StringBuilder aspectMessage = new StringBuilder();

        aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
                .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)")
                .append(",?()");

        /*
         * .
         */
        logger.info(aspectMessage.toString());

        //Object o = jionpoint.proceed();//???  
        return o;
    }

From source file:$.CommonAspect.java

License:Open Source License

/**
     * .//  www  . j a  va  2s .c o m
     * 
     * @param jionpoint
     * @return
     * @throws Throwable
     */
    @Around("commonPointcut() &&  @annotation(aspectLogger)")
    public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
        /*
         * .
         */
        long l1 = System.currentTimeMillis();
        /*
         * ??.
         */
        String desc = aspectLogger.value();
        /*
         * ???.  
         */
        String targetMethodName = jionpoint.getSignature().getName();
        /*
         * ???.
         */
        String targetClassName = jionpoint.getTarget().getClass().getName();
        /*
         * ?.
         */
        Object o = jionpoint.proceed();
        /*
         * ?.
         */
        long l2 = System.currentTimeMillis();
        /*
         * ?.
         */
        StringBuilder aspectMessage = new StringBuilder();

        aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
                .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)")
                .append(",?()");

        /*
         * .
         */
        logger.info(aspectMessage.toString());

        //Object o = jionpoint.proceed();//???  
        return o;
    }

From source file:$.CoreAspect.java

License:Open Source License

/**
     * .//ww w  .ja v a  2s  .com
     * 
     * @param jionpoint
     * @return
     * @throws Throwable
     */
    @Around("corePointcut() &&  @annotation(aspectLogger)")
    public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
        /*
         * .
         */
        long l1 = System.currentTimeMillis();
        /*
         * ??.
         */
        String desc = aspectLogger.value();
        /*
         * ???.  
         */
        String targetMethodName = jionpoint.getSignature().getName();
        /*
         * ???.
         */
        String targetClassName = jionpoint.getTarget().getClass().getName();
        /*
         * ?.
         */
        Object o = jionpoint.proceed();
        /*
         * ?.
         */
        long l2 = System.currentTimeMillis();
        /*
         * ?.
         */
        StringBuilder aspectMessage = new StringBuilder();

        aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
                .append(".").append(targetMethodName).append("),(").append(l2 - l1).append("ms)")
                .append(",?()");

        /*
         * .
         */
        logger.info(aspectMessage.toString());

        //Object o = jionpoint.proceed();//???  
        return o;
    }

From source file:$.LogAspect.java

License:Apache License

/**
     * ?? ProceedingJoinPoint ?. //from   w w  w.  j av a  2s .c  o  m
     * ??: 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:ajia.monitoring.AbstractPerformanceMonitoringAspect.java

License:Apache License

@Around("monitoredOp()&& !within(AbstractPerformanceMonitoringAspect)")
public Object monitor(ProceedingJoinPoint pjp) throws Throwable {
    if (!isEnabled()) {
        return pjp.proceed();
    }/*from   www.j av a 2s  .c om*/
    long start = System.nanoTime();
    try {
        return pjp.proceed();
    } finally {
        long complete = System.nanoTime();
        logger.log(Level.INFO, "Operation " + pjp.getSignature().toShortString() + " took " + (complete - start)
                + " nanoseconds");
    }
}

From source file:anza.stock.utils.AspectLogger.java

@Around("controller()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {

    long start = System.currentTimeMillis();
    try {//from   w  w w.j a v a2  s  .c  om
        String className = joinPoint.getSignature().getDeclaringTypeName();
        String methodName = joinPoint.getSignature().getName();
        Object result = joinPoint.proceed();
        long elapsedTime = System.currentTimeMillis() - start;
        System.out.println("Hello from aspect");

        return result;
    } catch (IllegalArgumentException e) {

        throw e;
    }
}

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("target(object) && "
        + "(get(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObject *.*) || "
        + " get(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObjectParent *.*))")
public Object getCloudObjectField(Object object, ProceedingJoinPoint pjp) throws Throwable {

    // // ww  w  . j  av a 2s .  c o m

    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    UUID id = CloudObjects.getId(object);

    if (id == null) {
        // maybe we are just working on a cloudobjectparent that is not actually a cloud object
        return pjp.proceed();
    }

    FieldSignature sig = (FieldSignature) pjp.getSignature();
    Field field = sig.getField();

    return getFieldValue(id, field);

}

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

License:Apache License

@Around("target(object) && args(val) && "
        + "(set(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObject *.*) || "
        + " set(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObjectParent *.*))")
public void setCloudObjectField(Object object, Object val, ProceedingJoinPoint pjp) throws Throwable {

    if (JCloudScaleConfiguration.isServerContext()) {
        pjp.proceed();/*from  ww  w.ja  va 2  s  .co  m*/
        return;
    }

    UUID id = CloudObjects.getId(object);

    if (id == null) {
        // maybe we are just working on a cloudobjectparent that is not actually a cloud object
        pjp.proceed();
        return;
    }

    if (CloudObjects.isDestroyed(id)) {
        // throw new JCloudScaleException("Field access on already destroyed CloudObject!");
        // this case happens during regular object construction - just proceed
        pjp.proceed();
        return;
    }

    FieldSignature sig = (FieldSignature) pjp.getSignature();
    Field field = sig.getField();

    setFieldValue(id, field, val);

}

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

License:Apache License

@Around("args(newval) && set(@at.ac.tuwien.infosys.jcloudscale.annotations.CloudGlobal static * *.*)")
public void writeStaticValueToClient(ProceedingJoinPoint pjp, Object newval) throws Throwable {

    if (!JCloudScaleConfiguration.isServerContext()) {
        pjp.proceed();//  w  ww. j  a  v a 2 s.com
        return;
    }

    try (IMQWrapper mq = JCloudScaleConfiguration.createMQWrapper()) {
        UUID corrId = UUID.randomUUID();

        FieldSignature sig = (FieldSignature) pjp.getSignature();
        Field field = sig.getField();

        Object newValProcessed = JCloudScaleReferenceManager.getInstance().processField(field, newval);
        byte[] serialzed = SerializationUtil.serializeToByteArray(newValProcessed);

        SetStaticValueRequest req = new SetStaticValueRequest();
        req.setField(field.getName());
        req.setClassName(field.getDeclaringClass().getCanonicalName());
        req.setValue(serialzed);

        mq.createQueueProducer(
                JCloudScaleConfiguration.getConfiguration().server().getStaticFieldWriteRequestQueueName());
        mq.createTopicConsumer(
                JCloudScaleConfiguration.getConfiguration().server().getStaticFieldWriteResponseTopicName(),
                "JMSCorrelationID = '" + corrId.toString() + "'");

        // we send request and wait for response to ensure that we in fact 
        // changed the value before continuing. 
        mq.requestResponse(req, corrId);

    } catch (JMSException | NamingException | IOException e) {
        e.printStackTrace();
        log.severe("Could not write static field: " + e.getMessage());
    }

}