FragmentAtClassScope 예제

이 예제는 FragmentAtClassScope 프로브 단편의 사용 방법을 예시합니다.

이 예제에서 프로브는 "com.sample*" 와일드 카드 패턴과 일치하는 패키지 내에 있는 모든 클래스의 작성된 인스턴스 수를 계수하고 100번째 인스턴스가 작성될 때마다 이를 보고합니다.

"fragment at class scope"은 entry 단편이 컴파일되는 클래스에서 int 유형의 정적 필드로 나타나는 카운터를 선언합니다. 이 단편은 프로브가 로드되었음을 보고하는 fragment 클래스에 대한 정적 초기화 프로그램도 선언합니다. fragmentAtClassScope 섹션의 항목은 프로브가 적용되는 클래스에 빌드되지 않고 생성된 프로브 클래스에 빌드됩니다. 정적 필드 또는 정적 초기화 프로그램 논리를 프로브가 적용되는 클래스에 삽입하려면 staticFieldstaticInitializer 오브젝트를 사용하십시오.

이 예제 코드를 사용하려면 대상 오브젝트에 있는 package="com.sample*"을 실제 패키지 이름으로 참조하도록 변경하십시오.

XML에서 &< 문자를 사용하려면 예제에 표시된 대로 문자 엔티티 &amp;&lt;를 지정해야 합니다.

<?xml version="1.0" encoding="ASCII"?>
<probekit>
   <probe>
      <fragmentAtClassScope>
         static public int entry_counter = 0;
         static int counter = 0;
         static { System.out.println("[fragmentAtClassScope sample probe has loaded.]"); }
      </fragmentAtClassScope>
      <target type="include" package="com.sample*" method="&lt;init>" />
      <target type="exclude" package="*" />
      <fragment type="entry">
         <code>
            ++counter;
            if (counter % 100 == 0)
              System.out.println("[" + counter + " instances of classes in com.sample package so far]");
         </code>
      </fragment>
   </probe>
</probekit>

상위 주제: Probekit 예제

관련 참조
FragmentAtClassScope 프로브 오브젝트

Copyright IBM Corporation and others 2000, 2004.