List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.clicktravel.cheddar.application.retry.RetryableAspectTest.java
License:Apache License
@Test public void shouldAttemptMethodAndCallExceptionHandler_withExceptionThrownAndExceptionHandlerNamed() throws Throwable { // Given//from www .ja va2 s . com final RetryableAspect retryableAspect = new RetryableAspect(); final ProceedingJoinPoint mockProceedingJoinPoint = setupSimpleProceedingJoinPointMock(); final Retryable mockRetryable = setupSimpleRetryableMock(); final RetryExceptionHandler retryExceptionHandler = new RetryExceptionHandler(); final MethodSignature mockMethodSignature = mock(MethodSignature.class); final String exceptionHandlerName = "joinPointMethodExceptionHandlingMethod"; RetryableConfiguration.setRetryableEnabled(false); when(mockProceedingJoinPoint.proceed()).thenThrow(new RetryAspectTestException()); when(mockProceedingJoinPoint.getThis()).thenReturn(retryExceptionHandler); when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature); when(mockProceedingJoinPoint.getArgs()).thenReturn(new Object[] { "exampleArgument" }); when(mockMethodSignature.getParameterTypes()).thenReturn( RetryExceptionHandler.class.getDeclaredMethod("joinPointMethod", String.class).getParameterTypes()); when(mockRetryable.exceptionHandlers()).thenReturn(new String[] { exceptionHandlerName }); // When retryableAspect.attemptMethodAndRetryIfNeeded(mockProceedingJoinPoint, mockRetryable); // Then verify(mockProceedingJoinPoint).proceed(); assertTrue(retryExceptionHandler.exceptionHandlerBeenCalled); }
From source file:com.clicktravel.cheddar.server.application.logging.LoggingAspect.java
License:Apache License
@Around("loggable()") protected Object advice(final ProceedingJoinPoint point) throws Throwable { // If not logging, avoid overhead of building expressions in logging statements return logger.isDebugEnabled() ? proceedAndLog(point) : point.proceed(); }
From source file:com.clicktravel.cheddar.server.application.logging.LoggingAspect.java
License:Apache License
private Object proceedAndLog(final ProceedingJoinPoint point) throws Throwable { final String methodCallDetail = methodCallDetail(point); final long startTime = System.currentTimeMillis(); try {// w w w . j a v a2s . c o m final Object result = point.proceed(); logger.debug("Method call; call:[{}] return:[{}] timeMillis:[{}]", methodCallDetail, result, System.currentTimeMillis() - startTime); return result; } catch (final Throwable e) { logger.debug("Method call; call:[{}] exception:[{}] timeMillis:[{}]", methodCallDetail, e, System.currentTimeMillis() - startTime); throw e; } }
From source file:com.cloud.event.ActionEventInterceptor.java
License:Apache License
public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable { MethodSignature methodSignature = (MethodSignature) call.getSignature(); Method targetMethod = methodSignature.getMethod(); if (needToIntercept(targetMethod)) { EventVO event = interceptStart(targetMethod); boolean success = true; Object ret = null;// w ww. j a v a 2s. co m try { ret = call.proceed(); } catch (Throwable e) { success = false; interceptException(targetMethod, event); throw e; } finally { if (success) { interceptComplete(targetMethod, event); } } return ret; } return call.proceed(); }
From source file:com.cloud.utils.db.TransactionContextBuilder.java
License:Apache License
public Object AroundAnyMethod(ProceedingJoinPoint call) throws Throwable { MethodSignature methodSignature = (MethodSignature) call.getSignature(); Method targetMethod = methodSignature.getMethod(); if (needToIntercept(targetMethod)) { Transaction txn = Transaction.open(call.getSignature().getName()); Object ret = null;/* w ww. j av a 2s .c o m*/ try { ret = call.proceed(); } finally { txn.close(); } return ret; } return call.proceed(); }
From source file:com.create.aop.LoggingAspect.java
License:Apache License
private Object logPerformance(ProceedingJoinPoint joinPoint, Logger logger, String watchId) throws Throwable { final StopWatch stopWatch = new StopWatch(watchId); stopWatch.start(watchId);//from w w w. ja va 2 s . com try { return joinPoint.proceed(); } finally { stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } }
From source file:com.crossbusiness.resiliency.aspect.AbstractAsyncAspect.java
License:Open Source License
/** * Intercept the given method invocation, submit the actual calling of the method to * the correct task executor and return immediately to the caller. * @return {@link Future} if the original method returns {@code Future}; {@code null} * otherwise.//w w w.java2s. co m */ // @Around("asyncMethodExecution()") private Object doAsync(final ProceedingJoinPoint point, Async asyncConfig) throws Throwable { log.debug(point + " -> " + asyncConfig); String qualifier = asyncConfig.value(); MethodSignature targetMethodSig = (MethodSignature) point.getSignature(); AsyncTaskExecutor executor = getExecutor(targetMethodSig.getMethod(), qualifier); if (executor == null) { return point.proceed(); } Callable<Object> callable = new Callable<Object>() { public Object call() throws Exception { try { Object result = point.proceed(); if (result instanceof Future) { return ((Future<?>) result).get(); } } catch (Throwable ex) { ReflectionUtils.rethrowException(ex); } return null; } }; Future<?> result = executor.submit(callable); if (Future.class.isAssignableFrom(targetMethodSig.getMethod().getReturnType())) { return result; } else { return null; } }
From source file:com.crossbusiness.resiliency.aspect.AbstractCircuitBreakerAspect.java
License:Open Source License
private Object proceed(ProceedingJoinPoint pjp) throws CircuitBreakerMethodExecutionException { try {/*from w w w . j ava 2 s . c o m*/ return pjp.proceed(); } catch (Throwable t) { log.debug("Exception while method execution: {}", pjp.getSignature().toLongString()); throw new CircuitBreakerMethodExecutionException(t); } }
From source file:com.crossbusiness.resiliency.aspect.AbstractFallbackAspect.java
License:Open Source License
public Object rerouteToFallback(ProceedingJoinPoint pjp, Fallback fallbackConfig) throws Throwable { String[] fallbacks = fallbackConfig.value(); Class<? extends Throwable>[] fallbackableExceptions = fallbackConfig.exceptions(); List<Object> fallbackBeans = new ArrayList<Object>(fallbacks.length); for (String fallback : fallbacks) { try {/* w w w.j a v a2 s . co m*/ fallbackBeans.add(context.getBean(fallback)); } catch (BeansException be) { log.error("configuration error: cannot find bean with name: '{}'", fallback, be); //configuration errors should be fixed immediately. throw be; } } MethodSignature targetMethodSig = (MethodSignature) pjp.getSignature(); Method targetMethod = targetMethodSig.getMethod(); Class[] paramTypes = (Class[]) targetMethod.getParameterTypes(); Object[] args = pjp.getArgs(); log.debug("fallbacks: {} method: '{}'", fallbacks, targetMethod); try { return pjp.proceed(); } catch (Throwable t) { // if the exception is not what we're looking for, rethrow it if (!isFallbackableException(t, fallbackableExceptions)) throw t; log.debug("got exception while trying the targetBean method: '{}'. will try fallbackBean...", targetMethod); Iterator<Object> iter = fallbackBeans.iterator(); while (iter.hasNext()) { Object fallbackBean = iter.next(); Method fallbackMethod; try { fallbackMethod = fallbackBean.getClass().getMethod(targetMethod.getName(), paramTypes); } catch (NoSuchMethodException | SecurityException nsme) { log.error( "configuration error: No matchig method found in fallbackBean: '{}' that matches to targetBean method: '{}'", new Object[] { fallbackBean.getClass().getName(), targetMethod, nsme }); //configuration errors should be fixed immediately. throw nsme; } try { log.debug("trying fallbackBean method: '{}'...", fallbackMethod); return fallbackMethod.invoke(fallbackBean, args); } catch (IllegalArgumentException | IllegalAccessException iae) { log.error( "configuration error: arguments missmatch: fallbackBean method: '{}' arguments missmatch to targetBean method: '{}' arguments", new Object[] { fallbackMethod, targetMethod, iae }); //configuration errors should be fixed immediately. throw iae; } catch (InvocationTargetException ite) { log.debug( "got exception while trying the fallbackBean method: '{}'. will try next fallbackBean...", fallbackMethod); //fallbackBean method thrown an exception. try next bean or throw exception if this is the last bean if (!iter.hasNext()) { //TODO : do we still need to check isFallbackableException? throw ite.getCause(); } } } //code should never reach this line. throw t; } }
From source file:com.crossbusiness.resiliency.aspect.AbstractGovernorAspect.java
License:Open Source License
protected Object wrap(final ProceedingJoinPoint pjp, Governor governorConfig) throws Throwable { // throttle per instance, per method String throttleKey = pjp.getTarget().hashCode() + pjp.getSignature().toLongString(); if (!throttles.containsKey(throttleKey)) { switch (governorConfig.type()) { case CONCURRENCY: throttles.put(throttleKey,/* w ww . j ava 2 s .c o m*/ new ConcurrencyThrottleDecorator(governorConfig.limit(), governorConfig.blocking())); break; case RATE: throttles.put(throttleKey, new RateThrottleDecorator(governorConfig.limit(), governorConfig.period(), governorConfig.unit(), governorConfig.blocking(), scheduler)); break; case ALL: //TODO break; default: log.error("Unknown Throttler type"); break; } } Throttler t = throttles.get(throttleKey); if (t != null) { return t.proceed(pjp); } else { log.error("no throttles found"); return pjp.proceed(); } }