Java Code Examples for org.aspectj.lang.Signature#getDeclaringTypeName()
The following examples show how to use
org.aspectj.lang.Signature#getDeclaringTypeName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 6 votes |
/** * This is an advice which will be used after the construction of an object. * * @param thisObject * @param jp * The static information about this joint point. */ // HINT: This may be logged multiple times due to super constructor calls... @AfterReturning("monitoredConstructor() && this(thisObject) && notWithinKieker()") public void afterConstruction(final Object thisObject, final JoinPoint.StaticPart jp) { if (!CTRLINST.isMonitoringEnabled()) { return; } final Signature signature = jp.getSignature(); if (!CTRLINST.isProbeActivated(this.signatureToLongString(signature))) { return; } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final ConstructionEvent crecord = new ConstructionEvent(TIME.getTime(), trace.getTraceId(), trace.getNextOrderId(), signature.getDeclaringTypeName(), System.identityHashCode(thisObject)); CTRLINST.newMonitoringRecord(crecord); }
Example 2
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
/** * This advice is used around static operations. * * @param thisJoinPoint * The joint point of the advice. * * @return The return value of the joint point's {@code proceed} method. * * @throws Throwable */ @Around("monitoredOperation() && !this(java.lang.Object) && notWithinKieker()") public Object staticOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable) if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature sig = thisJoinPoint.getSignature(); final String operationSignature = this.signatureToLongString(sig); if (!CTRLINST.isProbeActivated(operationSignature)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); final String clazz = sig.getDeclaringTypeName(); // measure before execution CTRLINST.newMonitoringRecord(new BeforeOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, 0)); // execution of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } catch (final Throwable th) { // NOPMD NOCS (catch throw might ok here) // measure after failed execution CTRLINST.newMonitoringRecord(new AfterOperationFailedObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString(), 0)); throw th; } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } // measure after successful execution CTRLINST.newMonitoringRecord(new AfterOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, 0)); return retval; }
Example 3
Source File: StatsD.java From automon with Apache License 2.0 | 5 votes |
/** * Save invocation/execution time associated with the method to StatsD in the format: com.mypackage.myMethod */ @Override public void stop(TimerContext context) { Signature sig = context.getJoinPoint().getSignature(); String className = sig.getDeclaringTypeName(); // package name: com.my.package String methodName = sig.getName(); // method name: myMethod String label = className + "." + methodName; statsdClient.recordExecutionTime(label, context.stop()); }
Example 4
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && !this(java.lang.Object) && notWithinKieker()") public Object staticOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable) if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature sig = thisJoinPoint.getSignature(); final String operationSignature = this.signatureToLongString(sig); if (!CTRLINST.isProbeActivated(operationSignature)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); final String clazz = sig.getDeclaringTypeName(); // measure before execution CTRLINST.newMonitoringRecord(new BeforeOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz)); // execution of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } catch (final Throwable th) { // NOPMD NOCS (catch throw might ok here) // measure after failed execution CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString())); throw th; } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } // measure after successful execution CTRLINST.newMonitoringRecord(new AfterOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz)); return retval; }
Example 5
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
/** * This is an advice used around calls from static elements to constructors. * * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && !this(java.lang.Object) && notWithinKieker()") public Object static2constructor(final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 6
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
/** * This is an advice used around calls from members to constructors. * * @param thisObject * The caller object. * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && this(thisObject) && notWithinKieker()") public Object member2constructor(final Object thisObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 7
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && !this(java.lang.Object) && !target(java.lang.Object) && notWithinKieker()") public Object static2staticOperation(final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, 0, 0)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 8
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && this(thisObject) && !target(java.lang.Object) && notWithinKieker()") public Object member2staticOperation(final Object thisObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); final int callerObject = System.identityHashCode(thisObject); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, callerObject, 0)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 9
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && !this(java.lang.Object) && target(targetObject) && notWithinKieker()") public Object static2memberOperation(final Object targetObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final String callee = this.signatureToLongString(thisJoinPoint.getSignature()); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = targetObject.getClass().getName(); final int calleeObject = System.identityHashCode(targetObject); // measure before call CTRLINST.newMonitoringRecord(new CallOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, 0, calleeObject)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 10
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && !this(java.lang.Object) && !target(java.lang.Object) && notWithinKieker()") public Object static2staticOperation(final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 11
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && this(thisObject) && !target(java.lang.Object) && notWithinKieker()") public Object member2staticOperation(final Object thisObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); // measure before call CTRLINST.newMonitoringRecord(new CallOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 12
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 5 votes |
@Around("monitoredOperation() && !this(java.lang.Object) && target(targetObject) && notWithinKieker()") public Object static2memberOperation(final Object targetObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final String callee = this.signatureToLongString(thisJoinPoint.getSignature()); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = targetObject.getClass().getName(); // measure before call CTRLINST.newMonitoringRecord(new CallOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 13
Source File: ReliableOnConsumedAspect.java From x7 with Apache License 2.0 | 4 votes |
@Around("cut() && @annotation(reliableOnConsumed) ") public void around(ProceedingJoinPoint proceedingJoinPoint, ReliableOnConsumed reliableOnConsumed) { Object[] args = proceedingJoinPoint.getArgs(); Object message = args[0]; Signature signature = proceedingJoinPoint.getSignature(); String logStr = signature.getDeclaringTypeName() + "." + signature.getName(); String nextTopic = reliableOnConsumed.nextTopic(); String[] svcs = reliableOnConsumed.nextSvcs(); if (StringUtil.isNotNull(nextTopic)){ if (svcs == null || svcs.length == 0){ throw new IllegalArgumentException(logStr + ", if config nextTopic, svcs of io.xream.x7.reliable.ReliableOnConsumed can not null, nextTopic: " + nextTopic); } } String svc = reliableOnConsumed.svc(); if (StringUtil.isNullOrEmpty(svc)){ svc = VerifyUtil.toMD5(logStr).substring(0,10); } this.backend.onConsumed(svc, message, () -> { try { MethodSignature ms = ((MethodSignature) signature); if (ms.getReturnType() == void.class) { proceedingJoinPoint.proceed(); } else { Object nextBody = proceedingJoinPoint.proceed(); String id = MessageIdGenerator.get(); int maxTry = reliableOnConsumed.nextRetryMax(); if (StringUtil.isNotNull(nextTopic)){ boolean flag = this.backend.createNext(id,maxTry,nextTopic,nextBody,message,svcs); if (!flag){ throw new RuntimeException(logStr + ", produce next topic failed: topic: " + nextTopic + ", message:"+ message + ",next body: " + nextBody); } } } } catch (Throwable e) { throw new RuntimeException(ExceptionUtil.getMessage(e)); } } ); }
Example 14
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 4 votes |
/** * This is an advice used around calls from static elements to constructors. * * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && !this(java.lang.Object) && target(targetObject) && notWithinKieker()") public Object static2constructor(final Object targetObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final Signature callerSig = thisEnclosingJoinPoint.getSignature(); final String caller = this.signatureToLongString(callerSig); final String callerClazz = callerSig.getDeclaringTypeName(); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); final int calleeObjectId = System.identityHashCode(targetObject); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, 0, calleeObjectId)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 15
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 4 votes |
/** * This is an advice used around calls from members to constructors. * * @param thisObject * The caller object. * @param thisJoinPoint * The joint point of the callee. * @param thisEnclosingJoinPoint * The joint point of the caller. * * @return The result of {@code proceed method} of the given joint point. * * @throws Throwable */ @Around("monitoredConstructor() && this(thisObject) && target(targetObject) && notWithinKieker()") public Object member2constructor(final Object thisObject, final Object targetObject, final ProceedingJoinPoint thisJoinPoint, final EnclosingStaticPart thisEnclosingJoinPoint) throws Throwable { // NOCS if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature calleeSig = thisJoinPoint.getSignature(); final String callee = this.signatureToLongString(calleeSig); if (!CTRLINST.isProbeActivated(callee)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); // caller final String caller = this.signatureToLongString(thisEnclosingJoinPoint.getSignature()); final String callerClazz = thisObject.getClass().getName(); final int callerObjectId = System.identityHashCode(thisObject); // callee final String calleeClazz = calleeSig.getDeclaringTypeName(); final int calleeObjectId = System.identityHashCode(targetObject); // measure before call CTRLINST.newMonitoringRecord(new CallConstructorObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), caller, callerClazz, callee, calleeClazz, callerObjectId, calleeObjectId)); // call of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } return retval; }
Example 16
Source File: AbstractAspect.java From kieker with Apache License 2.0 | 4 votes |
/** * This advice is used around static operations. * * @param thisJoinPoint * The joint point of the advice. * * @return The return value of the joint point's {@code proceed} method. * * @throws Throwable */ @Around("monitoredOperation() && !this(java.lang.Object) && notWithinKieker()") public Object staticOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable) if (!CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); } final Signature sig = thisJoinPoint.getSignature(); final String operationSignature = this.signatureToLongString(sig); if (!CTRLINST.isProbeActivated(operationSignature)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = TRACEREGISTRY.registerTrace(); CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); final String clazz = sig.getDeclaringTypeName(); // measure before execution CTRLINST.newMonitoringRecord(new BeforeOperationObjectInterfaceEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, 0, AbstractAspect.getInterface(thisJoinPoint))); // execution of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } catch (final Throwable th) { // NOPMD NOCS (catch throw might ok here) // measure after failed execution CTRLINST.newMonitoringRecord(new AfterOperationFailedObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString(), 0)); throw th; } finally { if (newTrace) { // close the trace TRACEREGISTRY.unregisterTrace(); } } // measure after successful execution CTRLINST.newMonitoringRecord(new AfterOperationObjectEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, 0)); return retval; }
Example 17
Source File: SysLogRecoderAspect.java From mumu with Apache License 2.0 | 4 votes |
/** * 构建日志参数 * @param joinPoint * @return */ private SysUserLog buildLog(ProceedingJoinPoint joinPoint) throws Throwable { SysUserLog userLog = new SysUserLog(); try{ Object principal = SecurityUtils.getSubject().getPrincipal(); if (principal != null) { userLog.setCreator(SecurityUtils.getSubject().getPrincipal().toString()); } SysUser user = (SysUser) SecurityUtils.getSubject().getSession(true).getAttribute(SysUser.SYS_USER); if (user != null) { userLog.setUserId(user.getUserId()); userLog.setUserName(user.getUserName()); } userLog.setIp(SecurityUtils.getSubject().getSession(true).getHost()); }catch (Exception e){ //TODO No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration. } userLog.setCreateTime(new Date()); //将日志信息打印在控制台 Signature signature = joinPoint.getSignature(); String method=signature.getDeclaringTypeName() + " " + signature.getName(); userLog.setMethod(method); //String parameter=StringUtils.join(joinPoint.getArgs(),","); StringBuilder builder=new StringBuilder(); Object[] joinPointArgs = joinPoint.getArgs(); for (Object arg:joinPointArgs){ if(arg instanceof HttpServletRequest||arg instanceof HttpServletResponse){ continue; } if(arg instanceof Serializable){ builder.append(gson.toJson(arg)+","); }else{ builder.append(arg+","); } } int lastIndexOf = builder.lastIndexOf(","); if(lastIndexOf>-1){ builder.deleteCharAt(lastIndexOf); } userLog.setParameter(builder.toString()); long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long end = System.currentTimeMillis(); String result=gson.toJson(proceed); userLog.setResult(result); userLog.setProceed(proceed); String usetime=(end - start) + "ms"; userLog.setUsetime(usetime); return userLog; }
Example 18
Source File: FallbackOnlyAspect.java From x7 with Apache License 2.0 | 4 votes |
@Around("cut() && @annotation(fallbackOnly) ") public Object around(ProceedingJoinPoint proceedingJoinPoint, FallbackOnly fallbackOnly) { long startTime = System.currentTimeMillis(); Object[] args = proceedingJoinPoint.getArgs(); Signature signature = proceedingJoinPoint.getSignature(); String logStr = signature.getDeclaringTypeName() + "." + signature.getName(); if (args == null || args.length == 0) throw new IllegalArgumentException(logStr + ", @fallbackOnly not support no args' method"); Class<? extends Throwable>[] clzzArr = fallbackOnly.exceptions(); try { MethodSignature ms = ((MethodSignature) signature); if (ms.getReturnType() == void.class) { proceedingJoinPoint.proceed(); return null; } else { return proceedingJoinPoint.proceed(); } } catch (Throwable e) { for (Class<? extends Throwable> clzz : clzzArr) { if (e.getClass() == clzz || e.getClass().isAssignableFrom(clzz)) { Class fallbackClzz = fallbackOnly.fallback(); if (fallbackClzz == void.class) break; try { Object obj = fallbackClzz.newInstance(); String methodName = signature.getName(); Class[] clzzs= new Class[args.length]; for (int i=0; i<args.length; i++){ clzzs[i] = args[i].getClass(); } fallbackClzz.getDeclaredMethod(methodName,clzzs).invoke(obj,args); }catch (Exception ee){ e.printStackTrace(); } break; } } throw new RuntimeException(ExceptionUtil.getMessage(e)); } }