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

License:Apache License

/**
 * Method to intercept incoming request.
 *
 * @return value of the intercepted method
 *///w w w .  j av a  2s .  c  om
@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.jersey.OperationExecutionJerseyServerInterceptor.java

License:Apache License

/**
 * Method to intercept outgoing response.
 *
 * @return value of the intercepted method
 *//*  w  w w .j a v  a 2 s.  c  o m*/
@Around("execution(public void com.sun.jersey.spi.container.ContainerResponse.write())")
public Object operationWriteResponse(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();
    }

    final long traceId = CF_REGISTRY.recallThreadLocalTraceId();

    if (traceId == -1) {
        // Kieker trace Id not registered. Should not happen, since this is a response message!
        LOG.warn("Kieker traceId not registered. Will unset all threadLocal variables and return.");
        return thisJoinPoint.proceed();
    }

    final String sessionId = SESSION_REGISTRY.recallThreadLocalSessionId();
    final ContainerResponse containerResponse = (ContainerResponse) thisJoinPoint.getTarget();
    final MultivaluedMap<String, Object> responseHeader = containerResponse.getHttpHeaders();

    // Pass back trace id, session id, eoi but not ess (use old value before the request)
    final List<Object> responseHeaderList = new ArrayList<Object>();
    responseHeaderList.add(Long.toString(traceId) + "," + sessionId + ","
            + Integer.toString(CF_REGISTRY.recallThreadLocalEOI()));
    responseHeader.put(JerseyHeaderConstants.OPERATION_EXECUTION_JERSEY_HEADER, responseHeaderList);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Sending response with header = " + responseHeader.toString() + " to the request: "
                + containerResponse.getContainerRequest().getRequestUri());
    }

    final Object retval = thisJoinPoint.proceed();

    return retval;
}

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

License:Apache License

@Around("monitoredOperation() && notWithinKieker()")
public Object operation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    if (!CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }/* www  .  jav a  2  s  .  com*/
    final String signature = this.signatureToLongString(thisJoinPoint.getSignature());
    if (!CTRLINST.isProbeActivated(signature)) {
        return thisJoinPoint.proceed();
    }
    // collect data
    final boolean entrypoint;
    final String hostname = VMNAME;
    final String sessionId = SESSIONREGISTRY.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
    long traceId = CFREGISTRY.recallThreadLocalTraceId(); // traceId, -1 if entry point
    if (traceId == -1) {
        entrypoint = true;
        traceId = CFREGISTRY.getAndStoreUniqueThreadLocalTraceId();
        CFREGISTRY.storeThreadLocalEOI(0);
        CFREGISTRY.storeThreadLocalESS(1); // next operation is ess + 1
        eoi = 0;
        ess = 0;
    } else {
        entrypoint = false;
        eoi = CFREGISTRY.incrementAndRecallThreadLocalEOI(); // ess > 1
        ess = CFREGISTRY.recallAndIncrementThreadLocalESS(); // ess >= 0
        if ((eoi == -1) || (ess == -1)) {
            LOG.error("eoi and/or ess have invalid values:" + " eoi == " + eoi + " ess == " + ess);
            CTRLINST.terminateMonitoring();
        }
    }
    // 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) {
            CFREGISTRY.unsetThreadLocalTraceId();
            CFREGISTRY.unsetThreadLocalEOI();
            CFREGISTRY.unsetThreadLocalESS();
        } else {
            CFREGISTRY.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();
    }//  w  w  w  . ja v a 2  s.  co  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:kieker.tools.slastic.plugins.slachecker.monitoring.kieker.probe.aspectJ.sla.SLAMonitoringProbe.java

License:Apache License

protected SLOMonitoringRecord initMonitoringRecord(final ProceedingJoinPoint thisJoinPoint) {
    // e.g. "getBook"
    final String methodname = thisJoinPoint.getSignature().getName();
    // toLongString provides e.g.
    // "public kieker.tests.springTest.Book kieker.tests.springTest.CatalogService.getBook()"
    String paramList = thisJoinPoint.getSignature().toLongString();
    final int paranthIndex = paramList.lastIndexOf('(');
    paramList = paramList.substring(paranthIndex); // paramList is now e.g.,
    // "()"/* w w w.j  a v  a 2s.  c om*/

    final SLOMonitoringRecord record = new SLOMonitoringRecord(
            thisJoinPoint.getSignature().getDeclaringTypeName() /* component */,
            methodname + paramList /* operation */, SLAMonitoringProbe.vmName);
    return record;
}

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:net.cit.tetrad.aop.ExecutionTimeCheck.java

License:Open Source License

public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
    String signatureString = joinPoint.getSignature().toShortString();
    logger.debug(signatureString + " start!!");
    long start = System.currentTimeMillis();
    try {/*  w w  w . j av a  2  s . co  m*/
        Object result = joinPoint.proceed();
        return result;
    } finally {
        long finish = System.currentTimeMillis();
        logger.debug(signatureString + " end!!");
        logger.info(signatureString + " execution time : " + (finish - start) + "ms");
    }
}

From source file:net.cristcost.study.aop.TestAspect.java

License:Apache License

public Object traceInvocation(ProceedingJoinPoint joinpoint) {
    Object ret = null;/*from   w w w. java  2s  .  c o m*/
    System.out.println("Processing aspect in: " + joinpoint.getSignature());
    long start = System.currentTimeMillis();
    try {
        ret = joinpoint.proceed();
    } catch (Throwable e) {
        System.out.println("Exception in aspect: " + e.getMessage());
    }
    long end = System.currentTimeMillis();

    System.out.println("@executed in " + (end - start) + " ms");
    System.out.println();
    return ret;
}

From source file:net.greencoding.thysdrus.circuitbreaker.aspect.CircuitBreakerAspect.java

License:Apache License

@Around("execution(@net.greencoding.thysdrus.circuitbreaker.annotation.MonitoredByCircuitBreaker * * (..))")
public Object breakCircuit(final ProceedingJoinPoint pjp) throws Throwable {
    Object returnObject = null;//from www  .  j  a v a  2 s  .co m
    final String method = pjp.getSignature().toLongString();
    CircuitBreakerStatus status = null;
    try {
        final MethodSignature sig = (MethodSignature) pjp.getStaticPart().getSignature();
        final MonitoredByCircuitBreaker cbAnnotation = sig.getMethod()
                .getAnnotation(MonitoredByCircuitBreaker.class);
        registry.registerMehtodIfnecessary(method, cbAnnotation);
        status = registry.getStatusWithHalfOpenExclusiveLockTry(method);
        if (status.equals(CircuitBreakerStatus.OPEN)) {
            logger.info("CIRCUIT STATUS: OPEN. Method {} can not be executed. try later!", method);
            if (cbAnnotation.isSilientMode()) {
                return null;
            } else {
                throw new OpenCircuitException();
            }
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN)) {
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN. Another thread has the exclusive lock for half open. Method {} can not be executed.",
                    method);
            if (cbAnnotation.isSilientMode()) {
                return null;
            } else {
                throw new OpenCircuitException();
            }
        } else if (status.equals(CircuitBreakerStatus.CLOSED)) {
            logger.info("CIRCUIT STATUS: CLOSED. execute method {}", method);
            returnObject = proceed(pjp);
        } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. This thread win the exclusive lock for the half open call. execute method: {}",
                    method);
            returnObject = proceed(pjp);
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }

    } catch (CircuitBreakerMethodExecutionException e) {
        Throwable throwable = e.getCause();
        for (Class<? extends Throwable> clazz : registry.getfailureIndications(method)) {
            if (clazz.isAssignableFrom(throwable.getClass())) {
                // detected a failure 
                logger.info("dectected failure. failure indication: {} \nException:", clazz.getCanonicalName(),
                        throwable);
                if (status.equals(CircuitBreakerStatus.CLOSED)
                        && registry.sameClosedCycleInLocalAndGlobaleContext(method)) {
                    logger.info("Valid failure: method call and failure are in the same CLOSED cycle.");
                    registry.addFailureAndOpenCircuitIfThresholdAchived(method);
                } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
                    registry.keepOpenAndUnlock(method);
                }
                throw throwable;
            }
        }
        // thrown exception is not a failureIndication
        if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) {
            logger.info(
                    "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}",
                    method);
            registry.closeAndUnlock(method);
        }
        // throw the original method execution exception upper to the method invoker
        throw throwable;
    } finally {
        registry.cleanUp(method);
    }
    return returnObject;
}

From source file:net.greencoding.thysdrus.circuitbreaker.aspect.CircuitBreakerAspect.java

License:Apache License

private Object proceed(ProceedingJoinPoint pjp) throws CircuitBreakerMethodExecutionException {
    try {/*from ww w  .j av a  2 s .c o  m*/
        return pjp.proceed();
    } catch (Throwable t) {
        logger.debug("Exception while method execution: {}", pjp.getSignature().toLongString());
        throw new CircuitBreakerMethodExecutionException(t);
    }
}