Package: DebugProfilingAspect
DebugProfilingAspect
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DebugProfilingAspect() |
|
|
|
|
|
||||||||||||||||||||
advice(ProceedingJoinPoint) |
|
|
|
|
|
||||||||||||||||||||
aspectOf() |
|
|
|
|
|
||||||||||||||||||||
getAnnotation(ProceedingJoinPoint, Class) |
|
|
|
|
|
||||||||||||||||||||
hasAspect() |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1:•/*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.aspect;
28:
29: import java.lang.annotation.Annotation;
30: import javax.annotation.Nonnull;
31: import org.aspectj.lang.ProceedingJoinPoint;
32: import org.aspectj.lang.annotation.Around;
33: import org.aspectj.lang.annotation.Aspect;
34: import org.aspectj.lang.reflect.MethodSignature;
35: import org.springframework.beans.factory.annotation.Configurable;
36: import lombok.extern.slf4j.Slf4j;
37:
38: /***********************************************************************************************************************
39: *
40: * @author Fabrizio Giudici
41: *
42: **********************************************************************************************************************/
43: @Configurable @Aspect @Slf4j
44:•public class DebugProfilingAspect
45: {
46: // @Around("execution(@it.tidalwave.northernwind.aspect.DebugProfiling * *(..))") FIXME: requires aspectj plugin 1.5
47: @Around("execution(* it.tidalwave.northernwind.frontend.media.impl.EmbeddedMediaMetadataProvider.getMetadataString(..))")
48: public Object advice (@Nonnull final ProceedingJoinPoint pjp)
49: throws Throwable
50: {
51: log.debug("getMetadataString({})", pjp.getArgs());
52: final var time = System.currentTimeMillis();
53:
54: final var result = pjp.proceed();
55:
56:• if (log.isDebugEnabled())
57: {
58: final var annotation = getAnnotation(pjp, DebugProfiling.class);
59: log.debug(">>>> {} in {} msec", annotation.message(), System.currentTimeMillis() - time);
60: }
61:
62: return result;
63: }
64:
65: // See http://stackoverflow.com/questions/2559255/spring-aop-how-to-get-the-annotations-of-the-adviced-method
66: @Nonnull
67: private static <T extends Annotation> T getAnnotation (@Nonnull final ProceedingJoinPoint pjp,
68: @Nonnull final Class<T> annotationClass)
69: throws NoSuchMethodException
70: {
71: final var methodSignature = (MethodSignature)pjp.getSignature();
72: var method = methodSignature.getMethod();
73:
74:• if (method.getDeclaringClass().isInterface()) // FIXME && annotation inheritance -- FIXME also ancestor class
75: {
76: final var methodName = pjp.getSignature().getName();
77: method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
78: }
79:
80: return method.getAnnotation(annotationClass);
81: }
82: }