本文整理汇总了Java中org.aspectj.lang.Signature.toShortString方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.toShortString方法的具体用法?Java Signature.toShortString怎么用?Java Signature.toShortString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.aspectj.lang.Signature
的用法示例。
在下文中一共展示了Signature.toShortString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: entering
import org.aspectj.lang.Signature; //导入方法依赖的package包/类
/**
* @param joinPoint Counts the invocation for the given joinPoint
*/
public static synchronized void entering(JoinPoint joinPoint) {
final Signature signature = joinPoint.getSignature();
final String methodName = signature.toShortString();
Integer invocedTimes = invoctions.get(methodName);
if(invocedTimes == null) {
invoctions.put(methodName, 1);
} else {
int i = invocedTimes.intValue();
invoctions.put(methodName, ++i);
}
}
示例3: log
import org.aspectj.lang.Signature; //导入方法依赖的package包/类
/**
* Advice that will be executed around each join point that has been selected by the
* 'loggingPointcut()' pointcut. This advice will log the entry, exit of the joint put
* including the available contextual information.
* @param call exposes the proceed(..) method in order to support around advice in @AJ aspects
* @return the method return value
* @throws Throwable any throwable thrown by the execution
*/
@Pointcut("be.gerard.common.aop.PointCutLibrary.springServiceOperation()")
public Object log(final ProceedingJoinPoint call) throws Throwable {
// Get the logger that handles the target instance of the method execution.
Signature signature = call.getSignature();
Logger logger = LogManager.getLogger(signature.getDeclaringType());
// This aspect is only valid for method calls
if (!(signature instanceof MethodSignature)) {
throw new IllegalArgumentException("call not valid [method call expected]");
}
MethodSignature methodSignature = (MethodSignature) signature;
// Compute the method information
String methodName = signature.toShortString();
String targetName = signature.getDeclaringTypeName();
Type returnType = methodSignature.getReturnType();
// AspectJ compiler has to be used to retrieve the parameter names
//String[] pp = methodSignature.getParameterNames();
// Compute the method parameters and trace the method entry
if (logger.isInfoEnabled()) {
logger.info(signature.toLongString());
logger.info(String.format("Invoke method [%s] on service [%s]", methodName, targetName));
Object[] parameterValues = call.getArgs();
String[] parameterNames = new String[parameterValues.length];
if ((methodSignature.getParameterNames() != null) && methodSignature.getParameterNames().length == parameterNames.length) {
parameterNames = methodSignature.getParameterNames();
}
for (int i = 0; i < parameterValues.length; i++) {
String parameterName = (parameterNames[i] == null ? String.valueOf(i) : parameterNames[i]);
String parameterValue;
if ((parameterValues[i] instanceof byte[]) && (parameterValues[i] != null)) {
parameterValue = String.format("byte array length [%s]", ((byte[]) parameterValues[i]).length);
} else {
parameterValue = String.valueOf(parameterValues[i]);
}
logger.info(String.format("|---parameter [%s] = [%s]", parameterName, parameterValue));
}
}
// Prepare a StopWath for computing the method statistic
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
String methodStatus = "SUCCESSFULLY";
Object methodResult = null;
try {
// Proceed with the next advice or target method invocation
methodResult = call.proceed();
return methodResult;
} catch (Exception throwable) {
logger.info(String.format("Method [%s] raised the following exception :\n%s.", methodName, String.valueOf(throwable)));
methodStatus = "UNSUCCESSFULLY";
throw throwable;
} finally {
stopWatch.stop();
final long millis = stopWatch.getTotalTimeMillis();
if (logger.isInfoEnabled()) {
if (returnType != null) {
logger.info(String.format("|---parameter [return]= [%s]", String.valueOf(methodResult)));
}
logger.info(String.format("Method [%s] on service [%s] %s invoked in %s milliseconds.", methodName, targetName, methodStatus, millis));
}
}
}
示例4: handleException
import org.aspectj.lang.Signature; //导入方法依赖的package包/类
@AfterThrowing(pointcut = "be.gerard.common.aop.PointCutLibrary.springServiceOperation()", throwing = "exception")
public void handleException(final JoinPoint call, final Throwable exception) throws Throwable {
if (exception instanceof BusinessException) {
throw exception;
}
// Get the logger that handles the target instance of the method execution.
Signature signature = call.getSignature();
Logger logger = LogManager.getLogger(signature.getDeclaringType());
MethodSignature methodSignature = (MethodSignature) signature;
// Compute the method information
String methodName = signature.toShortString();
String targetName = signature.getDeclaringTypeName();
Type returnType = methodSignature.getReturnType();
// Compute the method parameters and prepare the exception context
Map<String, String> exceptionContext = new LinkedHashMap<>();
exceptionContext.put("request", call.getSignature().toLongString());
exceptionContext.put("service name", targetName);
exceptionContext.put("method name", methodName);
if (returnType != null) {
exceptionContext.put("return parameter", String.valueOf(returnType.getClass().getCanonicalName()));
}
// AspectJ compiler has to be used to retrieve the parameter names
Object[] parameterValues = call.getArgs();
String[] parameterNames = new String[parameterValues.length];
if ((methodSignature.getParameterNames() != null) && methodSignature.getParameterNames().length == parameterNames.length) {
parameterNames = methodSignature.getParameterNames();
}
for (int i = 0; i < parameterValues.length; i++) {
String parameterName = (parameterNames[i] == null ? String.valueOf(i) : parameterNames[i]);
exceptionContext.put(String.format("method parameter [%s]", parameterName), String.valueOf(parameterValues[i]));
}
// Prepare the contextual exception to be logged.
String exceptionText = "An unexpected error was encountered while processing the service request.";
ContextualException contextualException = new ContextualException(exceptionText, exception, exceptionContext);
// Log the exception
logger.error(contextualException.toString());
// Throw the technical exception with the facadeException id.
throw new TechnicalException(exceptionText, technicalError, String.format("#%s", contextualException.getId()));
}