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


Java Signature類代碼示例

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


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

示例1: handlerLoginLog

import org.aspectj.lang.Signature; //導入依賴的package包/類
/**
 * 處理登陸日誌
 * @param joinPoint
 * @param proceed
 */
private void handlerLoginLog(ProceedingJoinPoint joinPoint,Object proceed) {
	Signature signature = joinPoint.getSignature();
	//是登陸操作
	if(signature.getDeclaringTypeName().equals("com.lovecws.mumu.system.controller.system.index.SysLoginController")&&signature.getName().equals("logining")){
		//登陸成功
		if(proceed instanceof ModelAndView){
			ModelAndView modelAndView=(ModelAndView)proceed;
			Map<String, Object> model = modelAndView.getModel();
			Object code = model.get("code");
			if(code!=null&&"200".equals(code.toString())){
				messageHandler.handler();
			}
		}
	}
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:21,代碼來源:SysLogRecoderAspect.java

示例2: monitorElapsedTime

import org.aspectj.lang.Signature; //導入依賴的package包/類
/**
 * Monitor the elapsed time of method on controller layer, in
 * order to detect performance problems as soon as possible.
 * If elapsed time > 1 s, log it as an error. Otherwise, log it
 * as an info.
 */
@Around("controllerLayer()")
public Object monitorElapsedTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // Timing the method in controller layer
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Object result = proceedingJoinPoint.proceed();
    stopWatch.stop();

    // Log the elapsed time
    double elapsedTime = stopWatch.getTime() / 1000.0;
    Signature signature = proceedingJoinPoint.getSignature();
    String infoString = "[" + signature.toShortString() + "][Elapsed time: " + elapsedTime + " s]";
    if (elapsedTime > 1) {
        log.error(infoString + "[Note that it's time consuming!]");
    } else {
        log.info(infoString);
    }

    // Return the result
    return result;
}
 
開發者ID:ustcwudi,項目名稱:springboot-seed,代碼行數:28,代碼來源:PerformanceMonitor.java

示例3: LogToDB

import org.aspectj.lang.Signature; //導入依賴的package包/類
@AfterThrowing(throwing = "ex", pointcut = "execution(* com.github.izhangzhihao.SSMSeedProject.*.*.*(..)))")
public void LogToDB(JoinPoint joinPoint, Throwable ex) {
    //出錯行
    int lineNumber = ex.getStackTrace()[0].getLineNumber();
    //方法簽名
    Signature signature = joinPoint.getSignature();
    //參數
    Object[] args = joinPoint.getArgs();
    //拚接參數
    StringBuilder argString = new StringBuilder();
    if (args.length > 0)
        for (Object arg : args)
            argString.append(arg);
    ex.printStackTrace();
    log.error("方法" + signature, "參數" + argString, "錯誤行:" + lineNumber, "時間" + new Date(), "異常內容" + ex.toString());
}
 
開發者ID:izhangzhihao,項目名稱:SSMSeedProject,代碼行數:17,代碼來源:LogAspect.java

示例4: requestMapping

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Around("monitored()")
public Object requestMapping(final ProceedingJoinPoint pcp) throws Throwable {
    Signature signature = pcp.getSignature();
    if (signature instanceof MethodSignature) {
        Method method = ((MethodSignature) signature).getMethod();

        MethodProfiling annotation = AnnotationUtils.findAnnotation(method, MethodProfiling.class);
        if (annotation == null) {
            annotation = AnnotationUtils.findAnnotation(pcp.getTarget().getClass(), MethodProfiling.class);
        }
        if (annotation != null) {
            return traceMethodCall(pcp, annotation.logCallStatistics(), annotation.logMethodCall(), annotation.maxToStringLength());
        }
    }
    return traceMethodCall(pcp);
}
 
開發者ID:Catalysts,項目名稱:cat-boot,代碼行數:17,代碼來源:MethodCallInterceptor.java

示例5: afterMethod

import org.aspectj.lang.Signature; //導入依賴的package包/類
@After("execution(* *..web..*Controller.*(..))")
// 在方法執行之後執行的代碼. 無論該方法是否出現異常
public void afterMethod(JoinPoint jp) {		
	Signature signature = jp.getSignature();
	MethodSignature methodSignature = (MethodSignature) signature;
	Method targetMethod = methodSignature.getMethod();
	//Class<? extends Method> clazz = targetMethod.getClass(); 
	if(record){
		if(targetMethod.getAnnotation(LogAudit.class) != null){
			saveOperateLog(targetMethod);
		}
		else if(baseControllerMethodNames.contains(targetMethod.getName())){
			Method parentMethod = baseControllerMethods.get(targetMethod.getName());
			if(parentMethod.getAnnotation(LogAudit.class) != null){
				saveOperateLog(targetMethod);
			}
		}
	}
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:20,代碼來源:SysOperateInfoAspect.java

示例6: generateCacheKey

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Nullable
private static JoinPointDescription generateCacheKey(ProceedingJoinPoint proceedingJoinPoint) {
    String className;
    String returnType;
    String methodName;

    Signature signature = proceedingJoinPoint.getSignature();
    if (signature instanceof MethodSignature) {
        MethodSignature methodSignature = (MethodSignature) signature;
        returnType = methodSignature.getReturnType().getCanonicalName();
        methodName = methodSignature.getName();
        className = methodSignature.getDeclaringTypeName();
    } else {
        return null;
    }

    return new JoinPointDescription(className, methodName, returnType, proceedingJoinPoint.getArgs());
}
 
開發者ID:deezer,項目名稱:Counsel,代碼行數:19,代碼來源:CacheableAspect.java

示例7: args

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Around("set(* (@com.lib.logthisannotations.annotation.LogThisClassFields *) . *) && args(newVal) && target(t) ")
public void aroundSetField(ProceedingJoinPoint jp, Object t, Object newVal) throws Throwable{
    Logger logger = Logger.getInstance();
    if(logger != null) {
        Signature signature = jp.getSignature();
        String fieldName = signature.getName();
        Field field = t.getClass().getDeclaredField(fieldName);
        field.setAccessible(true);
        Object oldVal = field.get(t);
        LogThisClassFields annotation = t.getClass().getAnnotation(LogThisClassFields.class);
        LoggerLevel loggerLevel = annotation.logger();
        StringBuilder builder = Strings.getStringFieldBuilder(fieldName, String.valueOf(oldVal), String.valueOf(newVal));

        logger.getLoggerInstance().log(t.getClass().getName(), "ClassField " + builder.toString(), loggerLevel, annotation.write());
        jp.proceed();
    }
}
 
開發者ID:luispereira,項目名稱:LogThis,代碼行數:18,代碼來源:LogThisClassFieldAspect.java

示例8: exitMethod

import org.aspectj.lang.Signature; //導入依賴的package包/類
private static void exitMethod(JoinPoint joinPoint, Object result, long lengthMillis) {
  if (!enabled) return;

  Signature signature = joinPoint.getSignature();

  Class<?> cls = signature.getDeclaringType();
  String methodName = signature.getName();
  boolean hasReturnType = signature instanceof MethodSignature
      && ((MethodSignature) signature).getReturnType() != void.class;

  StringBuilder builder = new StringBuilder("\u21E0 ")
      .append(methodName)
      .append(" [")
      .append(lengthMillis)
      .append("ms]");

  if (hasReturnType) {
    builder.append(" = ");
    builder.append(Strings.toString(result));
  }

  // TODO : use a real Logger
  System.out.println(asTag(cls) + " : " + builder.toString());
}
 
開發者ID:fpoyer,項目名稱:Hugo-Spring,代碼行數:25,代碼來源:Hugo.java

示例9: exit

import org.aspectj.lang.Signature; //導入依賴的package包/類
private void exit(JoinPoint joinPoint, Object result, StringBuilder builder) {
  if (!enabled) return;

  Signature signature = joinPoint.getSignature();

  Class<?> cls = signature.getDeclaringType();
  boolean hasReturnType = signature instanceof MethodSignature
      && ((MethodSignature) signature).getReturnType() != void.class;

  if (hasReturnType) {
    builder.append(" \u21a6 ");
    builder.append(Strings.toString(result));
  }

  Log.v(asTag(cls), builder.toString());
}
 
開發者ID:pt2121,項目名稱:MarbledCat,代碼行數:17,代碼來源:MarbledCat.java

示例10: checkBatchSize

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Before("methodWithBatchSizeCheck()")
public void checkBatchSize(JoinPoint joinPoint) throws NoSuchMethodException {
    Signature signature = joinPoint.getSignature();
    if (!(signature instanceof MethodSignature)) {
        return;
    }
    // must use target since the annotation is annotated on the impl, not api
    Method method = joinPoint.getTarget().getClass().getMethod(signature.getName(),
            ((MethodSignature) signature).getParameterTypes());
    if (method == null || !method.isAnnotationPresent(RestrictBatchSize.class)) {
        return;
    }
    RestrictBatchSize restrictBatchSize = method.getAnnotation(RestrictBatchSize.class);
    int paramIndex = restrictBatchSize.paramIndex();
    if (paramIndex < 0) {
        return;
    }
    int batchSize = (Integer) (joinPoint.getArgs())[paramIndex];
    checkArgument(batchSize <= ConstantsUtil.MaxBatchSize(), String.format("Batch size(%d) exceeds max allowed size: %d", batchSize, ConstantsUtil.MaxBatchSize()));
}
 
開發者ID:nobodyiam,項目名稱:java-web-bootstrap,代碼行數:21,代碼來源:BatchSizeAspect.java

示例11: trackFragmentView

import org.aspectj.lang.Signature; //導入依賴的package包/類
public static void trackFragmentView(JoinPoint joinPoint, Object result) {
    try {
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method targetMethod = methodSignature.getMethod();

        if (targetMethod == null) {
            return;
        }

        //Fragment名稱
        String fragmentName = joinPoint.getTarget().getClass().getName();

        if (result instanceof ViewGroup) {
            traverseView(fragmentName, (ViewGroup) result);
        } else if (result instanceof View) {
            View view = (View) result;
            view.setTag(R.id.sensors_analytics_tag_view_fragment_name, fragmentName);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:sensorsdata,項目名稱:sa-sdk-android,代碼行數:24,代碼來源:SensorsDataRuntimeBridge.java

示例12: testLogAfterThrowing

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Test
public void testLogAfterThrowing() {
  // Arrange
  JoinPoint joinPoint = Mockito.mock(JoinPoint.class);
  Signature signature = Mockito.mock(Signature.class);
  when(joinPoint.getSignature()).thenReturn(signature);
  when(signature.getDeclaringTypeName()).thenReturn("Declaring Type Name");
  when(signature.getName()).thenReturn("Name");
  Exception exception = Mockito.mock(Exception.class);
  when(exception.getCause()).thenReturn(Mockito.mock(Throwable.class));

  // Act
  this.loggingAspect.logAfterThrowing(joinPoint, exception);

  // Assert
  assertThat(this.loggingAspect, not(nullValue()));
}
 
開發者ID:dzhw,項目名稱:metadatamanagement,代碼行數:18,代碼來源:LoggingAspectTest.java

示例13: logAround

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
  Signature signature = joinPoint.getSignature();
  if (log.isDebugEnabled()) {
    log.debug("Enter: {}.{}() with argument[s] = {}", signature.getDeclaringTypeName(), signature.getName(), Arrays.toString(joinPoint.getArgs()));
  }
  try {
    Object result = joinPoint.proceed();
    if (log.isDebugEnabled()) {
      log.debug("Exit: {}.{}() with result = {}", signature.getDeclaringTypeName(), signature.getName(), result);
    }
    return result;
  } catch (IllegalArgumentException e) {
    log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), signature.getDeclaringTypeName(), signature.getName());
    throw e;
  }
}
 
開發者ID:priitl,項目名稱:p2p-webtv,代碼行數:18,代碼來源:LoggingAspect.java

示例14: testDetermineDelay

import org.aspectj.lang.Signature; //導入依賴的package包/類
@Test
public void testDetermineDelay() throws Exception {
    BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
    when(loader.getSahiProxyProperties().getRequestDelayMs()).thenReturn(500);
    loader.getActionProperties().setTypeDelay(0.05);

    JoinPoint joinPoint = mock(JoinPoint.class);
    Signature signature = mock(Signature.class);
    when(joinPoint.getSignature()).thenReturn(signature);
    when(signature.getName()).thenReturn("pasteSomething");
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 500);

    when(signature.getName()).thenReturn("typeMasked");
    when(joinPoint.getArgs()).thenReturn(new String[]{"1", "MOD"});
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 550);

    when(joinPoint.getArgs()).thenReturn(new String[]{"12characters", "MOD"});
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 12 * 550);
}
 
開發者ID:ConSol,項目名稱:sakuli,代碼行數:20,代碼來源:ModifySahiTimerAspectTest.java

示例15: getAnnotation

import org.aspectj.lang.Signature; //導入依賴的package包/類
private static Annotation getAnnotation(final Signature signature,
                            final Class<? extends Annotation> annotationClass) {
    if (signature instanceof ConstructorSignature) {
        final Constructor<?> ctor = ConstructorSignature.class.cast(signature)
                                .getConstructor();
        return ctor.getAnnotation(annotationClass);
    } else if (signature instanceof MethodSignature) {
        return MethodSignature.class.cast(signature)
                .getMethod()
                .getAnnotation(annotationClass);
    } else if (signature instanceof FieldSignature) {
        return FieldSignature.class.cast(signature)
                .getField()
                .getAnnotation(annotationClass);
    }

    throw new RuntimeException(
            "Unsupported signature type " + signature.getClass().getName()
        );
}
 
開發者ID:cardillo,項目名稱:joinery,代碼行數:21,代碼來源:Metrics.java


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