當前位置: 首頁>>代碼示例>>Java>>正文


Java ProceedingJoinPoint.getSignature方法代碼示例

本文整理匯總了Java中org.aspectj.lang.ProceedingJoinPoint.getSignature方法的典型用法代碼示例。如果您正苦於以下問題:Java ProceedingJoinPoint.getSignature方法的具體用法?Java ProceedingJoinPoint.getSignature怎麽用?Java ProceedingJoinPoint.getSignature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.aspectj.lang.ProceedingJoinPoint的用法示例。


在下文中一共展示了ProceedingJoinPoint.getSignature方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: around

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("dataSourcePointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
    MethodSignature signature = (MethodSignature) point.getSignature();
    Method method = signature.getMethod();

    DataSource ds = method.getAnnotation(DataSource.class);
    if (ds == null) {
        DynamicDataSource.setDataSource(DataSourceNames.FIRST);
        log.debug("set datasource is " + DataSourceNames.FIRST);
    } else {
        DynamicDataSource.setDataSource(ds.name());
        log.debug("set datasource is " + ds.name());
    }

    try {
        return point.proceed();
    } finally {
        DynamicDataSource.clearDataSource();
        log.debug("clean datasource");
    }
}
 
開發者ID:davichi11,項目名稱:my-spring-boot-project,代碼行數:22,代碼來源:DataSourceAspect.java

示例2: 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;
}
 
開發者ID:Zweihui,項目名稱:Aurora,代碼行數:19,代碼來源:TimeLogAspect.java

示例3: invoke

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Override
public Object invoke(String transactionGroupId, ProceedingJoinPoint point) throws Throwable {
    MethodSignature signature = (MethodSignature) point.getSignature();
    Method method = signature.getMethod();
    Class<?> clazz = point.getTarget().getClass();
    Object[] args = point.getArgs();
    Method thisMethod = clazz.getMethod(method.getName(), method.getParameterTypes());

    final String compensationId = CompensationLocal.getInstance().getCompensationId();

    final TxTransaction txTransaction = method.getAnnotation(TxTransaction.class);

    final int waitMaxTime = txTransaction.waitMaxTime();

    final PropagationEnum propagation = txTransaction.propagation();

    TransactionInvocation invocation = new TransactionInvocation(clazz, thisMethod.getName(), args, method.getParameterTypes());
    TxTransactionInfo info = new TxTransactionInfo(invocation,transactionGroupId,compensationId,waitMaxTime,propagation);
    final Class c = txTransactionFactoryService.factoryOf(info);
    final TxTransactionHandler txTransactionHandler =
            (TxTransactionHandler) SpringBeanUtils.getInstance().getBean(c);
    return txTransactionHandler.handler(point, info);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:24,代碼來源:AspectTransactionServiceImpl.java

示例4: aroundJoinPoint

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的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

示例5: constructorAnnotated

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的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: constructorAnnotated

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("methodAnnotated() || constructorAnnotated()")
public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    String className = methodSignature.getDeclaringType().getSimpleName();
    String methodName = methodSignature.getName();
    long startTime = System.nanoTime();
    Object result = joinPoint.proceed();//執行原方法
    long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);

    Logger.d("TimeLog: 類 " + className + " 方法 " + methodName + " 耗時 [" + cost + "ms]");
    /*Log.d("timeLog", "====================方法耗時檢測====================");
    Log.d("timeLog", "= 類名 : " + className);
    Log.d("timeLog", "= 方法名: " + methodName);
    Log.d("timeLog", "= 耗時 : [" + cost + "ms]");
    Log.d("timeLog", "====================================================");*/
    return result;
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:18,代碼來源:TimeLogAspect.java

示例7: args

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
/**
 * 遷移狀態過程鎖定
 *
 * @param pjp 切點
 * @param ctx 上下文
 * @return 原返回值
 */
@Around(value = "execution(* telemarketer.skittlealley.service.game.DrawGuess.process*(..))  && args(ctx)",
        argNames = "pjp,ctx")
public Object lockContext(ProceedingJoinPoint pjp, DrawGuessContext ctx) {
    ctx.lock();
    try {
        return pjp.proceed();
    } catch (Throwable e) {
        LOGGER.error("你畫我猜狀態遷移異常,即將恢複初始狀態,ctx:{}", JSONObject.toJSONString(ctx), e);
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        if (StringUtils.equals(signature.getName(), "processToReady")) {
            LOGGER.error("嚴重錯誤,遊戲無法恢複初始狀態。即將退出");
            throw new IllegalStateException(e);
        }
        return service.processToReady(ctx);
    } finally {
        ctx.unlock();
    }
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:26,代碼來源:DrawGuessAspect.java

示例8: before

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的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();
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:25,代碼來源:TokenAspect.java

示例9: begin

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
public MythTransaction begin(ProceedingJoinPoint point) {
    LogUtil.debug(LOGGER, () -> "開始執行Myth分布式事務!start");
    MythTransaction mythTransaction = getCurrentTransaction();
    if (Objects.isNull(mythTransaction)) {

        MethodSignature signature = (MethodSignature) point.getSignature();
        Method method = signature.getMethod();

        Class<?> clazz = point.getTarget().getClass();

        mythTransaction = new MythTransaction();
        mythTransaction.setStatus(MythStatusEnum.BEGIN.getCode());
        mythTransaction.setRole(MythRoleEnum.START.getCode());
        mythTransaction.setTargetClass(clazz.getName());
        mythTransaction.setTargetMethod(method.getName());
    }
    //保存當前事務信息
    coordinatorCommand.execute(new CoordinatorAction(CoordinatorActionEnum.SAVE, mythTransaction));

    //當前事務保存到ThreadLocal
    CURRENT.set(mythTransaction);

    //設置tcc事務上下文,這個類會傳遞給遠端
    MythTransactionContext context = new MythTransactionContext();

    //設置事務id
    context.setTransId(mythTransaction.getTransId());

    //設置為發起者角色
    context.setRole(MythRoleEnum.START.getCode());

    TransactionContextLocal.getInstance().set(context);

    return mythTransaction;

}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:37,代碼來源:MythTransactionManager.java

示例10: methodLoggingNotDisabledPointcut

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("allPublicControllerMethodsPointcut() "
        + "&& methodLoggingNotDisabledPointcut() "
        + "&& methodOrClassLoggingEnabledPointcut()")
@Nullable
public Object log(@Nonnull ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object result = null;
    String returnType = null;
    RequestMapping methodRequestMapping = null;
    RequestMapping classRequestMapping = null;

    try {
        MethodSignature methodSignature = (MethodSignature)proceedingJoinPoint.getSignature();
        methodRequestMapping = methodSignature.getMethod().getAnnotation(RequestMapping.class);
        classRequestMapping = proceedingJoinPoint.getTarget().getClass().getAnnotation(RequestMapping.class);

        // this is required to distinguish between a returned value of null and no return value, as in case of
        // void return type.
        returnType = methodSignature.getReturnType().getName();

        logPreExecutionData(proceedingJoinPoint, methodRequestMapping);
    } catch (Exception e) {
        LOG.error("Exception occurred in pre-proceed logic", e);
    }

    StopWatch timer = new StopWatch();
    try {
        timer.start();
        result = proceedingJoinPoint.proceed();
    } finally {
        timer.stop();
        if (returnType != null) {
            logPostExecutionData(
                    proceedingJoinPoint, timer, result, returnType, methodRequestMapping, classRequestMapping
            );
        }
    }

    return result;
}
 
開發者ID:harshilsharma63,項目名稱:controller-logger,代碼行數:40,代碼來源:GenericControllerAspect.java

示例11: DefaultRequestCacheKey

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
public DefaultRequestCacheKey(ProceedingJoinPoint point) throws NoSuchMethodException {
    Object[] args = point.getArgs();

    Signature signature = point.getSignature();
    if (!(signature instanceof MethodSignature)) {
        throw new IllegalArgumentException("該注解隻能用於方法");
    }
    MethodSignature methodSignature = (MethodSignature) signature;
    Object target = point.getTarget();
    Method currentMethod = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());

    clazzKey = currentMethod.getDeclaringClass().getName();
    methodKey = currentMethod.getName();
    Class[] parameterTypes = methodSignature.getParameterTypes();
    StringBuilder builderParamKey = new StringBuilder();
    StringBuilder builderValueKey = new StringBuilder();
    if (parameterTypes != null) {
        for (int i = 0; i < parameterTypes.length; i++) {
            if (i != 0) {
                builderParamKey.append("#");
                builderValueKey.append("#");
            }
            builderParamKey.append(parameterTypes[i].getName());
            builderValueKey.append(args[i]);
        }
    }
    paramKey = builderParamKey.toString();
    valueKey = builderValueKey.toString();
}
 
開發者ID:ling49043171,項目名稱:mark-framework,代碼行數:30,代碼來源:DefaultRequestCacheKey.java

示例12: retry

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("@annotation(com.wise.core.aop.annotation.RetriableTransaction)")
public Object retry(ProceedingJoinPoint pjp) throws Throwable {
	MethodSignature signature = (MethodSignature) pjp.getSignature();
	Method method = signature.getMethod();
	RetriableTransaction annotation = method.getAnnotation(RetriableTransaction.class);
	int maxAttempts = annotation.maxRetries();
	int attemptCount = 0;
	List<Class<? extends Throwable>> exceptions = Arrays.asList(annotation.retryFor());
	Throwable failure = null;
	TransactionStatus currentTransactionStatus = null;
	String businessName = pjp.getTarget().toString();
	businessName = businessName.substring(0, businessName.lastIndexOf("@")) + "." + method.getName();
	do {
		attemptCount++;
		try {
			DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
			transactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
			currentTransactionStatus = transactionManager.getTransaction(transactionDefinition);
			Object returnValue = pjp.proceed();
			transactionManager.commit(currentTransactionStatus);
			return returnValue;
		} catch (Throwable t) {
			if (!exceptions.contains(t.getClass())) {
				throw t;
			}
			if (currentTransactionStatus != null && !currentTransactionStatus.isCompleted()) {
				transactionManager.rollback(currentTransactionStatus);
				failure = t;
			}
			LOGGER.debug("事務重試:["+businessName+":"+attemptCount+"/"+maxAttempts+"]");
		}
	} while (attemptCount < maxAttempts);
	LOGGER.debug("事務重試:["+businessName+":已達最大重試次數]");
	throw failure;
}
 
開發者ID:onsoul,項目名稱:os,代碼行數:36,代碼來源:RetriableTransactionInterceptor.java

示例13: constructors

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("methods() || constructors()")
public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    String className = methodSignature.getDeclaringType().getSimpleName();
    String methodName = methodSignature.getName();

    Assertions.assertMainThread();

    return joinPoint.proceed();
}
 
開發者ID:jaggernod,項目名稱:threatasserter,代碼行數:11,代碼來源:MainThreadAspect.java

示例14: invoke

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
    boolean profilerSwitch = ProfilerSwitch.getInstance().isOpenProfilerTree();
    if (!profilerSwitch) {
        return pjp.proceed();
    }
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    String clazzName = pjp.getTarget().toString();
    Method method = methodSignature.getMethod();
    String methodName = this.getClassAndMethodName(clazzName, method);
    if (null == methodName) {
        return pjp.proceed();
    }
    try {
        if (Profiler.getEntry() == null) {
            Profiler.start(methodName);
        } else {
            Profiler.enter(methodName);
        }
        return pjp.proceed();
    } catch (Throwable e) {
        warnLog.warn("profiler " + methodName + " error");
        throw e;
    } finally {
        Profiler.release();
        //當root entry為狀態為release的時候,打印信息,並做reset操作
        Profiler.Entry rootEntry = Profiler.getEntry();
        if (rootEntry != null) {
            if (rootEntry.isReleased()) {
                long duration = rootEntry.getDuration();
                if (duration > ProfilerSwitch.getInstance().getInvokeTimeout()) {
                    profilerLogger.info("\n" + Profiler.dump() + "\n");
                    metricsLogger.info("\n" + Profiler.metrics() + "\n");
                }
                Profiler.reset();
            }
        }
    }
}
 
開發者ID:minotaursu,項目名稱:profilerAop,代碼行數:39,代碼來源:ProfilerAspectAop.java

示例15: execute

import org.aspectj.lang.ProceedingJoinPoint; //導入方法依賴的package包/類
@Around("execution(org.gra4j.dataMigration.utils.web.Response org.gra4j.dataMigration.controller..*.*(..)) "
        + " and @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object execute(ProceedingJoinPoint pjp) throws Throwable {
    // 從切點上獲取目標方法
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();
    // 若目標方法忽略了安全性檢查,則直接調用目標方法
    if (method.isAnnotationPresent(UnCheck.class))
        return pjp.proceed();

    HttpServletRequest request = WebContext.getRequest();
    String userName = ((SecurityContextImpl) request.getSession()
                                                    .getAttribute("SPRING_SECURITY_CONTEXT"))
                                                    .getAuthentication()
                                                    .getName();

    if (StringUtils.isEmpty(tokenName))
        tokenName = DEFAULT_TOKEN_NAME;

    // 從 request header 中獲取當前 token
    String token = request.getHeader(tokenName);
    // 檢查 token 有效性
    if (!tokenManager.checkToken(tokenName+"-"+userName,token)) {
        String message = String.format("token [%s] is invalid", token);
        throw new TokenException(message);
    }
    // 調用目標方法
    Object result = pjp.proceed();
    tokenManager.removeToke(tokenName+"-"+userName);
    return result;
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:32,代碼來源:TokenAspect.java


注:本文中的org.aspectj.lang.ProceedingJoinPoint.getSignature方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。