フィールド・レイアウトがわかっている場合は、コンパイル時にイベントを定義することを強くお薦めします。したがって、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
オブジェクトを作成します。このイベント・ファクトリに関連付けられているイベント・タイプを返します。newEvent()
イベントをインスタンス化することで、データを移入してFlight Recorderシステムに書き込むことができます。void
register()
登録されていないイベントを登録します。void
このイベント・ファクトリに関連付けられているイベントを登録解除します。
-
メソッドの詳細
-
create
public static EventFactory create(List<AnnotationElement> annotationElements, List<ValueDescriptor> fields) EventFactory
オブジェクトを作成します。値記述子の順序は、イベント値の設定時に使用する索引を指定します。
- パラメータ:
annotationElements
- イベントの注釈を説明する注釈要素のリスト(null
ではない)fields
- イベントのフィールドを説明する記述子のリスト(null
ではありません)- 戻り値:
null
ではなくイベント・ファクトリ- 例外:
IllegalArgumentException
- 入力が有効でない場合。 たとえば、フィールドのタイプまたは名前がJava言語で無効な場合や、注釈要素が見つからないタイプを参照している場合、入力が有効でない可能性があります。SecurityException
- セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")
がない場合- 関連項目:
-
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")
がない場合- 関連項目:
-
unregister
public void unregister()このイベント・ファクトリに関連付けられているイベントを登録解除します。未登録イベント・クラスはFlight Recorderにデータを書き込むことはできず、
FlightRecorder.getEventTypes()
を起動してもイベント・メタデータを取得できません。このイベント・ファクトリに関連付けられているイベント・クラスがまだ登録されていない場合、このメソッドの呼出しは無視されます。
- 例外:
SecurityException
- セキュリティ・マネージャが存在し、呼び出し元にFlightRecorderPermission("registerEvent")
がない場合- 関連項目:
-