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

クラスEventFactory


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

    フィールド・レイアウトがわかっている場合は、コンパイル時にイベントを定義することを強くお薦めします。したがって、Java Virtual Machine (JVM)はコードを最適化できます。Flight Recorderが非アクティブな場合、またはこのイベントの有効な設定がfalseに設定されている場合は、すべてのインストゥルメンテーションが削除される可能性があります。

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

    次の例は、動的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
    • メソッドのサマリー

      修飾子と型 メソッド 説明
      static EventFactory create​(List<AnnotationElement> annotationElements, List<ValueDescriptor> fields)
      EventFactoryオブジェクトを作成します。
      EventType getEventType()
      このイベント・ファクトリに関連付けられているイベント・タイプを返します。
      Event newEvent()
      イベントをインスタンス化することで、データを移入してFlight Recorderシステムに書き込むことができます。
      void register()
      登録されていないイベントを登録します。
      void unregister()
      このイベント・ファクトリに関連付けられているイベントを登録解除します。
    • メソッドの詳細

      • create

        public static EventFactory create​(List<AnnotationElement> annotationElements,
                                          List<ValueDescriptor> fields)
        EventFactoryオブジェクトを作成します。

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

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

        public Event newEvent()
        イベントをインスタンス化することで、データを移入してFlight Recorderシステムに書き込むことができます。

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

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

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

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

        デフォルトでは、イベントにRegistered注釈がない場合、イベント・ファクトリが作成されると、このイベント・ファクトリに関連付けられたイベント・クラスが登録されます。

        登録済イベント・クラスはFlight Recorderにデータを書き込むことができ、FlightRecorder.getEventTypes()を呼び出してイベント・メタデータを取得できます。

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

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

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

        未登録イベント・クラスはFlight Recorderにデータを書き込むことはできず、FlightRecorder.getEventTypes()を起動してもイベント・メタデータを取得できません。

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

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