Home > Back-end >  Bytebuddy bytecode enhancement on type matching questions
Bytebuddy bytecode enhancement on type matching questions

Time:11-13

 public class MyAgent {

Public static void premain (String agentArgs, Instrumentation inst) {
System. The out. Println (" this is an perform monitor agent. ");

AgentBuilder. Transformer Transformer=new AgentBuilder. Transformer () {
@ Override
Public DynamicType. Builder<?> The transform (DynamicType. Builder<?> Builder,
The TypeDescription the TypeDescription,
This this) {
Return builder
Method (ElementMatchers. & lt; MethodDescription> Any ())//intercept any method
Intercept (MethodDelegation. To (TimeInterceptor. Class));//
}
};

AgentBuilder. Listener Listener=new AgentBuilder. Listener () {
@ Override
Public void onTransformation (the TypeDescription the TypeDescription, this this, JavaModule module, DynamicType DynamicType) {}

@ Override
Public void onIgnored (the TypeDescription the TypeDescription, this this, JavaModule module) {}

@ Override
Public void one rror (String typeName, this this, JavaModule module, Throwable Throwable) {}

@ Override
Public void the onComplete (String typeName, this this, JavaModule module) {}
};

New AgentBuilder
The Default ()
Type (ElementMatchers. NameStartsWith (" com. Example. The demo "))//specifies the class need to intercept the
. The transform (transformer)
With (the listener)
InstallOn (inst);
}
}



Consulting, the code above is can enhance, but if you don't write a complete package of type, for example. The type (ElementMatchers. NameStartsWith (" com ")) why can't increase?
  • Related