List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.tsg.flooringmastery.consoleIO.TimeAspect.java
public Object timeMethod(ProceedingJoinPoint jp) { Object ret = null;//w ww . java2 s. c o m try { long start = System.currentTimeMillis(); ret = jp.proceed(); long end = System.currentTimeMillis(); System.out.println("++++++++++++++++++++++++++++++++++"); System.out.println(jp.getSignature().getName() + " " + (end - start) + " ms."); System.out.println("++++++++++++++++++++++++++++++++++"); } catch (Throwable e) { System.out.println("Exception in SimpleTimperAspect.timeMethod()"); } return ret; }
From source file:com.tsg.flooringmasteryspring.TimingAspect.java
public Object timingMethod(ProceedingJoinPoint jp) throws Throwable { Object ret = null;// w w w.j a va 2 s .c o m try { long start = System.nanoTime(); ret = jp.proceed(); long end = System.nanoTime(); System.out.println("[INFO] " + jp.getSignature().getName() + " took " + (end - start) + "ns"); } catch (Throwable ex) { System.out.println("Exception in SimpleTimerMethodAspect.timeMethod"); throw ex; } return ret; }
From source file:com.tuanche.log.aspect.PrintMethodRunTimeAspect.java
License:Open Source License
@Around("printMethodRunTimePointcut()") public Object processText(ProceedingJoinPoint proceedingJoinPoint) { Object result = null;//w ww .j av a 2s . c o m PrintMethodRunTime methodRunTime = this.findMethodAnnotation(proceedingJoinPoint, PrintMethodRunTime.class); String messageFormat = null; if (methodRunTime != null) { messageFormat = methodRunTime.messageFormat(); } if (messageFormat == null) { messageFormat = ""; } String message = messageFormat; String targetClassName = null; while (message.indexOf("{className}") > -1) { targetClassName = this.getClassName(proceedingJoinPoint); message = message.replace("{className}", targetClassName); } String methodName = null; while (message.indexOf("{methodName}") > -1) { methodName = this.getMethodName(proceedingJoinPoint); message = message.replace("{methodName}", methodName); } long startMillisecond = System.currentTimeMillis(); try { result = proceedingJoinPoint.proceed(); } catch (Throwable e) { e.printStackTrace(); } long endMillisecond = System.currentTimeMillis(); long runTime = endMillisecond - startMillisecond; while (message.indexOf("{millisecond}") > -1) { message = message.replace("{millisecond}", runTime + ""); } if (logger.isInfoEnabled()) { logger.info(message); } return result; }
From source file:com.twitterassistant.service.event.EventServiceImpl.java
License:Apache License
/** * Intercepts methods that declare @EventPublisher and broadcasts the return value to all listeners * * @param pjp proceeding join point/*from w w w. j ava 2s .com*/ * @return the intercepted method returned object * @throws Throwable in case something goes wrong in the actual method call */ @Around(value = "@annotation(com.twitterassistant.annotation.event.EventPublisher) && @annotation(eventPublisher)") public Object handleBroadcast(ProceedingJoinPoint pjp, EventPublisher eventPublisher) throws Throwable { Object retVal = pjp.proceed(); String[] events = eventPublisher.value(); for (String event : events) { LOG.debug(String.format("Intercepted %s", Arrays.toString(events))); publish(event, retVal); } return retVal; }
From source file:com.twocents.security.license.LicenseAspect.java
@Around("execution(* com.twocents.service..*.*(..))") public Object validateLicense(ProceedingJoinPoint pjp) throws Throwable { //log.info("Validating license for method: " + pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName()); //LicenseValidate.validateLicense(); return pjp.proceed(); }
From source file:com.vaadin.addon.jpacontainer.demo.aspects.ProviderLoggerAspect.java
License:Apache License
@Around("methodsToBeLogged()") public Object log(ProceedingJoinPoint pjp) throws Throwable { if (logger.isDebugEnabled()) { StringBuilder sb = new StringBuilder(pjp.getSignature().getName()); sb.append("("); if (pjp.getArgs().length > 0) { for (int i = 0; i < pjp.getArgs().length - 2; i++) { sb.append(pjp.getArgs()[i]); sb.append(","); }/* www. ja v a2 s . c om*/ sb.append(pjp.getArgs()[pjp.getArgs().length - 1]); } sb.append(")"); logger.debug("Calling method: " + sb.toString()); } Object result = pjp.proceed(); if (logger.isDebugEnabled()) { logger.debug("Result of method " + pjp.getSignature().getName() + ": " + result); } return result; }
From source file:com.variacode.utils.object.changelistener.ObservableObjectAspect.java
License:Apache License
@Around("execution(* *.set*(..)) && @within(annotation)") public Object setMethod(ProceedingJoinPoint joinPoint, Observe annotation) throws Throwable { ObserverSingleton.INSTANCE.change(new Change(annotation.stream(), Introspector.decapitalize(joinPoint.toShortString() .replaceFirst("execution\\(" + joinPoint.getThis().getClass().getSimpleName() + ".set", "") .replaceAll("\\.", "").replaceAll("\\)", "").replaceAll("\\(", "")), joinPoint.getArgs()[0], joinPoint.getThis())); return joinPoint.proceed(); }
From source file:com.vico.license.aop.SecurityAspect.java
@Around("needAnnotation()") public Object execute(ProceedingJoinPoint pjp) throws Throwable { System.out.println("=====SysLogAspect ====="); //??/*from ww w.java2 s.com*/ MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method method = methodSignature.getMethod(); //,(ignore?) if (method.isAnnotationPresent(IgnoreSecurity.class)) { return pjp.proceed(); } //request header??token System.out.println(WebContext.getRequest()); String token = WebContext.getRequest().getHeader(tokenName); //, System.out.println(token); //token if (!tokenManager.checkToken(token)) { String message = String.format("token [%s] is invalid", token); throw new TokenException(message); } // return pjp.proceed(); }
From source file:com.virtusa.isq.vtaf.aspects.AspectClass.java
License:Apache License
/** * Advice the joinpoint.//from w w w.j a v a 2 s . co m * * @param joinPoint the join point */ public final void advice(final ProceedingJoinPoint joinPoint) { caller = (SeleniumTestBase) joinPoint.getThis(); try { initiateRecoveryThread(caller, onerrorMethodNames); joinPoint.proceed(); cancelRecoveryThread(); } catch (WebDriverException e) { throw e; } catch (Exception e) { e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); } }
From source file:com.visural.domo.spring.TransactionInterceptor.java
License:Apache License
@Around("execution(@com.visural.domo.spring.Transactional * *(..))") public Object transactional(ProceedingJoinPoint mi) throws Throwable { MethodSignature signature = (MethodSignature) mi.getSignature(); Method method = signature.getMethod(); String connectionSource = method.getAnnotation(Transactional.class).connectionSource(); boolean alreadyTxForSource = scope.isInScope(connectionSource); scope.enter(connectionSource);// www . j a v a 2 s .c o m try { if (scope.getSeed(connectionSource, ConnectionSource.class) == null) { GeneratorProvider gp = transactionConfig.getConnectionProvider() .getGeneratorProvider(connectionSource); scope.seed(GeneratorProvider.class, gp); ConnectionSource con = transactionConfig.getConnectionProvider().get(connectionSource); scope.seed(ConnectionSource.class, con); } if (alreadyTxForSource) { Savepoint savepoint = null; if (transactionConfig.isSavepointAndRollbackNested()) { try { savepoint = tx.savepoint(); } catch (SQLFeatureNotSupportedException ns) { // TODO: log // not supported feature } } try { return mi.proceed(); } catch (Throwable t) { if (savepoint != null) { tx.rollbackToSavepoint(savepoint); } throw t; } } else { try { Object o = mi.proceed(); tx.commit(); return o; } catch (Throwable t) { try { tx.rollback(); } catch (SQLException se) { // prefer to bubble the original error, but log Logger.getLogger(TransactionInterceptor.class.getName()).log(Level.SEVERE, "Failed rolling back transaction after prior error.", se); } throw t; } } } finally { // close connection if we are the outermost tx for this source if (!alreadyTxForSource) { IOUtil.silentClose(TransactionInterceptor.class, tx.getConnection()); } scope.exit(connectionSource); } }