本文整理匯總了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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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]");
}
示例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";
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
}