List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:com.klistret.cmdb.aspect.crud.RelationIntegration.java
License:Open Source License
public Object transmit(ProceedingJoinPoint pjp) throws Throwable { try {// ww w. j a va 2s . c om Relation relation = (Relation) pjp.proceed(); Signature signature = pjp.getSignature(); String name = signature.getName().toUpperCase(); Object[] args = pjp.getArgs(); if (name.equals("GET")) name = "READ"; try { SignatureMethod method = SignatureMethod.valueOf(name); switch (method) { case CREATE: case DELETE: case UPDATE: case READ: Relation precedent = null; for (Object arg : args) if (arg instanceof Relation) precedent = (Relation) arg; logger.debug("Generating a message with CRUD function {} on relation [id: {}, version: {}]", new Object[] { name, relation.getId(), relation.getVersion() }); Message<Relation> message = MessageBuilder.withPayload(relation).setHeader("function", name) .setHeader("precedent", precedent == null ? null : precedent.getVersion()).build(); channel.send(message); break; } } catch (IllegalArgumentException e) { logger.debug("Method {} is not trasmitted", name); } return relation; } catch (HibernateOptimisticLockingFailureException e) { throw new ApplicationException("Stale relation.", new StaleStateException(e.getMessage())); } catch (Exception e) { logger.error("Unknown exception: {}", e.getMessage()); throw e; } }
From source file:com.klistret.cmdb.utility.spring.OptimisticLocking.java
License:Open Source License
public Object commitTransaction(ProceedingJoinPoint pjp) throws Throwable { try {// ww w .j a va 2 s. c om return pjp.proceed(); } catch (HibernateOptimisticLockingFailureException e) { Signature signature = pjp.getSignature(); logger.error("Stale in declaration:{}, name: {}, long: {} message: {}", new Object[] { signature.getDeclaringTypeName(), signature.getName(), pjp.toLongString(), e.getMessage() }); throw new ApplicationException("Stale entity captured."); } }
From source file:com.liferay.portal.workflow.WorkflowLinkAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_UPDATE_ACTIVE)) { long companyId = (Long) arguments[0]; String name = (String) arguments[2]; int version = (Integer) arguments[3]; boolean active = (Boolean) arguments[4]; if (!active) { int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil .getWorkflowDefinitionLinksCount(companyId, name, version); if (workflowDefinitionLinksCount >= 1) { throw new RequiredWorkflowDefinitionException(); }/*from w w w. jav a 2 s .co m*/ } } return proceedingJoinPoint.proceed(); }
From source file:com.liferay.portal.workflow.WorkflowLockingAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_START_WORKFLOW_INSTANCE_METHOD_NAME)) { String workflowDefinitionName = (String) arguments[3]; Integer workflowDefinitionVersion = (Integer) arguments[4]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(workflowDefinitionName, workflowDefinitionVersion); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException("Workflow definition name " + workflowDefinitionName + " and version " + workflowDefinitionVersion + " is being undeployed"); }/*from w w w .j av a 2s. co m*/ return proceedingJoinPoint.proceed(); } else if (!methodName.equals(_UNDEPLOY_WORKFLOW_DEFINITION_METHOD_NAME)) { return proceedingJoinPoint.proceed(); } long userId = (Long) arguments[1]; String name = (String) arguments[2]; Integer version = (Integer) arguments[3]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(name, version); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException( "Workflow definition name " + name + " and version " + version + " is being undeployed"); } try { LockLocalServiceUtil.lock(userId, className, key, String.valueOf(userId), false, Time.HOUR); return proceedingJoinPoint.proceed(); } finally { LockLocalServiceUtil.unlock(className, key); } }
From source file:com.liferay.portal.workflow.WorkflowPermissionAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME)) { long userId = (Long) arguments[1]; PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); if (permissionChecker.getUserId() != userId) { throw new PrincipalException(); }/*from ww w . jav a 2 s . c o m*/ } return proceedingJoinPoint.proceed(); }
From source file:com.liferay.util.aspectj.AspectJUtil.java
License:Open Source License
public static Method getMethod(ProceedingJoinPoint proceedingJoinPoint) throws NoSuchMethodException { MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); return getMethod(methodSignature); }
From source file:com.lushapp.core.aop.LogAspect.java
License:Apache License
/** * @param point /*from w ww . j a v a2 s . co m*/ */ @Around("execution(* com.lushapp.modules.*.service..*Manager.*(..))") public Object logAll(ProceedingJoinPoint point) throws Throwable { Object result = null; // ?? String methodName = point.getSignature().getName(); String className = point.getTarget().getClass().getSimpleName(); String userName = null; Long start = 0L; Long end = 0L; String ip = null; // ? try { // start = System.currentTimeMillis(); result = point.proceed(); end = System.currentTimeMillis(); // ?? SessionInfo sessionInfo = null; try { sessionInfo = SecurityUtils.getCurrentSessionInfo(); } catch (Exception e) { logger.error(e.getMessage()); } if (sessionInfo != null) { userName = sessionInfo.getLoginName(); ip = sessionInfo.getIp(); } else { userName = ""; ip = "127.0.0.1"; logger.warn("sessionInfo."); } } catch (Throwable e) { logger.error(e.getMessage(), e); throw e; } String name = null; // ? if (className.indexOf("Resource") > -1) { name = "??"; } else if (className.indexOf("Role") > -1) { name = "?"; } else if (className.indexOf("User") > -1) { name = "?"; } else if (className.indexOf("Organ") > -1) { name = "?"; } else { name = className; } // ? String opertype = methodName; if (StringUtils.isNotBlank(opertype) && (opertype.indexOf("save") > -1 || opertype.indexOf("update") > -1 || opertype.indexOf("delete") > -1 || opertype.indexOf("merge") > -1)) { Long time = end - start; Log log = new Log(); log.setType(LogType.operate.getValue()); log.setLoginName(userName); log.setModule(name); log.setAction(opertype); log.setOperTime(new Date(start)); log.setActionTime(time.toString()); log.setIp(ip); BrowserType browserType = BrowserUtils.getBrowserType(SpringMVCHolder.getRequest()); log.setBrowserType(browserType == null ? null : browserType.toString()); defaultEntityManager.save(log); } if (logger.isDebugEnabled()) { logger.debug(":{},?{},?{},{}ms.", new Object[] { userName, className, methodName, end - start }); } return result; }
From source file:com.moz.fiji.mapreduce.util.MRLogTimerAspect.java
License:Apache License
/** * Advice around functions that match PointCut "profile". * * @param thisJoinPoint The JoinPoint that matched the pointcut. * @return Object returned by function which matched PointCut "profile". * @throws Throwable if there is an exception in the function the advice surrounds. *///from w ww .j av a2s .co m @Around("execution(* com.moz.fiji.mapreduce.impl.HFileWriterContext.put(..)) || " + "execution(* com.moz.fiji.mapreduce.framework.FijiTableInputFormat.FijiTableRecordReader.nextKeyValue(..))") public Object aroundProfileMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable { final long start, end; start = System.nanoTime(); Object returnanswer = thisJoinPoint.proceed(); end = System.nanoTime(); String funcSig = thisJoinPoint.getSignature().toLongString(); final LoggingInfo existing = mSignatureTimeMap.putIfAbsent(funcSig, new LoggingInfo(end - start, 1)); if (existing != null) { existing.increment(end - start); } return returnanswer; }
From source file:com.moz.fiji.schema.util.LogTimerAspect.java
License:Apache License
/** * Advice around functions that match PointCut "profile". * * @param thisJoinPoint The JoinPoint that matched the pointcut. * @return Object returned by function which matched PointCut "profile". * @throws Throwable if there is an exception in the function the advice surrounds. *///ww w . ja va2 s . c om @Around("execution(* com.moz.fiji.schema.FijiCellDecoder.*(..)) || " + "execution(* com.moz.fiji.schema.FijiCellEncoder.*(..)) || " + "execution(* com.moz.fiji.schema.FijiMetaTable.*(..)) || " + "execution(* com.moz.fiji.schema.FijiSchemaTable.*(..)) || " + "execution(* com.moz.fiji.schema.FijiPutter.put(..))") public Object aroundProfileMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable { final long start, end; start = System.nanoTime(); Object returnanswer = thisJoinPoint.proceed(); end = System.nanoTime(); String funcSig = thisJoinPoint.getSignature().toLongString(); if (!mSignatureTimeMap.containsKey(funcSig)) { mSignatureTimeMap.put(funcSig, new LoggingInfo(end - start, 1)); } else { mSignatureTimeMap.get(funcSig).increment(end - start); } return returnanswer; }
From source file:com.mpobjects.rtcalltree.rec.AspectJRecorder.java
License:Apache License
/** * @param aJoinPoint/* w ww. j av a 2 s. c o m*/ * @return */ protected MutableCalltreeEntry createEntry(ProceedingJoinPoint aJoinPoint) { final Signature signature = aJoinPoint.getSignature(); String className = signature.getDeclaringTypeName(); final String methodName = signature.getName(); final Object target = aJoinPoint.getTarget(); if (target != null) { if (!Proxy.isProxyClass(target.getClass())) { className = target.getClass().getName(); } } CalltreeEntryImpl entry = new CalltreeEntryImpl(className, methodName); /* Spring AOP throws exceptions on getFileName() etc. instead of just returning null for SourceLocation */ // if (aJoinPoint.getSourceLocation() != null) { // entry.setSourceFilename(aJoinPoint.getSourceLocation().getFileName()); // entry.setSourceLine(aJoinPoint.getSourceLocation().getLine()); // } if (argumentConverter != null && aJoinPoint.getArgs() != null) { entry.setParameterValues(argumentConverter.convertArguments(aJoinPoint.getArgs())); } if (signature instanceof CodeSignature) { entry.setParameterTypes(getTypeNames(((CodeSignature) signature).getParameterTypes())); } return entry; }