[英]How to filter out events coming to UaMonitoredItem in OPC UA Milo?
I am trying to write an internal application event log based on UaMonitoredItem and its setValueConsumer(ValueConsumer valueConsumer) method.我正在尝试基于UaMonitoredItem及其setValueConsumer(ValueConsumer valueConsumer)方法编写内部应用程序事件日志。 Is it possible to filter out events coming to UaMonitoredItems after the "initialization"/"first use" of the setValueConsumer(ValueConsumer valueConsumer) method, and not during?
是否可以在setValueConsumer(ValueConsumer valueConsumer)方法的“初始化”/“首次使用”之后过滤掉到达UaMonitoredItems的事件,而不是在此期间? Would using ManagedDataItem or ManagedEventItem be a good practice in this case?
在这种情况下,使用ManagedDataItem或ManagedEventItem会是一个好习惯吗?
Code for example:代码例如:
public void subscribeOnComponentsEvent(List list) {
//....
//Created in MonitoringMode.Sampling to avoid race condition
for (UaMonitoredItem item : monitoredItems) {
allMonitoredItems.add(item);
item.setValueConsumer((e, vs) -> {
logger.info("Received from {}", e.getReadValueId().getNodeId());
});
}
}
public void setMonitoringMode(MonitoringMode mode) {
try {
subscription.setMonitoringMode(mode, allMonitoredItems).get();
} catch (InterruptedException | ExecutionException e) {
logger.error(e.getMessage());
}
}
public static void main(String[] args) {
//...
client.subscribeOnComponentsEvent(list);
client.setMonitoringMode(MonitoringMode.Reporting);
}
Output of code example: Output 的代码示例:
[milo-shared-thread-pool-3] INFO client.Client - Received from NodeId{ns=1, id=state_open}
[milo-shared-thread-pool-3] INFO client.Client - Received from NodeId{ns=1, id=state_closed}
[milo-shared-thread-pool-3] INFO client.Client - Received from NodeId{ns=1, id=state_alarm}
When the application starts, this code starts immediately, therefore, data from monitors that may have already been in the log will be re-written to the log.当应用程序启动时,此代码会立即启动,因此,可能已经在日志中的监视器中的数据将被重新写入日志。
Is there a way to avoid re-writing data to the log?有没有办法避免将数据重新写入日志?
This code doesn't start or run immediately, it's only going to run once the MonitoredItem has been created and the server sends a notification.此代码不会立即启动或运行,它只会在创建 MonitoredItem 并且服务器发送通知后运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.