本文整理汇总了Java中org.aspectj.lang.ProceedingJoinPoint类的典型用法代码示例。如果您正苦于以下问题:Java ProceedingJoinPoint类的具体用法?Java ProceedingJoinPoint怎么用?Java ProceedingJoinPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProceedingJoinPoint类属于org.aspectj.lang包,在下文中一共展示了ProceedingJoinPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructorAnnotated
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的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: around
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
* Invoked around method execution.
*
* @param joinPoint
* @return
* @throws ExecutionException
*/
@Around("execution(* com.catpeds.crawler.jsoup.DocumentRepository.get(String))")
public Object around(ProceedingJoinPoint joinPoint) throws ExecutionException {
final String url = (String) joinPoint.getArgs()[0];
LOGGER.debug("Retrieving document from URL {}", url);
Object result = cache.get(url, new Callable<Object>() {
@Override
public Object call() throws Exception {
LOGGER.debug("Result for URL {} not cached", url);
try {
// invoke the method
return joinPoint.proceed();
} catch (Throwable e) {
throw new Exception(e); // NOSONAR
}
}
});
LOGGER.trace("Result document {}", result);
return result;
}
示例3: updateAnswerResult
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的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;
}
示例4: setArgumentNamesFromStringArray
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
public void setArgumentNamesFromStringArray(String[] args) {
this.argumentNames = new String[args.length];
for (int i = 0; i < args.length; i++) {
this.argumentNames[i] = StringUtils.trimWhitespace(args[i]);
if (!isVariableName(this.argumentNames[i])) {
throw new IllegalArgumentException(
"'argumentNames' property of AbstractAspectJAdvice contains an argument name '" +
this.argumentNames[i] + "' that is not a valid Java identifier");
}
}
if (argumentNames != null) {
if (aspectJAdviceMethod.getParameterTypes().length == argumentNames.length + 1) {
// May need to add implicit join point arg name...
Class<?> firstArgType = aspectJAdviceMethod.getParameterTypes()[0];
if (firstArgType == JoinPoint.class ||
firstArgType == ProceedingJoinPoint.class ||
firstArgType == JoinPoint.StaticPart.class) {
String[] oldNames = argumentNames;
argumentNames = new String[oldNames.length + 1];
argumentNames[0] = "THIS_JOIN_POINT";
System.arraycopy(oldNames, 0, argumentNames, 1, oldNames.length);
}
}
}
}
示例5: hashString
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
*
* 定义String结构的缓存逻辑
* 使用例子:
* [email protected](dataStructure = DataStructure.string, key = "#viewnum", expireTime = 864000)
* public String aaa(String viewnum){.....}
*
*
* @author zhangshaobin
* @created 2014年11月30日 上午2:51:11
*
* @param cache
* @param method
* @param pjp
* @return
* @throws IllegalAccessException
* @throws InstantiationException
*/
@SuppressWarnings({ "rawtypes" })
private Object hashString(Cache cache, Method method, ProceedingJoinPoint pjp) throws InstantiationException,
IllegalAccessException {
int exTime = cache.expireTime();
String key = parseKey(cache.key(), method, pjp.getArgs());
Object result = redisOperations.get(key);
//获取方法返回信息
Class clazz = (Class) method.getGenericReturnType();// 返回类型
Object retObj = clazz.newInstance();
if (retObj instanceof String) { // 判断返回值是不是字符串类型
if (result == null) {
try {
result = pjp.proceed();
Assert.notNull(key, "key 不能为空值!!");
Assert.notNull(result, "key result不能为空值!!");
redisOperations.setex(key, exTime, result.toString());
} catch (Throwable e) {
e.printStackTrace();
}
}
}
return result;
}
示例6: springBeanPointcut
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
* Advice that logs when a method is entered and exited.
*
* @param joinPoint join point for advice
* @return result
* @throws Throwable throws IllegalArgumentException
*/
@Around("applicationPackagePointcut() && springBeanPointcut()")
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;
}
}
示例7: exceptionDeal
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
private Result exceptionDeal(Exception exception, String inputParamInfo, ProceedingJoinPoint pjp) {
XiaLiuException retError;
if (exception instanceof XiaLiuException) {
retError = (XiaLiuException) exception;
} else {
retError = new XiaLiuException(ErrorCode.UNKNOWN_ERROR, ExceptionUtils.getExceptionProfile(exception));
if (inputParamInfo == null) {
String className = pjp.getTarget().getClass().getSimpleName();
String methodName = pjp.getSignature().getName();
Object[] args = pjp.getArgs();
inputParamInfo = this.getInputParamInfo(className, methodName, args);
}
// 打印入参
log.error(inputParamInfo, exception.getMessage());
}
return getResultObj(false, retError.getErrorCode().getCode(), retError.getMessage());
}
示例8: aroundJoinPoint
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
@Around("methodAnnotated()")
public Object aroundJoinPoint(final ProceedingJoinPoint joinPoint) throws Throwable {
if (Looper.myLooper() != Looper.getMainLooper()) {
result = joinPoint.proceed();
} else {
C.doBack(new Runnable() {
@Override
public void run() {
try {
result = joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
});
}
return result;
}
示例9: onOkHttpNew
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
@Around("call(* okhttp3.OkHttpClient+.newCall(..))")
public Object onOkHttpNew(ProceedingJoinPoint joinPoint) throws Throwable {
if (!Configuration.httpMonitorEnable || joinPoint.getArgs().length != 1) {
return joinPoint.proceed();
}
Object[] args = joinPoint.getArgs();
Request request = (Request) args[0];
//url
URL url = request.url().url();
if (GlobalConfig.isExcludeHost(url.getHost())) {
return joinPoint.proceed();
}
RespBean bean = new RespBean();
bean.setUrl(url.toString());
bean.setStartTimestamp(System.currentTimeMillis());
startTimeStamp.add(bean);
return joinPoint.proceed();
}
示例10: after
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
* @param pjp
* @param returnValue
* @param ex
* @param map
* @return
*/
private boolean after(Map<String, Object> map, ProceedingJoinPoint pjp,
Optional<Object> returnValue, Optional<String> ex) {
boolean ok = true;
try {
map.put("argsAfter", converter.objectToJsonString(pjp.getArgs()));
map.put("thisAfter", converter.objectToJsonString(pjp.getThis()));
map.put("targetAfter", converter.objectToJsonString(pjp.getTarget()));
map.put("returnValue", converter.objectToJsonString(returnValue.orNull()));
map.put("exception", ex.orNull());
} catch (Exception e) {
LOG.debug(e);
ok = false;
}
return ok;
}
示例11: actorTransaction
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
public MythTransaction actorTransaction(ProceedingJoinPoint point, MythTransactionContext mythTransactionContext) {
MythTransaction mythTransaction =
buildProviderTransaction(point, mythTransactionContext.getTransId(), MythStatusEnum.BEGIN.getCode());
//保存当前事务信息
coordinatorCommand.execute(new CoordinatorAction(CoordinatorActionEnum.SAVE, mythTransaction));
//当前事务保存到ThreadLocal
CURRENT.set(mythTransaction);
//设置提供者角色
mythTransactionContext.setRole(MythRoleEnum.PROVIDER.getCode());
TransactionContextLocal.getInstance().set(mythTransactionContext);
return mythTransaction;
}
示例12: cacheMethod
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
private Object cacheMethod(final ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Cacheable cacheable = method.getAnnotation(Cacheable.class);
Object result = null;
if (cacheable!=null) {
String key = cacheable.key();
int expiry = cacheable.expiry();
result = joinPoint.proceed();
Cache cache = Cache.get(Utils.getContext());
if (expiry>0) {
cache.put(key,(Serializable)result,expiry);
} else {
cache.put(key,(Serializable)result);
}
} else {
// 不影响原来的流程
result = joinPoint.proceed();
}
return result;
}
示例13: interceptor
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
@Override
public Object interceptor(ProceedingJoinPoint pjp) throws Throwable {
MythTransactionContext mythTransactionContext = TransactionContextLocal.getInstance().get();
if (Objects.nonNull(mythTransactionContext) &&
mythTransactionContext.getRole() == MythRoleEnum.LOCAL.getCode()) {
mythTransactionContext = TransactionContextLocal.getInstance().get();
} else {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = requestAttributes == null ? null : ((ServletRequestAttributes) requestAttributes).getRequest();
String context = request == null ? null : request.getHeader(CommonConstant.MYTH_TRANSACTION_CONTEXT);
if (StringUtils.isNoneBlank(context)) {
mythTransactionContext =
GsonUtils.getInstance().fromJson(context, MythTransactionContext.class);
}
}
return mythTransactionAspectService.invoke(mythTransactionContext, pjp);
}
示例14: generateKey
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
* generate the key based on SPel expression.
*/
protected Object generateKey(String key, ProceedingJoinPoint pjp) throws ExpirableCacheException {
try {
Object target = pjp.getTarget();
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
Object[] allArgs = pjp.getArgs();
if (StringUtils.hasText(key)) {
CacheExpressionDataObject cacheExpressionDataObject = new CacheExpressionDataObject(method, allArgs, target, target.getClass());
EvaluationContext evaluationContext = new StandardEvaluationContext(cacheExpressionDataObject);
SpelExpression spelExpression = getExpression(key, method);
spelExpression.setEvaluationContext(evaluationContext);
return spelExpression.getValue();
}
return keyGenerator.generate(target, method, allArgs);
} catch (Throwable t) {
throw new ExpirableCacheException("### generate key failed");
}
}
示例15: executeIlluminatiByChaosBomber
import org.aspectj.lang.ProceedingJoinPoint; //导入依赖的package包/类
/**
* it is only execute on debug mode and activated chaosBomber.
* can't be use sampling rate.
*
* @param pjp
* @param request
* @return
* @throws Throwable
*/
public Object executeIlluminatiByChaosBomber (final ProceedingJoinPoint pjp, final HttpServletRequest request) throws Throwable {
if (this.isOnIlluminatiSwitch() == false) {
return pjp.proceed();
}
if (IlluminatiTemplateExecutorImpl.illuminatiTemplateIsActive() == false) {
ILLUMINATI_INIT_LOGGER.debug("ignore illuminati processor and the ChaosBomber mode is not effect of sampling rate.");
return pjp.proceed();
}
if (IlluminatiConstant.ILLUMINATI_DEBUG == false) {
return addToQueue(pjp, request, false);
}
return addToQueue(pjp, request, true);
}