[英]AspectJ - Load time weaving on java.net.Socket trouble
Source: 资源:
package net.andrewewhite.aspects;
import java.util.ArrayList;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Around;
@Aspect
public class SocketProfiler {
@Around("call(* java.net.Socket.connect(..)) || execution(* java.net.Socket.connect(..))")
public void SocketRead(ProceedingJoinPoint joinPoint) throws Throwable {
long time=0;
Object rt=null;
time= System.nanoTime();
joinPoint.proceed();
time=(System.nanoTime()-time)/1000;
com.profile.Profiler.socketRead.add(time);
}
}
aop.xml aop.xml文件
<aspectj>
<aspects>
<aspect name="net.andrewewhite.aspects.SocketProfiler"/>
</aspects>
<weaver options="-verbose -Xset:weaveJavaxPackages=true -Xset:weaveJavaPackages=true">
</weaver>
</aspectj>
-javaagent:D:\tools\aspectJn\lib\aspectjweaver.jar (on eclipse ide)
It works if i try to weaving the calls to system.out.println. 如果我尝试编织对system.out.println的调用,它可以工作。 But when i try Java.net.Socket it doesn't.
但是,当我尝试Java.net.Socket时,它没有。 Any help in regard appreciated.
任何帮助表示赞赏。
Actually I have no problems weaving call(Socket.connect)
, but execution(Socket.connect)
is another story altogether, because 实际上我编织
call(Socket.connect)
没有问题call(Socket.connect)
,但execution(Socket.connect)
完全是另一个故事,因为
call(Socket.connect)
matches join points in your client code, ie all the places in your code where the method is called, call(Socket.connect)
匹配客户端代码中的连接点,即代码中调用方法的所有位置, execution(Socket.connect)
matches join points in JDK code, but JDK packages java
and javax
are excluded from weaving by default. execution(Socket.connect)
匹配JDK代码中的连接点,但JDK包java
和javax
默认情况下不包括在编织中。 This seems to be the day on which I stumble upon this type of questions (or similar), so you may want to read my answers here and there for further information. 这似乎是我偶然发现这类问题(或类似问题)的日子,所以你可能想在这里和那里阅读我的答案以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.