List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.replaceAll(java.lang.CharSequence, java.lang.CharSequence))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeReplaceAllWithCharSequences(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final CharSequence patternCharSequence = (CharSequence) joinPoint.getArgs()[0]; final String patternString = patternCharSequence.toString(); final CharSequence replacement = (CharSequence) joinPoint.getArgs()[1]; final Matcher matcher = matcherFactory.createMatcher(patternString, Pattern.LITERAL); return matcher.reset(target).replaceAll(replacement.toString()); }
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.replace(java.lang.CharSequence, java.lang.CharSequence))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeReplace(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final CharSequence patternCharSequence = (CharSequence) joinPoint.getArgs()[0]; final String patternString = patternCharSequence.toString(); final CharSequence replacement = (CharSequence) joinPoint.getArgs()[1]; final Matcher matcher = matcherFactory.createMatcher(patternString, Pattern.LITERAL); return matcher.reset(target).replaceAll(Matcher.quoteReplacement(replacement.toString())); }
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.replaceFirst(java.lang.String, java.lang.String))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeReplaceFirst(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final String patternString = (String) joinPoint.getArgs()[0]; final String replacement = (String) joinPoint.getArgs()[1]; final Matcher matcher = matcherFactory.createMatcher(patternString); return matcher.reset(target).replaceFirst(replacement); }
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.split(java.lang.String))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeSplit(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final String patternString = (String) joinPoint.getArgs()[0]; final Pattern pattern = patternFactory.createPattern(patternString); return pattern.split(target); }
From source file:org.escidoc.core.aspects.PatternPerformanceAspect.java
License:Open Source License
@Around("call(public java.lang.String java.lang.String.split(java.lang.String, int))" + " && !within(org.escidoc.core.aspects.PatternPerformanceAspect)" + " && !within(org.escidoc.core.util.regex..*)") public Object optimizeSplitWithLimit(final ProceedingJoinPoint joinPoint) { final String target = (String) joinPoint.getTarget(); final String patternString = (String) joinPoint.getArgs()[0]; final Integer limit = (Integer) joinPoint.getArgs()[1]; final Pattern pattern = patternFactory.createPattern(patternString); return pattern.split(target, limit); }
From source file:org.eurekastreams.server.aop.PerformanceTimer.java
License:Apache License
/** * Method for logging timing data.//from w ww . j a va 2 s . c o m * * @param call * {@link ProceedingJoinPoint} * @return result of wrapped method. * @throws Throwable * on error. */ public Object profile(final ProceedingJoinPoint call) throws Throwable { StopWatch clock = null; // get the perf log for target object. Log log = LogFactory.getLog("perf.timer." + call.getTarget().getClass().getCanonicalName()); try { if (log.isInfoEnabled()) { clock = new StopWatch(); clock.start(call.toShortString()); } return call.proceed(); } finally { if (log.isInfoEnabled() && clock != null) { clock.stop(); Object[] args = call.getArgs(); StringBuffer params = new StringBuffer(); for (Object obj : args) { params.append("Param: " + ((obj == null) ? "null" : obj.toString()) + "\n\t"); } log.info(clock.getTotalTimeMillis() + " (ms) - " + call.getTarget().getClass().getSimpleName() + "." + call.getSignature().toShortString() + "\n\t" + params.toString()); } } }
From source file:org.finra.dm.core.StopWatchAdvice.java
License:Apache License
/** * Logs the time it takes to execute the method at the join point if the class or method isn't annotated with SuppressLogging and if the log level is set to * info./* w ww .j a v a2s . co m*/ * * @param pjp the join point. * * @return the return value of the method at the join point. * @throws Throwable if any errors were encountered. */ @SuppressWarnings("rawtypes") public static Object logMethodTime(ProceedingJoinPoint pjp) throws Throwable { // Get the target class being called. Class targetClass = pjp.getTarget().getClass(); // Get the target method being called. MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature(); Method targetMethod = targetMethodSignature.getMethod(); if (targetMethod.getDeclaringClass().isInterface()) { // Get the underlying implementation if we are given an interface. targetMethod = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), targetMethod.getParameterTypes()); } // Only keep a stop watch if the class and method aren't suppressing logging and the log level is info. if ((AnnotationUtils.findAnnotation(targetClass, SuppressLogging.class) == null) && (AnnotationUtils.findAnnotation(targetMethod, SuppressLogging.class) == null) && (LOGGER.isInfoEnabled())) { // Start the stop watch. StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Proceed to the join point (i.e. call the method and let it return). Object returnValue = pjp.proceed(); // Log the duration. LOGGER.info("Method " + targetClass.getName() + "." + targetMethodSignature.getName() + " took " + DmDateUtils.formatDuration(stopWatch.getTime(), true) + "."); // Return the method return value. return returnValue; } else { // Invoke the method normally. return pjp.proceed(); } }
From source file:org.finra.dm.dao.helper.AwsExceptionRetryAdvice.java
License:Apache License
/** * Invokes the method, catches following various exceptions and retries as needed: 1. Throttling exception. 2. 5xx exception. 3. Error codes defined in * configuration to be retried./*from w ww. j av a 2 s. c o m*/ * * @param pjp the join point. * * @return the return value of the method at the join point. * @throws Throwable if any errors were encountered. */ public Object retryOnException(ProceedingJoinPoint pjp) throws Throwable { // Get the method name being invoked. Class<?> targetClass = pjp.getTarget().getClass(); MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature(); String methodName = targetClass.getName() + "." + targetMethodSignature.getName(); // Get the max delay in seconds. long maxTotalDelay = getMaxRetryDelaySecs() * 1000L; // Initialize a retry count to know the number of times we have retried calling the method. int retryCount = 0; // Get the minimum and maximum retry delay. long minAwsDelay = dmStringHelper .getConfigurationValueAsInteger(ConfigurationValue.AWS_MIN_RETRY_DELAY_SECS) * 1000L; long maxAwsDelay = dmStringHelper .getConfigurationValueAsInteger(ConfigurationValue.AWS_MAX_RETRY_DELAY_SECS) * 1000L; StopWatch totalElapsedTimeStopWatch = new StopWatch(); totalElapsedTimeStopWatch.start(); // Loop indefinitely. We will exit the loop if the method returns normally or a non-retryable exception is thrown. // If a retryable exception is thrown, the loop will exit after we have exceeded the maximum retry delay seconds. while (true) { try { // Proceed to the join point (i.e. call the method and let it return normally). return pjp.proceed(); } catch (AmazonServiceException ase) { // Retry if: // 1) Is throttling exception. // 2) Is 5xx exception. // 3) Is an error to be re-tried on as defined in configuration. if (RetryUtils.isThrottlingException(ase) || is5xxException(ase) || isRetryableException(ase)) { long totalElapsedTime = totalElapsedTimeStopWatch.getTime(); // It's a retryable exception. Check if we've retried for enough time. if (totalElapsedTime >= maxTotalDelay) { // We've retried for enough time so re-throw the original exception. LOGGER.warn("An exception occurred while calling " + methodName + ". The method has been retried for " + (totalElapsedTime / 1000.0f) + " second(s) and will not be retried anymore since it would exceed the maximum retry delay." + " The exception will now be thrown."); throw ase; } // Get the next delay. long nextSleepDelay = Math.min(((long) Math.pow(2, retryCount) * minAwsDelay), maxAwsDelay); long timeLeftToRetry = maxTotalDelay - totalElapsedTime; // If time left to try is less than next sleep delay, then use time left as next sleep delay to be retried the last time. if (timeLeftToRetry < nextSleepDelay) { nextSleepDelay = timeLeftToRetry; } // Log a warning so we're aware that we are retrying. LOGGER.warn("A retryable exception occurred while calling " + methodName + ". " + (totalElapsedTime / 1000.0f) + " second(s) have elapsed since initial exception and maximum retry delay is " + (maxTotalDelay / 1000.0f) + " second(s). Will retry in " + (nextSleepDelay / 1000.0f) + " second(s)."); // We can retry again so increment a counter to keep track of the number of times we retried and recalculate the total elapsed time. retryCount++; // Sleep for the next sleep delay. dmThreadHelper.sleep(nextSleepDelay); } else { // It's not a retryable exception (i.e. some other type of service exception) so just re-throw it. throw ase; } } } }
From source file:org.finra.dm.service.helper.CheckAllowedMethodAdvice.java
License:Apache License
/** * Checks whether the requested operation is permitted. * * @param pjp the join point.//from ww w . j a va 2s. co m * * @return the return value of the method at the join point. * @throws Throwable if any errors were encountered. */ @SuppressWarnings("rawtypes") public Object checkNotAllowedMethods(ProceedingJoinPoint pjp) throws Throwable { // Get the method name being invoked. Class targetClass = pjp.getTarget().getClass(); MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature(); String methodName = targetClass.getName() + "." + targetMethodSignature.getName(); dmDaoHelper.checkNotAllowedMethod(methodName); return pjp.proceed(); }
From source file:org.finra.herd.core.StopWatchAdvice.java
License:Apache License
/** * Logs the time it takes to execute the method at the join point if the class or method isn't annotated with SuppressLogging and if the log level is set to * info.//from w w w. j a v a 2s . c o m * * @param pjp the join point. * * @return the return value of the method at the join point. * @throws Throwable if any errors were encountered. */ @SuppressWarnings("rawtypes") public static Object logMethodTime(ProceedingJoinPoint pjp) throws Throwable { // Get the target class being called. Class targetClass = pjp.getTarget().getClass(); // Get the target method being called. MethodSignature targetMethodSignature = (MethodSignature) pjp.getSignature(); Method targetMethod = targetMethodSignature.getMethod(); if (targetMethod.getDeclaringClass().isInterface()) { // Get the underlying implementation if we are given an interface. targetMethod = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), targetMethod.getParameterTypes()); } // Only keep a stop watch if the class and method aren't suppressing logging and the log level is info. if ((AnnotationUtils.findAnnotation(targetClass, SuppressLogging.class) == null) && (AnnotationUtils.findAnnotation(targetMethod, SuppressLogging.class) == null) && (LOGGER.isInfoEnabled())) { // Start the stop watch. StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Proceed to the join point (i.e. call the method and let it return). Object returnValue = pjp.proceed(); // Log the duration. LOGGER.info("Method " + targetClass.getName() + "." + targetMethodSignature.getName() + " took " + HerdDateUtils.formatDuration(stopWatch.getTime(), true) + "."); // Return the method return value. return returnValue; } else { // Invoke the method normally. return pjp.proceed(); } }