use of org.aspectj.lang.annotation.AfterReturning in project spf4j by zolyfarkas.
the class SamplingAllocationMonitorAspect method afterAllocation.
@AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj")
public void afterAllocation(final JoinPoint jp, final Object obj) {
MutableInteger counter = ThreadLocalCounter.get();
int value = counter.getValue();
if (value < SAMPLE_COUNT) {
counter.setValue(value + 1);
} else {
// the stack trace get and the object size method are expensive to be done at every allocation...
counter.setValue(0);
StackTrace st = StackTrace.from(Thread.currentThread().getStackTrace(), 2);
RECORDER.getRecorder(st).record(InstrumentationHelper.getObjectSize(obj));
}
}
use of org.aspectj.lang.annotation.AfterReturning in project topcom-cloud by 545314690.
the class LoginLogService method doAfter.
@AfterReturning("loginMethod()")
public void doAfter(JoinPoint pjp) throws Exception {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String contextPath = request.getContextPath();
User user = SubjectUtil.getCurrentUser(request);
LoginLog loginLog = new LoginLog();
loginLog.setUserId(user.getId());
loginLog.setUsername(user.getUsername());
loginLog.setHost(request.getRemoteHost());
if (StringUtils.isNotBlank(contextPath) && contextPath.length() > 0) {
loginLog.setSysName(contextPath.substring(1));
}
loginLogManager.save(loginLog);
}
use of org.aspectj.lang.annotation.AfterReturning in project topcom-cloud by 545314690.
the class OperationLogService method doBasicProfiling.
@AfterReturning("anyMethod()")
public void doBasicProfiling(JoinPoint pjp) throws Throwable {
HttpServletRequest request = SubjectUtil.getRequest();
Object[] args = pjp.getArgs();
OperationLog ol = new OperationLog();
Object obj = args[0];
// 拦截的实体类 Object target = pjp.getTarget();
Class<?> entityClazz = (Class<?>) ((ParameterizedType) pjp.getTarget().getClass().getGenericSuperclass()).getActualTypeArguments()[0];
ol.setEntity(entityClazz.getName());
if (obj instanceof Long) {
ol.setOperation(OperationLog.Operation.DELETE);
} else if (obj instanceof BaseEntityModel) {
BaseEntityModel objModel = (BaseEntityModel) obj;
if (objModel.getId() == null || objModel.getId() == 0) {
ol.setOperation(OperationLog.Operation.CREATE);
} else {
ol.setOperation(OperationLog.Operation.MODIFY);
}
ol.setEntity(objModel.getEntityName());
} else {
return;
}
// 拦截的方法名称
String methodName = pjp.getSignature().getName();
/**
* request是null,说明是系统调用save,否则是用户调用
*/
if (request == null) {
ol.setUsername("系统操作");
} else {
User user = SubjectUtil.getCurrentUser();
ol.setHost(request.getRemoteHost());
if (user != null) {
ol.setUserId(user.getId());
ol.setUsername(user.getUsername());
}
}
ol.setMethod(methodName);
/**
* 不使用save方法,更改了操作日志的保存方法,否则会造成无限循环调用
*/
// TODO:写一个注解,在方法名上标注不被拦截的方法
operationLogManager.persist(ol);
}
use of org.aspectj.lang.annotation.AfterReturning in project spring-framework by spring-projects.
the class ReflectiveAspectJAdvisorFactory method getAdvice.
@Override
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) {
Class<?> candidateAspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass();
validate(candidateAspectClass);
AspectJAnnotation<?> aspectJAnnotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(candidateAdviceMethod);
if (aspectJAnnotation == null) {
return null;
}
// Check that it's an AspectJ-annotated class
if (!isAspect(candidateAspectClass)) {
throw new AopConfigException("Advice must be declared inside an aspect type: " + "Offending method '" + candidateAdviceMethod + "' in class [" + candidateAspectClass.getName() + "]");
}
if (logger.isDebugEnabled()) {
logger.debug("Found AspectJ method: " + candidateAdviceMethod);
}
AbstractAspectJAdvice springAdvice;
switch(aspectJAnnotation.getAnnotationType()) {
case AtBefore:
springAdvice = new AspectJMethodBeforeAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtAfter:
springAdvice = new AspectJAfterAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtAfterReturning:
springAdvice = new AspectJAfterReturningAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
if (StringUtils.hasText(afterReturningAnnotation.returning())) {
springAdvice.setReturningName(afterReturningAnnotation.returning());
}
break;
case AtAfterThrowing:
springAdvice = new AspectJAfterThrowingAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
}
break;
case AtAround:
springAdvice = new AspectJAroundAdvice(candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
break;
case AtPointcut:
if (logger.isDebugEnabled()) {
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
}
return null;
default:
throw new UnsupportedOperationException("Unsupported advice type on method: " + candidateAdviceMethod);
}
// Now to configure the advice...
springAdvice.setAspectName(aspectName);
springAdvice.setDeclarationOrder(declarationOrder);
String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod);
if (argNames != null) {
springAdvice.setArgumentNamesFromStringArray(argNames);
}
springAdvice.calculateArgumentBindings();
return springAdvice;
}
use of org.aspectj.lang.annotation.AfterReturning in project ORCID-Source by ORCID.
the class OrcidApiVisibilitySecurityAspect method simpleVisibilityProfileFilter.
@AfterReturning(pointcut = "@annotation(visibilityAnnotation)", returning = "profile")
public void simpleVisibilityProfileFilter(OrcidProfile profile, VisibilityControl visibilityAnnotation) {
if (profile != null) {
OrcidMessage message = new OrcidMessage(profile);
visibilityFilter.filter(message, visibilityAnnotation.visibilities());
}
}
Aggregations