List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:it.tidalwave.role.spring.spi.DciContextWithAutoThreadBindingAspect.java
License:Apache License
@Around("within(@it.tidalwave.dci.annotation.DciContext *) && execution(* *(..))") public Object advice(final @Nonnull ProceedingJoinPoint pjp) throws Throwable { final Object context = pjp.getTarget(); if (!context.getClass().getAnnotation(DciContext.class).autoThreadBinding()) { return pjp.proceed(); } else {/* w ww . jav a2 s. c o m*/ if (log.isTraceEnabled()) { log.trace("executing {}.{}() with context thread binding", shortId(context), pjp.getSignature().getName()); } // It looks like the @Inject approach creates bogus multiple instance of ContextManager final ContextManager contextManager = ContextManager.Locator.find(); return contextManager.runWithContext(context, new Task<Object, Throwable>() { @Override public Object run() throws Throwable { return pjp.proceed(); } }); } }
From source file:jenergy.agent.aop.aspectj.aspects.TraceAspect.java
License:Apache License
/** * Around advice to trace every method of application except the methods of the profiler. This is a runtime advice. * //w ww .ja v a 2 s.co m * @param thisJoinPoint * The joint point reference. * @return The result value. This value will be returned as result of the call to method {@link #proceed(Object)}. * @throws Throwable * May throw any exceptions declared by the join point itself. If this exception is not declared and is not a runtime exception, it * will be encapsulated in a {@link RuntimeException} before being thrown to the basis system. */ @org.aspectj.lang.annotation.Around("execution(* *(..)) && !within(jenergy..*)") public Object invoke(final ProceedingJoinPoint thisJoinPoint) throws Throwable { Method method = AspectjUtils.getMethod(thisJoinPoint.getSignature()); return this.invokeAdvice(method, thisJoinPoint); }
From source file:jenergy.agent.aop.aspectj.util.AspectjUtils.java
License:Apache License
/** * //from w w w . j a va 2 s . c o m * @param thisJoinPoint * The reference to the constructor joinpoint. * @param clazz * The class to invoke the same constructor of the joinpoint. * @param newArgs * The arguments to be passed to the constructor call. In this case, the constructor arguments will be: the arguments of the original * constructor defined by the joinpoint, and the newArgs. * @param <T> * The type returned by the constructor call. * @return A new object created by calling the constructor of the given class. * @throws NoSuchMethodException * If a matching method is not found. * @throws SecurityException * If a security manager, <em>s</em>, is present and any of the following conditions is met: * <ul> * <li>invocation of s.checkMemberAccess(this, Member.PUBLIC) denies access to the constructor</li> * <li>the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of * s.checkPackageAccess() denies access to the package of this class.</li> * </ul> * @throws InstantiationException * If the class that declares the underlying constructor represents an abstract class. * @throws IllegalAccessException * If the Constructor object is enforcing Java language access control and the underlying constructor is inaccessible. * @throws IllegalArgumentException * If the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after * possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation * conversion; if this constructor pertains to an {@link Enum} type. * @throws InvocationTargetException * If the underlying constructor throws an exception. * @throws ClassCastException * If it is not a constructor joinpoint. * @see ConstructorSignature */ public static <T> T newInstance(ProceedingJoinPoint thisJoinPoint, Class<T> clazz, Object... newArgs) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { ConstructorSignature signature = (ConstructorSignature) thisJoinPoint.getSignature(); Class<?>[] parameterTypes = new Class[signature.getParameterTypes().length + (newArgs != null ? newArgs.length : 0)]; Object[] newConstructorArgs = new Object[parameterTypes.length]; for (int i = 0; i < signature.getParameterTypes().length; i++) { parameterTypes[i] = signature.getParameterTypes()[i]; newConstructorArgs[i] = thisJoinPoint.getArgs()[i]; } for (int i = 0, j = newConstructorArgs.length - newArgs.length; i < newArgs.length; i++, j++) { parameterTypes[j] = newArgs[i].getClass(); newConstructorArgs[j] = newArgs[i]; } Constructor<T> constructor = clazz.getConstructor(parameterTypes); constructor.setAccessible(true); return constructor.newInstance(newConstructorArgs); }
From source file:jenergy.agent.aop.aspectj.util.AspectjUtils.java
License:Apache License
/** * Returns the reference of the {@link Method} of the advice. * //w w w . j av a2s .c o m * @param joinPoint * The joinpoint reference. * @return The method of the advice. It's never <code>null</code>. * @throws Exception * If it's not possible to invoke the private method in the JVM. */ public static Method getMethod(ProceedingJoinPoint joinPoint) throws Exception { return getMethod(joinPoint.getSignature()); }
From source file:joinery.impl.Metrics.java
License:Open Source License
@Around("execution(@com.codahale.metrics.annotation.Timed * *(..))") public Object injectTimer(final ProceedingJoinPoint point) throws Throwable { final Signature signature = point.getSignature(); final Annotation annotation = getAnnotation(signature, Timed.class); final Timed timed = Timed.class.cast(annotation); final String name = name(signature, timed.name(), "timer", timed.absolute()); final Timer timer = registry.timer(name); final Timer.Context context = timer.time(); try {//from ww w . ja va 2 s. c o m return point.proceed(point.getArgs()); } finally { context.stop(); } }
From source file:jp.co.opentone.bsol.framework.core.MethodTraceAdvice.java
License:Apache License
private Method getMethod(ProceedingJoinPoint jp) { MethodSignature s = (MethodSignature) jp.getSignature(); return s.getMethod(); }
From source file:jsst.core.client.aspects.DispatcherAspect.java
License:LGPL
@SuppressWarnings({ "unchecked" }) @Around(value = "method()") public void dispatch(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); ServerResponse response = getDispatcher().dispatch(methodSignature.getMethod()); getHandler().handle(response);/*from ww w .j ava2s .com*/ }
From source file:kieker.monitoring.probe.aspectj.flow.constructorCall.AbstractAspect.java
License:Apache License
/** * This is an advice used around calls from members to constructors. * /*from w ww .j ava2 s . com*/ * @param thisObject * The caller object. * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && this(thisObject) && notWithinKieker()") public Object member2constructor(final Object thisObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
From source file:kieker.monitoring.probe.aspectj.flow.constructorCall.AbstractAspect.java
License:Apache License
/** * This is an advice used around calls from static elements to constructors. * // w w w.j a v a 2 s.co m * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && !this(java.lang.Object) && notWithinKieker()") public Object static2constructor(final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
From source file:kieker.monitoring.probe.aspectj.flow.constructorCallObject.AbstractAspect.java
License:Apache License
/** * This is an advice used around calls from members to constructors. * * @param thisObject/* w ww. j a va2 s .c om*/ * The caller object. * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && this(thisObject) && target(targetObject) && notWithinKieker()") public Object member2constructor(final Object thisObject, final Object targetObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); final int callerObjectId = System.identityHashCode(thisObject); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); final int calleeObjectId = System.identityHashCode(targetObject); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, callerObjectId, calleeObjectId)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }