メインコンテンツまでスキップ

EventFilter

概要​

OPC UA Part 4 §7.18 EventFilter 二つの部分から構成される:

  • selectClauses — どのフィールドを抽出するか
  • whereClause — フィルタ条件 (V1 未実装)

Java 側の対応する型は EventFilterDef.Filter (全体) および EventFilterDef.Operand (個々の select 句、仕様名 SimpleAttributeOperand) です:

オペランド パラメータ説明
typeDefinitionIdイベントの種類 NodeId、例:"i=2041";null はワイルドカードとして扱われる
browsePathフィールドパス (String[])
attributeId属性 Id、null を渡すとデフォルト値 Enums.AttributeId.Value
indexRange配列のインデックス(通常は null)

カスタムフィルターを指定しない場合、基盤層では以下の4つのフィールドが固定でサブスクライブされます: Severity / Message / SourceName / Time, コールバック内では severity / message / sourceName / に対応します timeFt。EventId / EventType がサブスクリプションに含まれていない場合:コールバックの eventType は常に null となり、 EventId の元の値も公開 ByteString されません。

API​

// 単一の select 句 (仕様名 SimpleAttributeOperand)
public record EventFilterDef.Operand(String typeDefinitionId, String[] browsePath,
Enums.AttributeId attributeId, String indexRange)

// トータルフィルター(規格名 EventFilter)
public record EventFilterDef.Filter(EventFilterDef.Operand[] selectClauses, String whereClause)

// コンテナが接続済みの で、「filter」を EventSubscription 押して切り替える MI
public void OpcUaEventSubscription.subscribe(String objectNodeId, EventFilterDef.Filter filter)

// イベントコールバック:フラットフィールドのスナップショット( Variant 配列ではない)
public final List<Consumer<OpcUaEventSubscription.EventArrivedEventArgs>> onEventArrived

EventArrivedEventArgs フィールドは6つだけである: severity(int) / message(String) / sourceName(String) / timeFt(long, FileTime, 0 = なし) / eventType(String) / arrivedAtUtc(Instant)。eventType 現在は常にnull(内部的にはnull SelectClauses ではない EventType)であり、Java側で記録された到着時刻 arrivedAtUtc である。

コード例​

import com.darra.opcua.*;
import java.time.Instant;

try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();

// selectClauses: 関心のあるフィールドを項目ごとに指定する(現在の Stack ではカスタムフィールドは表示されない。「実装説明」を参照)
EventFilterDef.Operand[] select = new EventFilterDef.Operand[] {
new EventFilterDef.Operand("i=2041", new String[]{"EventId"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2041", new String[]{"EventType"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2041", new String[]{"SourceName"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2041", new String[]{"Time"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2041", new String[]{"Message"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2041", new String[]{"Severity"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2782", new String[]{"ConditionId"}, Enums.AttributeId.Value, null),
new EventFilterDef.Operand("i=2915", new String[]{"ActiveState","Id"},Enums.AttributeId.Value, null)
};
// whereClause (ContentFilter) V1 未実装、null を渡す
EventFilterDef.Filter filter = new EventFilterDef.Filter(select, null);

OpcUaEventSubscription ev = ua.subscribeEvents();
try (ev) {
ev.subscribe("i=2253", filter); // デフォルトをカスタムに selectClauses 置き換える MI

ev.onEventArrived.add(args -> {
// コールバックはフラットなフィールドのスナップショットであり、インデックスに基づいて公開 selectClauses されることはありません。
Instant t = (args.timeFt > 0)
? Instant.ofEpochMilli((args.timeFt - 116444736000000000L) / 10000L)
: args.arrivedAtUtc;
System.out.printf("[%s] sev=%d src=%s: %s%n",
t, args.severity, args.sourceName, args.message);
});
}
}

フィールドのクイックリファレンス​

に記述する一般的な EventFilterDef.Operand.browsePath フィールドのパス(カスタム設定が実際に有効になってから取得 selectClauses 可能になります):

EventTypeBrowsePath意味
BaseEventType (i=2041)["EventId"]イベント一意ID (byte[])
BaseEventType["Severity"]深刻度 1~1000
ConditionType (i=2782)["ConditionId"]条件 NodeId
ConditionType["EnabledState", "Id"]bool 有効にするかどうか
AcknowledgeableConditionType (i=2881)["AckedState", "Id"]bool Ackかどうか
AlarmConditionType (i=2915)["ActiveState", "Id"]bool 有効か

実装の説明​

  • カスタム EventFilter 現在有効ではありません:引数が filter.selectClauses() 空でない場合 SDK 固定の4つのフィールドに戻す (深刻度 / メッセージ / SourceName / 時刻) とともに、Diagnostic Info イベントを一件送信し、再接続・ filter 再構築のためにキャッシュに残しておく
  • コールバックselect_clauses の結果をインデックスとして公開しない: EventArrivedEventArgs 一つのセクションにのみ記載 API されている6つのフラットフィールド、 EventId 元の ByteString 現在は表示されない
  • whereClause (ContentFilter) V1 未実装、null を渡す

ベストプラクティス​

  • フィールドを明示的に列挙し、デフォルトに頼らない
  • コールバック内でフィールド名を使用して値を取得する場合(args.severity / args.message)、下付き文字は使用しないでください。
  • アラームパネルには ConditionId、まず 内に一覧 selectClauses 表示する必要があります(カスタムフィールドは現在表示されません。実装説明を参照してください)。

多言語対照​

C#PythonJavaC++RustC
EventFilterEventFilterEventFilterDef.FilterEventFilterEventFilterDarraUa_EventFilter
SimpleAttributeOperandSimpleAttributeOperandEventFilterDef.OperandSimpleAttributeOperandSimpleAttributeOperandDarraUa_SimpleAttributeOperand

次のステップ​