当前位置: 首页>>代码示例>>Java>>正文


Java Around类代码示例

本文整理汇总了Java中org.aspectj.lang.annotation.Around的典型用法代码示例。如果您正苦于以下问题:Java Around类的具体用法?Java Around怎么用?Java Around使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Around类属于org.aspectj.lang.annotation包,在下文中一共展示了Around类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cacheMonitor

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("execution(* org.packt.aop.transaction.dao.impl.EmployeeDaoImpl.getEmployees(..))")
public Object cacheMonitor(ProceedingJoinPoint joinPoint) throws Throwable  {
   logger.info("executing " + joinPoint.getSignature().getName());
   Cache cache = cacheManager.getCache("employeesCache");
  
   logger.info("cache detected is  " + cache.getName());
   logger.info("begin caching.....");
   String key = joinPoint.getSignature().getName();
   logger.info(key);
   if(cache.get(key) == null){
	   logger.info("caching new Object.....");
	   Object result = joinPoint.proceed();
	   cache.put(new Element(key, result)); 	   
	   return result;
   }else{
	   logger.info("getting cached Object.....");
	   return cache.get(key).getObjectValue();
   }
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:20,代码来源:CacheListenerAspect.java

示例2: aroundTemplateRead

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("readDao()") 
public Object aroundTemplateRead(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
    ReadWriteSplittingDataSourceHolder.setReadDataSource();
    Object processResult = null;
    //需要先定位是哪个DataSourceGroupId的
    //设置为读状态
    processResult = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
    return processResult;
}
 
开发者ID:devpage,项目名称:sharding-quickstart,代码行数:10,代码来源:SqlSessionTemplateAdvice.java

示例3: advise

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("execution(@org.apache.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
  String spanName = spanAnnotation.spanName();
  String callPath = spanAnnotation.callPath();
  Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
  LOG.debug("Generating zipkin span for method {}", method.toString());
  if ("".equals(spanName)) {
    spanName = method.getName();
  }
  if ("".equals(callPath)) {
    callPath = method.toString();
  }

  return adviser.invoke(spanName, callPath, joinPoint::proceed);

}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:ZipkinSpanAspect.java

示例4: updateAnswerResult

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("execution( * com.way.learning.service..*ServiceImpl.checkAnswer(..))")
public Object updateAnswerResult(ProceedingJoinPoint pjp) throws Throwable{
	System.out.println(pjp.getSignature().getName()+"() target method call....");
	Member mvo=(Member)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	Object[ ] params=pjp.getArgs();
	int questionNo=Integer.parseInt(params[0].toString());
	String userId=mvo.getUserId();
	answerService.updatePostCntSubmit(questionNo);
	answerService.updateMyCntSubmit(questionNo,userId );
	Object result= pjp.proceed();
		if(result.toString().equals("1") ){
			answerService.updatePostCntRight(questionNo);
			answerService.updateMyCntRight(questionNo,userId );
		}else answerService.updateMyCntWrong(questionNo, userId );	
		
	return result;
}
 
开发者ID:INSUPARK83,项目名称:way_learning,代码行数:18,代码来源:AnswerAspect.java

示例5: constructorAnnotated

import org.aspectj.lang.annotation.Around; //导入依赖的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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:TimeLogAspect.java

示例6: aroundJoinPoint

import org.aspectj.lang.annotation.Around; //导入依赖的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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:MemoryCacheAspect.java

示例7: traceAroundRepositoryMethods

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
/**
 * @param pjp the proceeding join point
 * @return the result of the method being wrapped
 * @throws Throwable
 */
@Around("springRepositories()")
public Object traceAroundRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable {
    logger.trace("Advising repository");
    boolean hasClassAnnotation = false;

    for (Class<?> i : pjp.getTarget().getClass().getInterfaces()) {
        if (i.getAnnotation(XRayEnabled.class) != null) {
            hasClassAnnotation = true;
            break;
        }
    }

    if (hasClassAnnotation) {
        return this.processXRayTrace(pjp);
    } else {
        return XRayInterceptorUtils.conditionalProceed(pjp);
    }
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:24,代码来源:AbstractXRayInterceptor.java

示例8: logAround

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
/**
 * Advice that logs when a method is entered and exited.
 *
 * @param joinPoint join point for advice
 * @return result
 * @throws Throwable throws IllegalArgumentException
 */
@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:28,代码来源:LoggingAspect.java

示例9: invokeWithCatTransaction

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("anyRepositoryMethod()")
public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
  String name =
      joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature()
          .getName();
  Transaction catTransaction = Tracer.newTransaction("SQL", name);
  try {
    Object result = joinPoint.proceed();
    catTransaction.setStatus(Transaction.SUCCESS);
    return result;
  } catch (Throwable ex) {
    catTransaction.setStatus(ex);
    throw ex;
  } finally {
    catTransaction.complete();
  }
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:RepositoryAspect.java

示例10: handleAnnotation

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("within(@com.minsx.spring.jpatemplate.Query *)||@annotation(com.minsx.spring.jpatemplate.Query)")
public Object handleAnnotation(ProceedingJoinPoint pjp) throws Throwable {
    System.out.println("--------------");
    Class<? extends Object> invokeClass = pjp.getTarget().getClass();
    String signatureName = pjp.getSignature().getName();
    Method methods[] = invokeClass.getMethods();
    for (Method method : methods) {
        if (method.getName().equals(signatureName)) {
            String paramCollection = method.getAnnotation(Query.class).value();
            LOGGER.info(String.format("Query sql is %s", paramCollection));
            Parameter[] parameters = method.getParameters();
            for (Parameter parameter : parameters) {
                parameter.getName();
            }
        }
    }
    pjp.proceed();
    return new User(1, "goodsavess", "Ss123456", "[email protected]");
}
 
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:20,代码来源:QueryAspect.java

示例11: delPointcut

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("classPointcut() && delPointcut()  && @annotation(mapping)")
public String delEmployee(ProceedingJoinPoint joinPoint,  RequestMapping mapping) throws Throwable{
	   HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	   logger.info("executing " + joinPoint.getSignature().getName());
	   int userId = (Integer)req.getSession().getAttribute("userId");
	   System.out.println("userId" + userId);
	   
	   List<RolePermission> permission = loginServiceImpl.getPermissionSets(userId);
	   if(isAuthroize(permission)){
		   logger.info("user " + userId + " is authroied to delete");
		   joinPoint.proceed();
		   return "menu";
	   }else{
		   logger.info("user " + userId + " is NOT authroied to delete");
		   return "banned";
	   }
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:18,代码来源:DeleteAuthorizeAspect.java

示例12: execute

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
/**
 * 接收到客户端请求时执行
 *
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("controllerAspect()")
public Object execute(ProceedingJoinPoint pjp) throws Throwable {
    // 从切点上获取目标方法
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();
    /**
     * 验证Token
     */
    if (method.isAnnotationPresent(Token.class)) {
        // 从 request header 中获取当前 token
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader(DEFAULT_TOKEN_NAME);
        if (StringUtils.isEmpty(token)) {
            throw new TokenException("客户端X-Token参数不能为空,且从Header中传入,如果没有登录,请先登录获取Token");
        }
        // 检查 token 有效性
        if (!tokenManager.checkToken(token)) {
            String message = String.format("Token [%s] 非法", token);
            throw new TokenException(message);
        }
    }

    // 调用目标方法
    return pjp.proceed();
}
 
开发者ID:melonlee,项目名称:LazyREST,代码行数:33,代码来源:SecurityAspect.java

示例13: doConcurrentOperation

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("retryOnOptFailure()")
public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
    int numAttempts = 0;
    do {
        numAttempts++;
        try {
            return pjp.proceed();
        } catch (OptimisticLockingFailureException ex) {
            if (numAttempts > maxRetries) {
                //log failure information, and throw exception
                throw ex;
            } else {
                //log failure information for audit/reference
                //will try recovery
            }
        }
    } while (numAttempts <= this.maxRetries);

    return null;
}
 
开发者ID:Dawn-Team,项目名称:dawn,代码行数:21,代码来源:OptimisticLockingFailureExecutor.java

示例14: constructProcess

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
@Around("constructor()")
public Object constructProcess(ProceedingJoinPoint joinPoint) throws Throwable {
  Object result = joinPoint.proceed();
  Object puppet = joinPoint.getTarget();
  //Only inject the class that marked by Puppet annotation.

  Method onAttach = getRiggerMethod("onPuppetConstructor", Object.class);
  onAttach.invoke(getRiggerInstance(), puppet);
  return result;
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:11,代码来源:FragmentInjection.java

示例15: logBeforeService

import org.aspectj.lang.annotation.Around; //导入依赖的package包/类
/**
 * Aspect for logging before service calls.
 *
 * @param joinPoint joinPoint
 * @return method result
 * @throws Throwable throwable
 */
@SneakyThrows
@Around("servicePointcut() && !excluded()")
public Object logBeforeService(ProceedingJoinPoint joinPoint) {

    StopWatch stopWatch = StopWatch.createStarted();

    try {
        logStart(joinPoint);

        Object result = joinPoint.proceed();

        logStop(joinPoint, result, stopWatch);

        return result;
    } catch (Exception e) {
        logError(joinPoint, e, stopWatch);
        throw e;
    }

}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:28,代码来源:ServiceLoggingAspect.java


注:本文中的org.aspectj.lang.annotation.Around类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。