List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:org.geosdi.geoplatform.cas.aop.SecurityCASAOP.java
License:Open Source License
@Around("execution(* it.geosolutions.geoserver.rest.GeoServerRESTPublisher.*(..))") public Object adviceGeoServerRESTPublisher(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { logger.info("AOP GeoServerRESTPublisher.*(..) is running..."); Assertion receivedAssertion = this.retrieveAssertion(); CASHTTPUtils.setCasAssertion(receivedAssertion); Object[] parameters = proceedingJoinPoint.getArgs(); Class[] types = new Class[parameters.length]; for (int i = 0; i < parameters.length; i++) { Object object = parameters[i]; types[i] = object.getClass();//from w ww. j a va 2s . co m logger.info("Parameter type: " + object.getClass()); } try { Method method = GeoServerCASRESTPublisher.class.getMethod(proceedingJoinPoint.getSignature().getName(), types); method.setAccessible(Boolean.TRUE); return method.invoke(this.casRestPublisher, proceedingJoinPoint.getArgs()); } catch (Exception e) { e.printStackTrace(); throw new IllegalStateException(e.getMessage()); } }
From source file:org.geosdi.geoplatform.cas.aop.SecurityCASAOP.java
License:Open Source License
@Around("execution(* it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager.*(..))") public Object adviceGeoServerRESTStoreManager(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { logger.info("AOP GeoServerRESTStoreManager.*(..) is running..."); Assertion receivedAssertion = this.retrieveAssertion(); CASHTTPUtils.setCasAssertion(receivedAssertion); Object[] parameters = proceedingJoinPoint.getArgs(); Class[] types = new Class[parameters.length]; for (int i = 0; i < parameters.length; i++) { Object object = parameters[i]; types[i] = object.getClass();//from www .j a v a2 s .c o m logger.debug("REST Store Parameter type: " + object.getClass()); } try { Method method = GeoServerCASRESTStoreManager.class .getMethod(proceedingJoinPoint.getSignature().getName(), types); method.setAccessible(Boolean.TRUE); logger.info("After REST Store Manager Method"); return method.invoke(this.casRestStoreManager, proceedingJoinPoint.getArgs()); } catch (Exception e) { e.printStackTrace(); throw new IllegalStateException(e.getMessage()); } }
From source file:org.grazy.experimental.graspectj.MethodLogger.java
License:Apache License
@Around("execution(* *(..)) && @annotation(Loggable)") public Object around(ProceedingJoinPoint point) { long start = System.currentTimeMillis(); Object result;/*from w w w. j a v a 2s. c om*/ try { result = point.proceed(); logger.log(Level.INFO, "source location: {0}", point.getSourceLocation().toString()); logger.log(Level.INFO, "#%s(%s): %s in %[msec]s{0}{1}{2}{3}", new Object[] { MethodSignature.class.cast(point.getSignature()).getMethod().getName(), point.getArgs(), result, System.currentTimeMillis() - start }); return result; } catch (Throwable ex) { Logger.getLogger(MethodLogger.class.getName()).log(Level.SEVERE, null, ex); } throw new RuntimeException("ma non scassare la minchia"); }
From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifyAspectJAspect.java
License:Open Source License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//ww w . j a v a 2s .c om * * @param joinPnt Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked" }) @Around("execution(@org.gridgain.grid.compute.gridify.Gridify * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); Gridify ann = mtd.getAnnotation(Gridify.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); // Initialize defaults. GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), mtd.getParameterTypes(), joinPnt.getArgs(), joinPnt.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPnt.proceed(); } if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) { throw new GridException("Gridify annotation must specify either Gridify.taskName() or " + "Gridify.taskClass(), but not both: " + ann); } try { Grid grid = G.grid(gridName); // If task class was specified. if (!ann.taskClass().equals(GridifyDefaultTask.class)) { return grid.compute().withTimeout(ann.timeout()) .execute((Class<? extends GridComputeTask<GridifyArgument, Object>>) ann.taskClass(), arg) .get(); } // If task name was not specified. if (ann.taskName().isEmpty()) { return grid.compute().withTimeout(ann.timeout()) .execute(new GridifyDefaultTask(joinPnt.getSignature().getDeclaringType()), arg).get(); } // If task name was specified. return grid.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg).get(); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java
License:Open Source License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes./*w w w . j ava 2s.c o m*/ * * @param joinPnt Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check method return type. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPnt.getArgs(), joinPnt.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPnt.proceed(); } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPnt.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPnt.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(grid, joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.compute.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java
License:Open Source License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes./*from w ww .jav a 2 s. c o m*/ * * @param joinPnt Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.gridgain.grid.compute.GridComputeJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check is method allowed for gridify. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPnt.getArgs(), joinPnt.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPnt.proceed(); } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPnt.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPnt.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(mtd, grid, joinPnt.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.gridify.aop.aspectj.GridifyAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.// w w w.ja v a2 s. c o m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked" }) @Around("execution(@org.gridgain.grid.gridify.Gridify * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); Gridify ann = mtd.getAnnotation(Gridify.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) { throw new GridException("Grid is not locally started: " + gridName); } // Initialize defaults. GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), mtd.getParameterTypes(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) { return joinPoint.proceed(); } } if (!ann.taskClass().equals(GridifyDefaultTask.class) && ann.taskName().length() > 0) { throw new GridException("Gridify annotation must specify either Gridify.taskName() or " + "Gridify.taskClass(), but not both: " + ann); } try { Grid grid = G.grid(gridName); // If task class was specified. if (!ann.taskClass().equals(GridifyDefaultTask.class)) { return grid.execute((Class<? extends GridTask<GridifyArgument, Object>>) ann.taskClass(), arg, ann.timeout()).get(); } // If task name was not specified. if (ann.taskName().length() == 0) { return grid.execute(new GridifyDefaultTask(joinPoint.getSignature().getDeclaringType()), arg, ann.timeout()).get(); } // If task name was specified. return grid.execute(ann.taskName(), arg, ann.timeout()).get(); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) { throw cause; } cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) { throw e; } } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//from w ww . j ava 2 s.c o m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check method return type. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPoint.proceed(); } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPoint.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPoint.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes./* ww w .java 2 s . c o m*/ * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check is method allowed for gridify. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) { return joinPoint.proceed(); } } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPoint.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPoint.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(mtd, grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.test.aop.aspectj.GridifyJunitAspectJAspect.java
License:GNU General Public License
/** * Executes JUnit4 tests annotated with {@link GridifyTest @GridifyTest} annotation * on the grid./*from w w w . j a va 2s . co m*/ * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @Around("execution(public void (org.junit.runners.Suite).run(org.junit.runner.notification.RunNotifier))" + "&& !cflow(target(org.gridgain.grid.test.junit4.GridJunit4Suite))") public Object gridifyJunit4(ProceedingJoinPoint joinPoint) throws Throwable { Describable suite = (Describable) joinPoint.getTarget(); // We create class with caller class loader, // thus JUnit 4 task will pick up proper class loader. ClassLoader clsLdr = joinPoint.getSignature().getDeclaringType().getClassLoader(); Class<?> cls = Class.forName(suite.getDescription().getDisplayName(), true, clsLdr); if (cls.getAnnotation(GridifyTest.class) != null) { new GridJunit4Suite(cls, clsLdr).run((RunNotifier) joinPoint.getArgs()[0]); return null; } return joinPoint.proceed(); }