EventFilter
Overview
OPC UA Part 4 §7.18 EventFilter consists of two parts:
- selectClauses — Which fields to capture
- whereClause — Filter Criteria (V1 Not yet implemented)
The corresponding types on the Java side are EventFilterDef.Filter (overall) and EventFilterDef.Operand (single SELECT clause, schema name SimpleAttributeOperand):
| Operand Parameter | Note |
|---|---|
| typeDefinitionId | Event type NodeId, such as "i=2041"; "null" is treated as a wildcard |
| browsePath | Field Path (String[]) |
| attributeId | Property Id; if null is passed, the default value is used. Enums.AttributeId.Value |
| indexRange | Array index (usually null) |
If no custom filter is provided, the underlying system subscribes to 4 fixed fields: Severity / Message / SourceName / Time, Corresponds to severity / message / sourceName / in the callback timeFt.EventId / EventType is not included in the subscription: is eventType always null in the callback, and the original EventId value is not ByteString exposed.
API
// Single SELECT clause (schema name SimpleAttributeOperand)
public record EventFilterDef.Operand(String typeDefinitionId, String[] browsePath,
Enums.AttributeId attributeId, String indexRange)
// Integral Filter (Specification Name EventFilter)
public record EventFilterDef.Filter(EventFilterDef.Operand[] selectClauses, String whereClause)
// On the container that is already attached, press EventSubscription "filter" to switch MI
public void OpcUaEventSubscription.subscribe(String objectNodeId, EventFilterDef.Filter filter)
// Event callback: Flat field snapshot, not an array Variant
public final List<Consumer<OpcUaEventSubscription.EventArrivedEventArgs>> onEventArrived
EventArrivedEventArgs There are only 6 fields: severity(int) / message(String) / sourceName(String) / timeFt(long, FileTime, 0 = none) / eventType(String) / arrivedAtUtc(Instant).eventType The current value is always null (the underlying type does not SelectClauses include this value EventType), and represents arrivedAtUtc the arrival time as recorded by the Java side.
Code Example
import com.darra.opcua.*;
import java.time.Instant;
try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();
// selectClauses: Specify the fields of interest one by one (the current Stack does not expose custom fields; see “Implementation Notes”)
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 Not implemented; pass null
EventFilterDef.Filter filter = new EventFilterDef.Filter(select, null);
OpcUaEventSubscription ev = ua.subscribeEvents();
try (ev) {
ev.subscribe("i=2253", filter); // selectClauses Replace the default with a custom one MI
ev.onEventArrived.add(args -> {
// A callback is a snapshot of a flat field; it is not exposed by index 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);
});
}
}
Field Quick Reference
Common field paths to include in EventFilterDef.Operand.browsePath (these will only be available once the custom selectClauses takes effect):
| EventType | BrowsePath | Meaning |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | Unique Event ID (byte[]) |
| BaseEventType | ["Severity"] | Severity 1–1000 |
| ConditionType (i=2782) | ["ConditionId"] | Conditions NodeId |
| ConditionType | ["EnabledState", "Id"] | bool Enabled |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | bool Is Ack |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | bool IsActive |
Implementation Notes
- Custom EventFilter Currently not in effect: When
filter.selectClauses()the input is not empty SDKRevert to the fixed 4 fields (Severity / Message / SourceName / Time), and send a Diagnostic Info event;filterstill cached for reconnection and reconstruction - CallbackDo not expose the results of select_clauses by index:
EventArrivedEventArgsOnly the 6 flat fields API listed in one section, EventId Original Not currently ByteString visible whereClause(ContentFilter) V1 Not implemented; pass null
Best Practices
- Explicitly list the fields; don't rely on the default settings.
- In the callback, retrieve values by field name (
args.severity/args.message), not by index. - To use the alarm panel ConditionId, first list selectClauses it in (custom fields are not currently exposed; see the implementation notes).
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilterDef.Filter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | EventFilterDef.Operand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |