org.aspectj.lang.JoinPoint.StaticPart Java Examples

The following examples show how to use org.aspectj.lang.JoinPoint.StaticPart. 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: MethodInvocationProceedingJoinPointTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCanGetStaticPartFromJoinPoint() {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
			StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
			assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
			assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
			assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
			assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	// Any call will do
	itb.getAge();
}
 
Example #2
Source File: AbstractAspectWithoutTraceRegistry.java    From kieker with Apache License 2.0 6 votes vote down vote up
@Before("monitoredOperation() && notWithinKieker()")
public void beforeOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}
	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	Long threadId = this.threadLocalId.get();
	if (null == threadId) {
		threadId = this.idGenerator.getNewId();
		this.threadLocalId.set(threadId);

		// CTRLINST.newMonitoringRecord(new TraceMetadata(-1, threadId, "<NO SESSION ID>", CTRLINST.getHostname(), -1, -1));
		CTRLINST.newMonitoringRecord(new ThreadMetaData(CTRLINST.getHostname(), threadId));
	}

	final int orderIndex = this.currentOrderIndex.get().incrementValue();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();

	CTRLINST.newMonitoringRecord(
			new BeforeThreadBasedEvent(TIME.getTime(), threadId, orderIndex, operationSignature, typeName));
}
 
Example #3
Source File: AbstractAspectWithoutTraceRegistry.java    From kieker with Apache License 2.0 6 votes vote down vote up
@AfterReturning("monitoredOperation() && notWithinKieker()")
public void afterReturningOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}
	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final long threadId = this.threadLocalId.get();
	final int orderIndex = this.currentOrderIndex.get().incrementValue();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();

	CTRLINST.newMonitoringRecord(
			new AfterThreadBasedEvent(TIME.getTime(), threadId, orderIndex, operationSignature, typeName));
}
 
Example #4
Source File: AbstractAspectWithoutTraceRegistry.java    From kieker with Apache License 2.0 6 votes vote down vote up
@AfterThrowing(pointcut = "monitoredOperation() && notWithinKieker()", throwing = "th")
public void afterThrowing(final StaticPart jpStaticPart, final Throwable th) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}
	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final long threadId = this.threadLocalId.get();
	final int orderIndex = this.currentOrderIndex.get().incrementValue();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();

	CTRLINST.newMonitoringRecord(new AfterFailedThreadBasedEvent(TIME.getTime(), threadId, orderIndex,
			operationSignature, typeName, th.toString()));
}
 
Example #5
Source File: AbstractAspect.java    From kieker with Apache License 2.0 6 votes vote down vote up
@AfterReturning("monitoredOperation() && notWithinKieker()")
public void afterReturningOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}

	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final TraceMetadata trace = TRACEREGISTRY.getTrace();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();

	CTRLINST.newMonitoringRecord(new AfterOperationEvent(TIME.getTime(), trace.getTraceId(), trace.getNextOrderId(), operationSignature, typeName));
}
 
Example #6
Source File: AbstractAspect.java    From kieker with Apache License 2.0 6 votes vote down vote up
@AfterThrowing(pointcut = "monitoredOperation() && notWithinKieker()", throwing = "th")
public void afterThrowing(final StaticPart jpStaticPart, final Throwable th) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}

	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final TraceMetadata trace = TRACEREGISTRY.getTrace();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();

	CTRLINST.newMonitoringRecord(
			new AfterOperationFailedEvent(TIME.getTime(), trace.getTraceId(), trace.getNextOrderId(), operationSignature, typeName, th.toString()));
}
 
Example #7
Source File: MethodInvocationProceedingJoinPointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCanGetStaticPartFromJoinPoint() {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
			assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
			assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
			assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
			assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	// Any call will do
	itb.getAge();
}
 
Example #8
Source File: AbstractAspect.java    From kieker with Apache License 2.0 6 votes vote down vote up
@After("monitoredOperation() && notWithinKieker()")
public void afterOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}

	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final int stackIndex = this.currentStackIndex.get().decrementValue();
	if (stackIndex == 1) {
		TRACEREGISTRY.unregisterTrace();
	}
}
 
Example #9
Source File: MethodInvocationProceedingJoinPointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCanGetStaticPartFromJoinPoint() {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
			StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
			assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
			assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
			assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
			assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	// Any call will do
	itb.getAge();
}
 
Example #10
Source File: NetworkOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void close(JoinPoint.StaticPart jp) throws IOException {
    Network.Close.starting(out, jp);
    try {
        out.close();
    } finally {
        Network.Close.finished(out, jp);
    }
}
 
Example #11
Source File: NetworkInputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public long skip(long n, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    long numSkipped = 0;
    try {
        return numSkipped = in.skip(n);
    } finally {
        Read.finished(in, numSkipped, jp);
    }
}
 
Example #12
Source File: NetworkInputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public NetworkInputStreamWrapper(InputStream is, JoinPoint.StaticPart jp, boolean isLoopback) {
    super(is);
    this.creator = jp;
    if (isLoopback)
        Read = Network.LoopbackRead;
    else
        Read = Network.Read;
}
 
Example #13
Source File: NetworkInputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int read(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    int numRead = 0;
    try {
        return numRead = in.read(b);
    } finally {
        Read.finished(in, numRead, jp);
    }
}
 
Example #14
Source File: NetworkInputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int read(JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    try {
        return in.read();
    } finally {
        Read.finished(in, 1, jp);
    }
}
 
Example #15
Source File: NetworkInputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int read(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    int numRead = 0;
    try {
        return numRead = in.read(b, off, len);
    } finally {
        Read.finished(in, numRead, jp);
    }
}
 
Example #16
Source File: XTraceReport.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Indicates that the execution is entering the specified join point, and that all X-Trace reports should attribute to this join point */
public static void entering(JoinPoint.StaticPart jp) {
    if (jp == null) {
        originalJp.remove();
    } else {
        originalJp.set(jp);
    }
}
 
Example #17
Source File: XTraceReport.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Add information to the report such as source line, etc. */
public void setJoinPoint(JoinPoint.StaticPart joinPoint) {
    JoinPoint.StaticPart originalJoinPoint = originalJp.get();
    if (originalJoinPoint != null) {
        builder.setSource(originalJoinPoint.getSourceLocation().toString());
    } else if (joinPoint != null) {
        builder.setSource(joinPoint.getSourceLocation().toString());
    }
}
 
Example #18
Source File: EALoggerImpl.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
public void logMethodExit(StaticPart staticPart, Object result) {
    // Nom de la méthode interceptée
    String name = staticPart.getSignature().toLongString();

    float time = ((float) (System.currentTimeMillis() - timeMap.get(name))) / 1000f;
    timeMap.remove(name);

    Logger.getLogger(EALoggerImpl.class).info(getHostname() + " - " + "LEAVING " + name + " returning: [" + result + "]");

    Logger.getLogger(EALoggerImpl.class).info("Execution Time is : " + time);
}
 
Example #19
Source File: AbstractAspect.java    From kieker with Apache License 2.0 5 votes vote down vote up
@Before("monitoredOperation() && notWithinKieker()")
public void beforeOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}
	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	TraceMetadata trace = TRACEREGISTRY.getTrace();
	final boolean newTrace = trace == null;
	if (newTrace) {
		trace = TRACEREGISTRY.registerTrace(); // TO-DO parent trace is never used, so reduce impl. (chw)
		CTRLINST.newMonitoringRecord(trace);
	}

	// long threadId = Thread.currentThread().getId();
	// int orderIndex = currentOrderIndex.get().incrementValue();
	// int stackIndex =
	this.currentStackIndex.get().incrementValue();

	final long traceId = trace.getTraceId();
	final String typeName = jpStaticPart.getSignature().getDeclaringTypeName();
	// measure before execution
	CTRLINST.newMonitoringRecord(
			new BeforeOperationEvent(TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, typeName));
}
 
Example #20
Source File: XTraceReport.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Turns this report into an X-Trace "event", by adding the current thread's
 * parent event IDs to the report, generating a random event ID for the
 * report, and updating the current thread's parent event IDs to this
 * report's event ID
 * @param joinPoint 
 * 
 * @return This report, with additional fields added
 */
public XTraceReport makeXTraceEvent(StaticPart joinPoint) {
    AtomicInteger counter = new AtomicInteger();
    long taskId = XTraceBaggageInterface.getTaskID(counter);
    if (counter.get() > 1) {
        builder.addTags("TracingError");
    }
    long eventId = XTrace.randomId();
    Collection<Long> parentIds = XTraceBaggageInterface.getParentEventIds();
    setXTrace(taskId, eventId, parentIds);
    XTraceBaggageInterface.setParentEventId(eventId);
    return this;
}
 
Example #21
Source File: FileOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, len, jp, true);
    try {
        super.write(b, off, len);
    } finally {
        DiskResource.Write.finished(this, len, jp, true);
        counter.wrote(len);
    }
}
 
Example #22
Source File: FileOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, b.length, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, b.length, jp, true);
        counter.wrote(b.length);
    }
}
 
Example #23
Source File: FileOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(int b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, 1, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, 1, jp, true);
        counter.wrote(1);
    }
}
 
Example #24
Source File: FileOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void flush(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Flush.starting(this, jp, true);
    try {
        super.flush();
    } finally {
        DiskResource.Flush.finished(this, jp, true);
    }
}
 
Example #25
Source File: FileOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void close(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Close.starting(this, jp, true);
    try {
        super.close();
    } finally {
        DiskResource.Close.finished(this, jp, true);
    }
}
 
Example #26
Source File: NetworkOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b, off, len);
    } finally {
        Write.finished(out, len, jp);
    }
}
 
Example #27
Source File: NetworkOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b);
    } finally {
        Write.finished(out, b.length, jp);
    }
}
 
Example #28
Source File: NetworkOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void write(int b, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b);
    } finally {
        Write.finished(out, 1, jp);
    }
}
 
Example #29
Source File: NetworkOutputStreamWrapper.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void flush(JoinPoint.StaticPart jp) throws IOException {
    Network.Flush.starting(out, jp);
    try {
        out.flush();
    } finally {
        Network.Flush.finished(out, jp);
    }
}
 
Example #30
Source File: MethodInvocationProceedingJoinPointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouse();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	}
	catch (IOException ex) {
		// we don't really care...
	}
}