什么是关于btrace的代码的意思

时间:2013-10-17 14:44:05

标签: java btrace

在以下代码中:

import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
import org.jboss.deployment.DeploymentInfo; 

@BTrace public class Trace{
   @OnMethod(
      clazz="org.jboss.deployment.SARDeployer",
      method="parseDocument"
   )
   public static void traceExecute(DeploymentInfo di){
      printFields(di);
   }

   @OnMethod(
      clazz="java.net.URL",
      method="openConnection",
      location=@Location(Kind.RETURN)
   )
   public static void resolveEntity(@Self Object instance){
     String protocol = str(get(field("java.net.URL", "protocol"),instance));
     String file = str(get(field("java.net.URL", "file"),instance));
     if(startsWith(protocol,"http") && (endsWith(file,".xsd") || endsWith(file,".dtd"))){
        String authority = str(get(field("java.net.URL", "authority"),instance));
        String path = str(get(field("java.net.URL", "path"),instance));
        println("=====================================");
        print(protocol);
        print("://");
        print(authority);
        print(path);
        println(" not found!");
        println("who call:");
        jstack();
     }
   }
}

这是什么意思:get(field("java.net.URL", "authority"),instance)

请参阅文档。

1 个答案:

答案 0 :(得分:1)

field("java.net.URL", "authority")将安全地从类 java.net.URL

中检索名为权限的字段

get(field, instance)反复获取指定实例中给定字段的值。

Javadoc for BTraceUtils是一个很好的起点。