- java.lang.Object
-
- 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
-
-
メソッドのサマリー
すべてのメソッド 静的メソッド インスタンス・メソッド 具象メソッド 修飾子と型 メソッド 説明 static EventFactory
create(List<AnnotationElement> annotationElements, List<ValueDescriptor> fields)
EventFactory
を作成します。EventType
getEventType()
このファクトリに関連付けられたイベント・タイプを返します。Event
newEvent()
イベントをインスタンス化するため、データを入力してコミットできます。void
register()
登録されていないイベントを登録します。void
unregister()
このファクトリに関連付けられたイベントの登録を解除します。
-
-
-
メソッドの詳細
-
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にデータを書き込むことができ、
EventType
はFlightRecorder.getEventTypes()
を呼び出すことで取得できます。このファクトリに関連付けられたイベント・クラスがすでに登録されている場合、このメソッドへの呼び出しは無視されます。
- 例外:
SecurityException
- セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")
がない場合- 関連項目:
Registered
,FlightRecorder.register(Class)
-
unregister
public void unregister()
このファクトリに関連付けられたイベントの登録を解除します。登録されていないイベントは、Flight Recorderにデータを書き込むことができず、
FlightRecorder.getEventTypes()
を呼び出すことによってEventType
を取得することはできません。このファクトリに関連付けられたイベント・クラスがすでに登録されている場合、このメソッドへの呼び出しは無視されます。
- 例外:
SecurityException
- セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")
がない場合- 関連項目:
Registered
,FlightRecorder.unregister(Class)
-
-