Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ManagerLoggingAspect |
|
| 1.0;1 |
1 | package org.jtheque.core.spring.aspect; | |
2 | ||
3 | import org.aspectj.lang.ProceedingJoinPoint; | |
4 | import org.aspectj.lang.annotation.Around; | |
5 | import org.aspectj.lang.annotation.Aspect; | |
6 | import org.slf4j.LoggerFactory; | |
7 | ||
8 | /* | |
9 | * This file is part of JTheque. | |
10 | * | |
11 | * JTheque is free software: you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation, either version 3 of the License. | |
14 | * | |
15 | * JTheque is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
22 | */ | |
23 | ||
24 | /** | |
25 | * An AspectJ aspect to logging the managers' init, preInit and close methods. | |
26 | * | |
27 | * @author Baptiste Wicht | |
28 | */ | |
29 | @Aspect | |
30 | 0 | public final class ManagerLoggingAspect { |
31 | /** | |
32 | * Log the init method of the managers. | |
33 | * | |
34 | * @param joinPoint The join point of the advised method. | |
35 | * | |
36 | * @return The return value of the joint point method. | |
37 | * | |
38 | * @throws Throwable Throw if the init method throws an exception. | |
39 | */ | |
40 | @Around("execution(* org.jtheque.core.managers.*Manager.init())") | |
41 | public Object logInit(ProceedingJoinPoint joinPoint) throws Throwable{ | |
42 | 0 | return trace(joinPoint, "init"); |
43 | } | |
44 | ||
45 | /** | |
46 | * Log the preInit method of the managers. | |
47 | * | |
48 | * @param joinPoint The join point of the advised method. | |
49 | * | |
50 | * @return The return value of the joint point method. | |
51 | * | |
52 | * @throws Throwable Throw if the preInit method throws an exception. | |
53 | */ | |
54 | @Around("execution(* org.jtheque.core.managers.*Manager.preInit())") | |
55 | public Object logPreInit(ProceedingJoinPoint joinPoint) throws Throwable{ | |
56 | 0 | return trace(joinPoint, "pre-init"); |
57 | } | |
58 | ||
59 | /** | |
60 | * Log the close method of the managers. | |
61 | * | |
62 | * @param joinPoint The join point of the advised method. | |
63 | * | |
64 | * @return The return value of the joint point method. | |
65 | * | |
66 | * @throws Throwable Throw if the close method throws an exception. | |
67 | */ | |
68 | @Around("execution(* org.jtheque.core.managers.*Manager.close())") | |
69 | public Object logClose(ProceedingJoinPoint joinPoint) throws Throwable{ | |
70 | 0 | return trace(joinPoint, "close"); |
71 | } | |
72 | ||
73 | /** | |
74 | * Trace the join point method start and finish | |
75 | * | |
76 | * @param joinPoint The join point to trace. | |
77 | * @param phase The current manager phase. | |
78 | * | |
79 | * @return The return value of the joint point method. | |
80 | * | |
81 | * @throws Throwable Throw if the traced method throws an exception. | |
82 | */ | |
83 | private Object trace(ProceedingJoinPoint joinPoint, String phase) throws Throwable{ | |
84 | 0 | LoggerFactory.getLogger(getClass()).trace( |
85 | "{} {} started", | |
86 | joinPoint.getSourceLocation().getWithinType().getSimpleName(), phase); | |
87 | ||
88 | 0 | Object retVal = joinPoint.proceed(); |
89 | ||
90 | 0 | LoggerFactory.getLogger(getClass()).trace( |
91 | "{} {} finished", | |
92 | joinPoint.getSourceLocation().getWithinType().getSimpleName(), phase); | |
93 | ||
94 | 0 | return retVal; |
95 | } | |
96 | } |