All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.automon.aspects.AutomonSpringAspect Maven / Gradle / Ivy

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.automon.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * 

This aspect should contain pointcut language that is compatible with Spring. Use this as your Base class if you use Spring. * It will also work with any AspectJ program, but will be more limited in how expressive the pointcuts can be.

* *

Note a developer should implement and provide pointcuts that you want to monitor by implementing {@link #user_monitor()} * and {@link #user_exceptions()}

*/ @Component public class AutomonSpringAspect extends AutomonAspectBase { /** * _monitor() advice - Wraps the given pointcut and calls the appropriate {@link org.automon.implementations.OpenMon} method * at the beginning and end of the method call. * * @param pjp * @return The advised methods value or void. * @throws Throwable If the method throws a {@link java.lang.Throwable} the advice will rethrow it. */ public Object monitor(ProceedingJoinPoint pjp) throws Throwable { // Note: context is typically a Timer/Monitor object returned by the monitoring implementation (Jamon, JavaSimon, Metrics,...) // though to this advice it is simply an object and the advice doesn't care what the intent of the context/object is. Object context = getOpenMon().start(pjp.getStaticPart()); try { Object retVal = pjp.proceed(); getOpenMon().stop(context); return retVal; } catch (Throwable throwable) { getOpenMon().stop(context, throwable); throw throwable; } } /** * exceptions() advice - Takes action on any Exception thrown. It typically Tracks/Counts any exceptions thrown by the pointcut. * Note arguments are passed on to {@link org.automon.implementations.OpenMon#exception(org.aspectj.lang.JoinPoint, Throwable)} * @param pjp * @param exception */ public void throwing(JoinPoint pjp, Throwable exceptionArg) { getOpenMon().exception(pjp, exceptionArg); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy