简体   繁体   中英

Interpreting server response for events correclty

I would like to store values of event properties received from the server in a database. My problems are that in the event consumer:

  1. I cant figure out which eventtype my client received.
  2. I dont know how to map variant indexes to properties without knowing the EventType.

Events come with the property "EventType", which would solve my first problem. But since I am receiving many different event types, I do not know in which variant index it is located. Should I always relocate "EventType" at index 0 in the select clause whenever creating a new EventFilter?

For the second problem, item.getMonitoringFilter().decode(client.getSerializationContext())) offers a view on the property structure but I am not sure how to use it for mapping of variants to properties. Does anybody know how to solve those problems?

Here is the event consumer code that I use. It is taken from milo client examples.

for (UaMonitoredItem monitoredItem: mItems){
                monitoredItem.setEventConsumer((item, vs) -> {
                    LOGGER.info(
                        "Event Received from: {}", item.getReadValueId().getNodeId());
                    LOGGER.info(
                        "getMonitoredItemId: {}", item.getMonitoredItemId());
                    LOGGER.info(
                        "getMonitoringFilter: {}", item.getMonitoringFilter().decode(client.getSerializationContext()));
                    for (int i = 0; i < vs.length; i++) {
                        LOGGER.info("variant[{}]:, datatype={}, value={}", i, vs[i].getDataType(), vs[i].getValue());
                    }
                });
            }

Thank you in advance.

Update:

Seems I have figured it out, by typcasting to EventFilter. Further information such as qName for event properties or event type node IDs can then be derived:

ExtensionObject eObject = item.getMonitoringFilter();
EventFilter eFilter = ((EventFilter) eObject.decode(client.getSerializationContext()));
QualifiedName qName = eFilter.getSelectClauses()[0].getBrowsePath()[0];

LiteralOperand literalOperand  = (LiteralOperand) eFilter.getWhereClause().getElements()[0]
        .getFilterOperands()[1].decode(client.getSerializationContext());
NodeId eventTypeNodeId = (NodeId) literalOperand.getValue().getValue();

Didn't you supply the filter in the first place when you created the MonitoredItem? Why do you need to "reverse engineer" the filter result to get back to what you did in the first place?

The properties you receive in the event data and the order they come in are defined by the select clause you used when creating the MonitoredItem. If you choose to select the EventId field then it will always be at the same corresponding index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM