EventFilter
개요
OPC UA Part 4 §7.18 EventFilter 두 부분으로 구성된다:
- selectClauses — 어떤 필드를 추출할 것인가
- whereClause — 필터 조건 (V1 아직 구현되지 않음)
Java 측의 대응되는 유형은 EventFilterDef.Filter (전체)와 EventFilterDef.Operand (단일 select 절, 규격명 SimpleAttributeOperand)입니다:
| Operand 매개변수 | 설명 |
|---|---|
| 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이며(기본값은 없음 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 후에야 확인할 수 있음):
| EventType | BrowsePath | 의미 |
|---|---|---|
| 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# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilterDef.Filter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | EventFilterDef.Operand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |