モジュール jdk.jfr
パッケージ jdk.jfr

クラスEventFactory


  • public final class EventFactory
    extends Object
    実行時にイベントを定義するクラス。

    フィールド・レイアウトがわかっている場合は、コンパイル時にイベントを定義することを強くお勧めします。JVMが積極的にコードを最適化し、Flight Recorderが無効であるか、イベントが無効になっていると、。

    コンパイル時にイベントを定義するには、Eventを参照してください。

    例,

     
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));
    
     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));
    
     EventFactory f = EventFactory.create(eventAnnotations, fields);
    
     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
     
     
    導入されたバージョン:
    9
    • メソッドの詳細

      • create

        public static EventFactory create​(List<AnnotationElement> annotationElements,
                                          List<ValueDescriptor> fields)
        EventFactoryを作成します。

        値記述子の順序は、イベント値を設定するときに使用する索引を決定します。

        パラメータ:
        annotationElements - nullではなく、イベントの注釈を記述するAnnotationElementのリスト
        fields - ValueDescriptorではなく、イベントのフィールドを記述するValueDescriptorをリスト
        戻り値:
        nullではなくイベント・ファクトリ
        例外:
        IllegalArgumentException - 入力が有効でない場合。 これは、フィールド型または名前がJava言語で有効でないか、注釈要素が見つからない型を参照している場合に発生します。
        SecurityException - セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")がない場合
        関連項目:
        Event.set(int, Object)
      • newEvent

        public Event newEvent()
        イベントをインスタンス化するため、データを入力してコミットできます。

        Event.set(int, Object)を使用して値を設定します。

        戻り値:
        nullではなくイベント・インスタンス
      • getEventType

        public EventType getEventType()
        このファクトリに関連付けられたイベント・タイプを返します。
        戻り値:
        nullではなく、このファクトリに関連付けられたイベント・タイプ
        例外:
        IllegalStateException - 注釈Registered(false)でイベント・ファクトリが作成され、このメソッドの起動前に手動で登録されていない場合
      • register

        public void register()
        登録されていないイベントを登録します。

        デフォルトでは、このファクトリに関連付けられたイベント・クラスは、イベントがRegistered注釈を持っていない限り、イベント・ファクトリの作成時に登録されます。

        登録されたイベントはFlight Recorderにデータを書き込むことができ、EventTypeFlightRecorder.getEventTypes()を呼び出すことで取得できます。

        このファクトリに関連付けられたイベント・クラスがすでに登録されている場合、このメソッドへの呼び出しは無視されます。

        例外:
        SecurityException - セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")がない場合
        関連項目:
        Registered, FlightRecorder.register(Class)
      • unregister

        public void unregister()
        このファクトリに関連付けられたイベントの登録を解除します。

        登録されていないイベントは、Flight Recorderにデータを書き込むことができず、FlightRecorder.getEventTypes()を呼び出すことによってEventTypeを取得することはできません。

        このファクトリに関連付けられたイベント・クラスがすでに登録されている場合、このメソッドへの呼び出しは無視されます。

        例外:
        SecurityException - セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")がない場合
        関連項目:
        Registered, FlightRecorder.unregister(Class)