|
@@ -0,0 +1,77 @@
|
|
|
+package com.its.rota.client.aspect;
|
|
|
+
|
|
|
+import com.beanit.its.CurrentLinkState;
|
|
|
+import com.beanit.its.IncidentConditions;
|
|
|
+import com.its.app.common.utils.Elapsed;
|
|
|
+import com.its.rota.client.process.dbms.DbmsData;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class LoggingAspect {
|
|
|
+ @Around("@annotation(com.its.rota.client.aspect.annotation.ScheduleElapsed)")
|
|
|
+ public Object scheduleElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+
|
|
|
+ String proceedName = String.format("%45s", joinPoint.getTarget().getClass().getSimpleName() + "." + joinPoint.getSignature().getName());
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
+ Object proceed = joinPoint.proceed();
|
|
|
+ log.info("{}: {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+ @Around("@annotation(com.its.rota.client.aspect.annotation.ProcessElapsed)")
|
|
|
+ public Object processElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ String proceedName = String.format("%45s", joinPoint.getTarget().getClass().getSimpleName() + "." + joinPoint.getSignature().getName());
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
+ Object proceed = joinPoint.proceed();
|
|
|
+ log.info("{}: {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+ @Around("@annotation(com.its.rota.client.aspect.annotation.DbmsElapsed)")
|
|
|
+ public Object dbmsElapsedTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ Object[] params = joinPoint.getArgs();
|
|
|
+ DbmsData dbmsData = null;
|
|
|
+ if (params.length > 0) {
|
|
|
+ if (params[0] instanceof DbmsData) {
|
|
|
+ dbmsData = (DbmsData) params[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String proceedName = String.format("%45s", joinPoint.getTarget().getClass().getSimpleName() + "." + joinPoint.getSignature().getName());
|
|
|
+ Elapsed elapsed = new Elapsed();
|
|
|
+ Object proceed = joinPoint.proceed();
|
|
|
+ if (dbmsData != null) {
|
|
|
+ switch(dbmsData.getType()) {
|
|
|
+ case DbmsData.DBMS_DATA_RCV_LINK_TRAFFIC:
|
|
|
+ List<CurrentLinkState> trafficLists = (List<CurrentLinkState>) dbmsData.getData();
|
|
|
+ log.info("{}: DBMS_DATA_RCV_LINK_TRAFFIC, {} EA. {}", proceedName, trafficLists.size(), Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ break;
|
|
|
+ case DbmsData.DBMS_DATA_RCV_INCIDENT:
|
|
|
+ List<IncidentConditions> incidentLists = (List<IncidentConditions>)dbmsData.getData();
|
|
|
+ log.info("{}: DBMS_DATA_RCV_INCIDENT, {} EA. {}", proceedName, incidentLists.size(), Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ break;
|
|
|
+ case DbmsData.DBMS_DATA_DELETE_RCV_LINK_TRAFFIC:
|
|
|
+ log.info("{}: DBMS_DATA_DELETE_RCV_LINK_TRAFFIC, {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ break;
|
|
|
+ case DbmsData.DBMS_DATA_DELETE_RCV_LOG:
|
|
|
+ log.info("{}: DBMS_DATA_DELETE_RCV_LOG, {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ break;
|
|
|
+ case DbmsData.DBMS_DATA_DELETE_RCV_INCIDENT:
|
|
|
+ log.info("{}: DBMS_DATA_DELETE_RCV_INCIDENT, {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.info("{}: {}", proceedName, Elapsed.elapsedTimeStr(elapsed.nanoSeconds()));
|
|
|
+ }
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+}
|