我正在尝试基于UaMonitoredItem及其setValueConsumer(ValueConsumer-ValueConsumer(方法编写内部应用程序事件日志。是否可以过滤掉在"之后进入UaMonitoredItems的事件;初始化"/"第一次使用";setValueConsumer(ValueConsumer-ValueConsumer(方法的,而不是在?在这种情况下,使用ManagedDataItem或 ManagedEventItem例如代码: 代码示例输出: 当应用程序启动时,此代码会立即启动,因此,来自监控器的可能已经在日志中的数据将被重新写入日志。 有没有办法避免将数据重新写入日志?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);
}
[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}
此代码不会立即启动或运行,它只会在创建MonitoredItem并且服务器发送通知后运行。