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:kieker.monitoring.probe.aspectj.jersey.OperationExecutionJerseyClientInterceptor.java

License:Apache License

/**
 * Method to intercept outgoing request and incoming response.
 *
 * @return value of the intercepted method
 *///from w w  w .  ja  v a 2  s.  c  o m
@Around("execution(public com.sun.jersey.api.client.ClientResponse com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(com.sun.jersey.api.client.ClientRequest))")
public Object operation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    if (!CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }
    final String signature = this.signatureToLongString(thisJoinPoint.getSignature());
    if (!CTRLINST.isProbeActivated(signature)) {
        return thisJoinPoint.proceed();
    }

    boolean entrypoint = true;
    final String hostname = VMNAME;
    final String sessionId = SESSION_REGISTRY.recallThreadLocalSessionId();
    final int eoi; // this is executionOrderIndex-th execution in this trace
    final int ess; // this is the height in the dynamic call tree of this execution
    final int nextESS;
    long traceId = CF_REGISTRY.recallThreadLocalTraceId(); // traceId, -1 if entry point
    if (traceId == -1) {
        entrypoint = true;
        traceId = CF_REGISTRY.getAndStoreUniqueThreadLocalTraceId();
        CF_REGISTRY.storeThreadLocalEOI(0);
        CF_REGISTRY.storeThreadLocalESS(1); // next operation is ess + 1
        eoi = 0;
        ess = 0;
        nextESS = 1;
    } else {
        entrypoint = false;
        eoi = CF_REGISTRY.incrementAndRecallThreadLocalEOI();
        ess = CF_REGISTRY.recallAndIncrementThreadLocalESS();
        nextESS = ess + 1;
        if ((eoi == -1) || (ess == -1)) {
            LOG.error("eoi and/or ess have invalid values:" + " eoi == " + eoi + " ess == " + ess);
            CTRLINST.terminateMonitoring();
        }
    }

    // Get request header
    final Object[] args = thisJoinPoint.getArgs();
    final ClientRequest request = (ClientRequest) args[0];
    final URI uri = request.getURI();
    // LOG.info("URI = " + uri.toString());

    // This is a hack to put all values in the header
    MultivaluedMap<String, Object> requestHeader = request.getHeaders();
    if (requestHeader == null) {
        requestHeader = new MultivaluedHashMap<String, Object>();
    }

    final List<Object> requestHeaderList = new ArrayList<Object>(4);
    requestHeaderList.add(Long.toString(traceId) + "," + sessionId + "," + Integer.toString(eoi) + ","
            + Integer.toString(nextESS));
    requestHeader.put(JerseyHeaderConstants.OPERATION_EXECUTION_JERSEY_HEADER, requestHeaderList);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Sending request to " + uri.toString() + " with header = " + requestHeader.toString());
    }

    // measure before
    final long tin = TIME.getTime();
    // execution of the called method
    Object retval = null;
    try {
        retval = thisJoinPoint.proceed(args);
    } finally {
        // measure after
        final long tout = TIME.getTime();

        // Process response
        if (retval instanceof ClientResponse) {
            final ClientResponse response = (ClientResponse) retval;
            final MultivaluedMap<String, String> responseHeader = response.getHeaders();
            if (responseHeader != null) {
                final List<String> responseHeaderList = responseHeader
                        .get(JerseyHeaderConstants.OPERATION_EXECUTION_JERSEY_HEADER);
                if (responseHeaderList != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Received response from " + uri.toString() + " with header = "
                                + responseHeader.toString());
                    }
                    final String[] responseHeaderArray = responseHeaderList.get(0).split(",");

                    // Extract trace id
                    final String retTraceIdStr = responseHeaderArray[0];
                    Long retTraceId = -1L;
                    if (!"null".equals(retTraceIdStr)) {
                        try {
                            retTraceId = Long.parseLong(retTraceIdStr);
                        } catch (final NumberFormatException exc) {
                            LOG.warn("Invalid tradeId");
                        }
                    }
                    if (traceId != retTraceId) {
                        LOG.error("TraceId in response header (" + retTraceId
                                + ") is different from that in request header (" + traceId + ")");
                    }

                    // Extract session id
                    String retSessionId = responseHeaderArray[1];
                    if ("null".equals(retSessionId)) {
                        retSessionId = OperationExecutionRecord.NO_SESSION_ID;
                    }

                    // Extract eoi
                    int retEOI = -1;
                    final String retEOIStr = responseHeaderArray[2];
                    if (!"null".equals(retEOIStr)) {
                        try {
                            retEOI = Integer.parseInt(retEOIStr);
                            CF_REGISTRY.storeThreadLocalEOI(retEOI);
                        } catch (final NumberFormatException exc) {
                            LOG.warn("Invalid eoi", exc);
                        }
                    }

                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("No monitoring data found in the response header from " + uri.toString()
                                + ". Is it instrumented?");
                    }
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Response header from " + uri.toString() + " is null. Is it instrumented?");
                }
            }
        }

        CTRLINST.newMonitoringRecord(
                new OperationExecutionRecord(signature, sessionId, traceId, tin, tout, hostname, eoi, ess));
        // cleanup
        if (entrypoint) {
            CF_REGISTRY.unsetThreadLocalTraceId();
            CF_REGISTRY.unsetThreadLocalEOI();
            CF_REGISTRY.unsetThreadLocalESS();
            SESSION_REGISTRY.unsetThreadLocalSessionId();
        } else {
            CF_REGISTRY.storeThreadLocalESS(ess); // next operation is ess
        }
    }
    return retval;
}

From source file:kieker.monitoring.probe.aspectj.jersey.OperationExecutionJerseyServerInterceptor.java

License:Apache License

/**
 * Method to intercept incoming request.
 *
 * @return value of the intercepted method
 *///from ww  w . j  ava  2s .  co  m
@Around("execution(private void com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(com.sun.jersey.server.impl.application.WebApplicationContext, com.sun.jersey.spi.container.ContainerRequest, com.sun.jersey.spi.container.ContainerResponse))")
public Object operationHandleRequest(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    if (!CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }
    final String signature = this.signatureToLongString(thisJoinPoint.getSignature());
    if (!CTRLINST.isProbeActivated(signature)) {
        return thisJoinPoint.proceed();
    }

    boolean entrypoint = true;
    final String hostname = VMNAME;
    String sessionId = SESSION_REGISTRY.recallThreadLocalSessionId();
    Long traceId = -1L;
    int eoi; // this is executionOrderIndex-th execution in this trace
    int ess; // this is the height in the dynamic call tree of this execution

    final Object[] args = thisJoinPoint.getArgs();
    final ContainerRequest request = (ContainerRequest) args[1];

    final MultivaluedMap<String, String> requestHeader = request.getRequestHeaders();
    final List<String> requestJerseyHeader = requestHeader
            .get(JerseyHeaderConstants.OPERATION_EXECUTION_JERSEY_HEADER);
    if ((requestJerseyHeader == null) || (requestJerseyHeader.isEmpty())) {
        LOG.debug("No monitoring data found in the incoming request header");
        // LOG.info("Will continue without sending back reponse header");
        traceId = CF_REGISTRY.getAndStoreUniqueThreadLocalTraceId();
        CF_REGISTRY.storeThreadLocalEOI(0);
        CF_REGISTRY.storeThreadLocalESS(1); // next operation is ess + 1
        eoi = 0;
        ess = 0;
    } else {
        final String operationExecutionHeader = requestJerseyHeader.get(0);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Received request: " + request.getRequestUri() + "with header = "
                    + requestHeader.toString());
        }
        final String[] headerArray = operationExecutionHeader.split(",");

        // Extract session id
        sessionId = headerArray[1];
        if ("null".equals(sessionId)) {
            sessionId = OperationExecutionRecord.NO_SESSION_ID;
        }

        // Extract EOI
        final String eoiStr = headerArray[2];
        eoi = -1;
        try {
            eoi = 1 + Integer.parseInt(eoiStr);
        } catch (final NumberFormatException exc) {
            LOG.warn("Invalid eoi", exc);
        }

        // Extract ESS
        final String essStr = headerArray[3];
        ess = -1;
        try {
            ess = Integer.parseInt(essStr);
        } catch (final NumberFormatException exc) {
            LOG.warn("Invalid ess", exc);
        }

        // Extract trace id
        final String traceIdStr = headerArray[0];
        if (traceIdStr != null) {
            try {
                traceId = Long.parseLong(traceIdStr);
            } catch (final NumberFormatException exc) {
                LOG.warn("Invalid trace id", exc);
            }
        } else {
            traceId = CF_REGISTRY.getUniqueTraceId();
            sessionId = SESSION_ID_ASYNC_TRACE;
            entrypoint = true;
            eoi = 0; // EOI of this execution
            ess = 0; // ESS of this execution
        }

        // Store thread-local values
        CF_REGISTRY.storeThreadLocalTraceId(traceId);
        CF_REGISTRY.storeThreadLocalEOI(eoi); // this execution has EOI=eoi; next execution will get eoi with incrementAndRecall
        CF_REGISTRY.storeThreadLocalESS(ess + 1); // this execution has ESS=ess
        SESSION_REGISTRY.storeThreadLocalSessionId(sessionId);
    }

    // measure before
    final long tin = TIME.getTime();
    // execution of the called method
    final Object retval;
    try {
        retval = thisJoinPoint.proceed();
    } finally {
        // measure after
        final long tout = TIME.getTime();
        CTRLINST.newMonitoringRecord(
                new OperationExecutionRecord(signature, sessionId, traceId, tin, tout, hostname, eoi, ess));
        // cleanup
        if (entrypoint) {
            this.unsetKiekerThreadLocalData();
        } else {
            CF_REGISTRY.storeThreadLocalESS(ess); // next operation is ess
        }
    }
    return retval;
}

From source file:kieker.monitoring.probe.aspectj.operationExecution.AbstractOperationExecutionAspectServlet.java

License:Apache License

@Around("monitoredServlet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) && notWithinKieker()")
public Object servlet(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    if (!CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }//from  w  w  w . ja va2  s  .c  o  m
    if (!CTRLINST.isProbeActivated(this.signatureToLongString(thisJoinPoint.getSignature()))) {
        return thisJoinPoint.proceed();
    }
    final HttpServletRequest req = (HttpServletRequest) thisJoinPoint.getArgs()[0];
    final String sessionId = (req != null) ? req.getSession(true).getId() : null; // NOPMD (assign null) // NOCS (inline cond)
    SESSIONREGISTRY.storeThreadLocalSessionId(sessionId);
    Object retVal;
    try {
        retVal = thisJoinPoint.proceed();
    } finally {
        SESSIONREGISTRY.unsetThreadLocalSessionId();
    }
    return retVal;
}

From source file:me.xiaochutian.aspect.ExceptionAspect.java

@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint joinPoint) throws Throwable {
    //        System.out.println("");  
    //        System.out.println("??"+joinPoint.getTarget().getClass().getName());  
    //        System.out.println("??"+joinPoint.getSignature().getName());  
    //        System.out.println("?"+joinPoint.getArgs());  
    //        System.out.println("staticPart:"+ joinPoint.getStaticPart().toShortString());  
    //        System.out.println("kind:"+joinPoint.getKind());  
    //        System.out.println("sourceLocation:"+joinPoint.getSourceLocation());  
    //        Object object = joinPoint.proceed();//   
    //        System.out.println("");  
    Logger logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
    logger.debug("??" + joinPoint.getSignature().getName());
    logger.debug("?");
    Arrays.stream(joinPoint.getArgs()).forEach(a -> logger.debug(a.toString() + " "));
    Object object = joinPoint.proceed();
    logger.debug("?");
    return object;
}

From source file:moe.yuna.palinuridae.log.LogAspect.java

@Around("execution(* moe.yuna.palinuridae.dialect..*.*(..))")
public Object logSql(ProceedingJoinPoint pjp) throws Throwable {
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass()).debug("====Prepare Sql:" + result);
    return result;
}

From source file:moe.yuna.palinuridae.log.LogAspect.java

@Around("execution(* moe.yuna.palinuridae.core.*BaseDao.find*(..))")
public Object logFindById(ProceedingJoinPoint pjp) throws Throwable {
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass()).debug("====result:" + result);
    return result;
}

From source file:moe.yuna.palinuridae.log.LogAspect.java

@Around("execution(* moe.yuna.palinuridae.core.*BaseDao.select*(..))")
public Object logSelect(ProceedingJoinPoint pjp) throws Throwable {
    long currentTimeMillis = System.currentTimeMillis();
    Object result = pjp.proceed(pjp.getArgs());
    long currentTimeMillis1 = System.currentTimeMillis();
    LoggerFactory.getLogger(pjp.getTarget().getClass()).debug("====result:" + result);
    return result;
}

From source file:moe.yuna.palinuridae.log.ProcessTimeAspect.java

@Around("execution(* moe.yuna.palinuridae.xutilsmodel.XUtilsModelDao.*(..))")
public Object xutilProcessTime(ProceedingJoinPoint pjp) throws Throwable {
    long nanoTime = System.currentTimeMillis();
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass())
            .debug("====xutil process time:" + (System.currentTimeMillis() - nanoTime) + "ms=========");
    return result;
}

From source file:moe.yuna.palinuridae.log.ProcessTimeAspect.java

@Around("execution(* moe.yuna.palinuridae.core.*BaseDao.*(..))")
public Object logProcessTime(ProceedingJoinPoint pjp) throws Throwable {
    long nanoTime = System.currentTimeMillis();
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass())
            .debug("====process time:" + (System.currentTimeMillis() - nanoTime) + "ms=========");
    return result;
}

From source file:mum.maharishi.maharishiinn.others.MyControllerAspect.java

@Around("execution (* mum.maharishi.maharishiinn.service.UserInformationService.nothing(..))")
public Object aroundAspectMethod(ProceedingJoinPoint pjp) throws Throwable {
    //Before here
    Object retVal = null;//from w ww  . ja  v  a 2s.  co m
    try {
        Object[] args = pjp.getArgs();
        retVal = pjp.proceed(args);

        Object targetClass = pjp.getTarget();
        jptDomain val = ((UserInformationService) targetClass).something("here");

        System.out.println("val.value is: " + val.getName());
    } catch (Exception e) {
        //After throw here
    } finally {
        //after finally here
    }

    //after here
    retVal = (Integer) retVal + 1;
    return retVal;
}