本文整理汇总了Java中org.aspectj.lang.reflect.MethodSignature类的典型用法代码示例。如果您正苦于以下问题:Java MethodSignature类的具体用法?Java MethodSignature怎么用?Java MethodSignature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodSignature类属于org.aspectj.lang.reflect包,在下文中一共展示了MethodSignature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructorAnnotated
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("methodAnnotated() || constructorAnnotated()")//在连接点进行方法替换
public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Timber.i(methodSignature.getMethod().getDeclaringClass().getCanonicalName());
String className = methodSignature.getDeclaringType().getSimpleName();
String methodName = methodSignature.getName();
long startTime = System.nanoTime();
Object result = joinPoint.proceed();//执行原方法
StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(methodName + ":");
for (Object obj : joinPoint.getArgs()) {
if (obj instanceof String) keyBuilder.append((String) obj);
else if (obj instanceof Class) keyBuilder.append(((Class) obj).getSimpleName());
}
String key = keyBuilder.toString();
Timber.i((className + "." + key + joinPoint.getArgs().toString() + " --->:" + "[" + (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)) + "ms]"));// 打印时间差
return result;
}
示例2: constructorAnnotated
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("methodAnnotated() || constructorAnnotated()")//在连接点进行方法替换
public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
LogUtils.showLog("TimeLog getDeclaringClass", methodSignature.getMethod().getDeclaringClass().getCanonicalName());
String className = methodSignature.getDeclaringType().getSimpleName();
String methodName = methodSignature.getName();
long startTime = System.nanoTime();
Object result = joinPoint.proceed();//执行原方法
StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(methodName + ":");
for (Object obj : joinPoint.getArgs()) {
if (obj instanceof String) keyBuilder.append((String) obj);
else if (obj instanceof Class) keyBuilder.append(((Class) obj).getSimpleName());
}
String key = keyBuilder.toString();
LogUtils.showLog("TimeLog", (className + "." + key + joinPoint.getArgs().toString() + " --->:" + "[" + (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)) + "ms]"));// 打印时间差
return result;
}
示例3: afterReturn
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
/**
* @param joinPoint
*/
@AfterReturning("logAnnoAspect()")
public void afterReturn(JoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
LogDelete logDelete = method.getAnnotation(LogDelete.class);
if (null != logDelete) {
BaseEntity entity = (BaseEntity) joinPoint.getArgs()[0];
Log log = new Log();
log.setUserId(((User) SecurityUtils.getSubject().getSession().getAttribute("curUser")).getId());
log.setAction(Constants.LOG_ACTION_DELETE + logDelete.resource());
log.setResource(entity.getLogResource());
log.setResourceId(entity.getId());
logService.insert(log);
}
}
示例4: aroundJoinPoint
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("methodAnnotated()")//在连接点进行方法替换
public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
String methodName = methodSignature.getName();
MemoryCacheManager mMemoryCacheManager = MemoryCacheManager.getInstance();
StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(methodName);
for (Object obj : joinPoint.getArgs()) {
if (obj instanceof String) keyBuilder.append((String) obj);
else if (obj instanceof Class) keyBuilder.append(((Class) obj).getSimpleName());
}
String key = keyBuilder.toString();
Object result = mMemoryCacheManager.get(key);//key规则 : 方法名+参数1+参数2+...
LogUtils.showLog("MemoryCache", "key:" + key + "--->" + (result != null ? "not null" : "null"));
if (result != null) return result;//缓存已有,直接返回
result = joinPoint.proceed();//执行原方法
if (result instanceof List && result != null && ((List) result).size() > 0 //列表不为空
|| result instanceof String && !TextUtils.isEmpty((String) result)//字符不为空
|| result instanceof Object && result != null)//对象不为空
mMemoryCacheManager.add(key, result);//存入缓存
LogUtils.showLog("MemoryCache", "key:" + key + "--->" + "save");
return result;
}
示例5: needCheck
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
private boolean needCheck(ProceedingJoinPoint point) {
if (! MethodSignature.class.isAssignableFrom(point.getSignature().getClass())) {
return false;
}
MethodSignature methodSignature = (MethodSignature) point.getSignature();
Method method = methodSignature.getMethod();
if (method.isAnnotationPresent(LoginCheck.class)) {
return true;
}
Class glass = method.getDeclaringClass();
if (! glass.isAnnotationPresent(LoginCheck.class)) {
return false;
}
LoginCheck loginCheck = (LoginCheck) glass.getAnnotation(LoginCheck.class);
String[] methods = loginCheck.exclusions();
return ! ArrayUtils.contains(methods, method.getName());
}
示例6: intercept
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("interceptDao()")
public Object intercept(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
try {
Class clazz = MethodSignature.class.cast(joinPoint.getSignature()).getDeclaringType();
DynamicDS targetDataSource = AnnotationUtils.findAnnotation(clazz, DynamicDS.class);
if (targetDataSource != null) {
DataSourceContextHolder.setTargetDataSource(DataSourceEnum.valueOf(targetDataSource.value()));
} else {
DataSourceContextHolder.resetDefaultDataSource();
}
result = joinPoint.proceed();
return result;
} catch (Throwable ex) {
throw new RuntimeException(ex);
}
}
示例7: around
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("anyPublicJdbcMethod()")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
if (logger.isTraceEnabled()) {
String enterMessage = MessageFormat.format("Entering method {0}({1})",
MethodSignature.class.cast(proceedingJoinPoint.getSignature()).getMethod().getName(),
proceedingJoinPoint.getArgs());
logger.trace(enterMessage);
}
Object response = proceedingJoinPoint.proceed();
if (logger.isTraceEnabled()) {
String exitMessage = MessageFormat.format("Exiting method {0}({1}) : {2}",
MethodSignature.class.cast(proceedingJoinPoint.getSignature()).getMethod().getName(),
proceedingJoinPoint.getArgs(), response);
logger.trace(exitMessage);
}
return response;
}
示例8: execution
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("execution(* org.assertj.core.api.AbstractAssert+.*(..)) "
+ "|| execution(* org.assertj.core.api.Assertions.assertThat(..))")
public Object step(final ProceedingJoinPoint joinPoint) throws Throwable {
final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
final String name = joinPoint.getArgs().length > 0
? String.format("%s \'%s\'", methodSignature.getName(), arrayToString(joinPoint.getArgs()))
: methodSignature.getName();
final String uuid = UUID.randomUUID().toString();
final StepResult result = new StepResult()
.withName(name);
getLifecycle().startStep(uuid, result);
try {
final Object proceed = joinPoint.proceed();
getLifecycle().updateStep(uuid, s -> s.withStatus(Status.PASSED));
return proceed;
} catch (Throwable e) {
getLifecycle().updateStep(uuid, s -> s
.withStatus(getStatus(e).orElse(Status.BROKEN))
.withStatusDetails(getStatusDetails(e).orElse(null)));
throw e;
} finally {
getLifecycle().stopStep(uuid);
}
}
示例9: isLocalProceeder
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
/**
* @param method
* @return <code>true</code> if the given method has the same signature as
* the currently aspectJ extension-overridden method
*/
static boolean isLocalProceeder(Method method)
{
if (!ajLocalProceedingJoinPoints.get().isEmpty())
{
ProceedingContext proceedingCotext = ajLocalProceedingJoinPoints.get().peek();
MethodSignature ms = (MethodSignature) proceedingCotext.proceedingJoinPoint.getSignature();
Method jpMethod = ms.getMethod();
return jpMethod.getName().endsWith(method.getName()) && Arrays.equals(jpMethod.getParameterTypes(),
method.getParameterTypes());
}
else
{
return false;
}
}
示例10: before
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("execution(org.springframework.web.servlet.ModelAndView org.gra4j.dataMigration.controller..*.*(..)) "
+ " and @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object before(ProceedingJoinPoint pjp) throws Throwable {
// 从切点上获取目标方法
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
// 若目标方法忽略了安全性检查,则直接调用目标方法
if (method.isAnnotationPresent(UnCheck.class))
return pjp.proceed();
if (StringUtils.isEmpty(tokenName))
tokenName = DEFAULT_TOKEN_NAME;
HttpServletRequest request = WebContext.getRequest();
HttpServletResponse response = WebContext.getResponse();
String token = tokenManager.createToken(
((SecurityContextImpl) request.getSession()
.getAttribute("SPRING_SECURITY_CONTEXT"))
.getAuthentication()
.getName());
response.addHeader(tokenName,token);
return pjp.proceed();
}
示例11: updateCache
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@AfterReturning ("@annotation(fr.gael.dhus.spring.cache.IncrementCache)")
public void updateCache (JoinPoint joinPoint)
{
IncrementCache annotation = ((MethodSignature) joinPoint.getSignature ())
.getMethod ().getAnnotation (IncrementCache.class);
Cache cache = getCacheManager().getCache(annotation.name());
if (cache != null)
{
synchronized (cache)
{
Integer old_value = cache.get (annotation.key (), Integer.class);
cache.clear ();
if (old_value == null)
{
return;
}
cache.put (annotation.key (), (old_value + annotation.value ()));
}
}
}
示例12: providerBegin
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
TccTransaction providerBegin(TccTransactionContext context, ProceedingJoinPoint point) {
LogUtil.debug(LOGGER, "参与方开始执行tcc事务!start:{}", context::toString);
MethodSignature signature = (MethodSignature) point.getSignature();
Method method = signature.getMethod();
Class<?> clazz = point.getTarget().getClass();
TccTransaction transaction = new TccTransaction(context.getTransId());
//设置角色为提供者
transaction.setRole(TccRoleEnum.PROVIDER.getCode());
transaction.setStatus(TccActionEnum.PRE_TRY.getCode());
transaction.setTargetClass(clazz.getName());
transaction.setTargetMethod(method.getName());
//保存当前事务信息
coordinatorService.save(transaction);
//传入当前threadLocal
CURRENT.set(transaction);
return transaction;
}
示例13: invoke
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
@Around("@annotation(com.apssouza.monitoring.Monitored)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("callend");
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
if (this.enabled) {
StopWatch sw = new StopWatch(joinPoint.toShortString());
sw.start("invoke");
try {
return joinPoint.proceed();
} finally {
sw.stop();
synchronized (this) {
this.callCount++;
this.accumulatedCallTime += sw.getTotalTimeMillis();
}
publisher.publishEvent(new MonitoringInvokedEvent(
method.getName(),
this.accumulatedCallTime
));
}
} else {
return joinPoint.proceed();
}
}
示例14: logPreExecutionData
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
public void logPreExecutionData(
@Nonnull ProceedingJoinPoint proceedingJoinPoint,
@Nullable RequestMapping methodRequestMapping) {
MethodSignature methodSignature = (MethodSignature)proceedingJoinPoint.getSignature();
String methodName = methodSignature.getName() + "()";
Object argValues[] = proceedingJoinPoint.getArgs();
String argNames[] = methodSignature.getParameterNames();
String requestContext = RequestUtil.getRequestContext().toString();
Annotation annotations[][] = methodSignature.getMethod().getParameterAnnotations();
StringBuilder preMessage = new StringBuilder().append(methodName);
if (argValues.length > 0) {
logFunctionArguments(argNames, argValues, preMessage, annotations, methodRequestMapping);
}
preMessage.append(" called via ").append(requestContext);
LOG.info(preMessage.toString());
}
示例15: getQueueNames
import org.aspectj.lang.reflect.MethodSignature; //导入依赖的package包/类
/**
* Get queues names separated with comma from {@link RabbitListener} annotation.
*
* @param call Call
* @return Queues names
*/
private String[] getQueueNames(ProceedingJoinPoint call) {
final MethodSignature signature = (MethodSignature) call.getSignature();
final Method method = signature.getMethod();
final RabbitListener rabbitListenerAnnotation = method.getAnnotation(RabbitListener.class);
return rabbitListenerAnnotation.queues();
}