List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:org.apache.ignite.compute.gridify.aop.aspectj.GridifyAspectJAspect.java
License:Apache License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.// ww w. j av a 2 s . co m * * @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.apache.ignite.compute.gridify.Gridify * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") 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 IgniteCheckedException("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 IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or " + "Gridify.taskClass(), but not both: " + ann); } try { Ignite ignite = G.ignite(gridName); // If task class was specified. if (!ann.taskClass().equals(GridifyDefaultTask.class)) { return ignite.compute().withTimeout(ann.timeout()) .execute((Class<? extends ComputeTask<GridifyArgument, Object>>) ann.taskClass(), arg); } // If task name was not specified. if (ann.taskName().isEmpty()) { return ignite.compute().withTimeout(ann.timeout()) .execute(new GridifyDefaultTask(joinPnt.getSignature().getDeclaringType()), arg); } // If task name was specified. return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg); } 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.apache.ignite.compute.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java
License:Apache License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes./*from w ww. j a v a 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.apache.ignite.compute.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") 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 IgniteCheckedException("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 { Ignite ignite = G.ignite(gridName); return execute(ignite.compute(), 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.apache.ignite.compute.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java
License:Apache License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.// ww w .ja v 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.apache.ignite.compute.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") 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 IgniteCheckedException("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 { Ignite ignite = G.ignite(gridName); return execute(mtd, ignite.compute(), 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.apache.ivory.aspect.AbstractIvoryAspect.java
License:Apache License
@Around("@annotation(org.apache.ivory.monitors.Monitored)") public Object LogAround(ProceedingJoinPoint joinPoint) throws Throwable { String methodName = joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); Object result = null;/* www. j ava2s . c om*/ ResourceMessage.Status status; long startTime = System.nanoTime(); long endTime; try { result = joinPoint.proceed(); } catch (Exception e) { endTime = System.nanoTime(); status = ResourceMessage.Status.FAILED; publishMessage(getResourceMessage( joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName, args, status, endTime - startTime)); throw e; } endTime = System.nanoTime(); status = ResourceMessage.Status.SUCCEEDED; publishMessage( getResourceMessage(joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + methodName, args, status, endTime - startTime)); return result; }
From source file:org.apache.nifi.audit.ProcessGroupAuditor.java
License:Apache License
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroupFlow(..))") public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { final Object[] args = proceedingJoinPoint.getArgs(); final String groupId = (String) args[0]; final NiFiUser user = (NiFiUser) args[1]; final ProcessGroupDAO processGroupDAO = getProcessGroupDAO(); final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId); final VersionControlInformation vci = processGroup.getVersionControlInformation(); final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed(); final VersionControlInformation updatedVci = updatedProcessGroup.getVersionControlInformation(); final Operation operation; if (vci == null) { operation = Operation.StartVersionControl; } else {/*from www . j a va 2s . c o m*/ if (updatedVci == null) { operation = Operation.StopVersionControl; } else if (vci.getVersion() == updatedVci.getVersion()) { operation = Operation.RevertLocalChanges; } else { operation = Operation.ChangeVersion; } } saveUpdateAction(user, groupId, operation); return updatedProcessGroup; }
From source file:org.apache.nifi.audit.ProcessGroupAuditor.java
License:Apache License
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateVersionControlInformation(..))") public ProcessGroup updateVersionControlInformationAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { final VersionControlInformationDTO vciDto = (VersionControlInformationDTO) proceedingJoinPoint.getArgs()[0]; final ProcessGroupDAO processGroupDAO = getProcessGroupDAO(); final ProcessGroup processGroup = processGroupDAO.getProcessGroup(vciDto.getGroupId()); final VersionControlInformation vci = processGroup.getVersionControlInformation(); final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed(); final Operation operation; if (vci == null) { operation = Operation.StartVersionControl; } else {/*from w ww . j a v a 2 s . com*/ operation = Operation.CommitLocalChanges; } saveUpdateAction(NiFiUserUtils.getNiFiUser(), vciDto.getGroupId(), operation); return updatedProcessGroup; }
From source file:org.apache.pulsar.broker.zookeeper.aspectj.ClientCnxnAspect.java
License:Apache License
private void processEvent(ProceedingJoinPoint joinPoint) { long startTimeNano = getStartTime(joinPoint.getArgs()[0]); if (startTimeNano == -1) { // couldn't find start time return;/* www . j a v a 2 s .c o m*/ } Record request = getEventType(joinPoint.getArgs()[0]); if (request != null) { long timeElapsed = (MathUtils.nowInNano() - startTimeNano); notifyListeners(checkType(request), TimeUnit.NANOSECONDS.toMicros(timeElapsed)); } }
From source file:org.apache.pulsar.zookeeper.FinalRequestProcessorAspect.java
License:Apache License
@Around("processRequest()") public void timedProcessRequest(ProceedingJoinPoint joinPoint) throws Throwable { joinPoint.proceed();//ww w .j a va2s . c om Request request = (Request) joinPoint.getArgs()[0]; String type = requestTypeMap.getOrDefault(request.type, "unknown"); requests.labels(type).inc(); long latencyMs = System.currentTimeMillis() - request.createTime; String latencyLabel = isWriteRequest(request.type) ? "write" : "read"; requestsLatency.labels(latencyLabel).observe(latencyMs); }
From source file:org.apache.pulsar.zookeeper.SerializeUtilsAspect.java
License:Apache License
@Around("execution(* org.apache.zookeeper.server.util.SerializeUtils.deserializeTxn(..))") public Record wrapper(ProceedingJoinPoint joinPoint) throws IOException { byte[] txnBytes = (byte[]) joinPoint.getArgs()[0]; TxnHeader hdr = (TxnHeader) joinPoint.getArgs()[1]; return deserializeTxn(txnBytes, hdr); }
From source file:org.apache.rave.synchronization.SynchronizingAspect.java
License:Apache License
@Around("synchronizePointcut()") public Object synchronizeInvocation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); Method method = methodSignature.getMethod(); Object target = proceedingJoinPoint.getTarget(); Object[] args = proceedingJoinPoint.getArgs(); Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target); Synchronized annotation = getAnnotation(targetClass, method); Validate.notNull(annotation, "Could not find @Synchronized annotation!"); Lock lock = getLock(targetClass, method, args, annotation); if (lock == null) { logger.debug(/*from ww w . j a v a 2s. com*/ "No lock obtained for call [{}] on targetClass [{}] - proceeding without synchronization on " + "thread {}", new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() }); return proceedingJoinPoint.proceed(); } else { try { logger.debug( "Lock obtained for call [{}] on targetClass [{}] - proceeding with synchronization on thread {}", new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() }); lock.lock(); return proceedingJoinPoint.proceed(); } finally { lock.unlock(); lockService.returnLock(lock); } } }