Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
MonitoredEventItems handling
May 8, 2012
13:26, EEST
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Looking at the SampleConsoleServer there is an own NodeManager implemented providing its own EventManagerListener. In my server application I’ll have to send events to a client after polling them from a database (at fixed interval).

In my model I created HasNotifier references from server down to the node generating the event. I see this structure under server node also. Now my question:

As with BigNodeManager for DataItems I override onAfterCreateMonitoredEventItem() and put new MonitoredEventItems to a Collection of such items. For my understanding, a client may subscribe events starting from Server node and down to the nodes generating events. How do you handle these different possibilities? How will I decide which events to forward to the client?

Example:

Server
+- Folder A
+- Folder B
+- Node A
+- Node B

Node A and B will Generate events of type “MySimpleEventType” every 10 seconds.

Scenario 1: Client subscribes to events from Server node (drag&drop Server node to Event view in UaExpert)
Expected: Client gets notified on each event from both, A and B

Scenario 2: Client subscribes to events from Node A only
Expected: Notified for A only. No notification for Node B

Scenario 3: Same as Scenario 2, but for Node B

Problem is how to I manage this monitoredItems collection in order to find the correct events to forward to the client? For server I will have to iterate through the list of all nodes within server?

In addition, it seems to me that a subscription for Server node is done immediately after connecting the client. Is this correct?

Thanks

May 8, 2012
14:28, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

With NodeManagerUaNode and UaNode objects the SDK uses the (inverse) HasEventSource, HasNotifier and HasCondition references to trigger the event for every node in the hierarchy – and the MonitoredEventItems get notified via that.

If you are not using NodeManagerUaNode, you must keep track of the hierarchy yourself and locate the MonitoredEventItems that are affected accordingly.

Some clients may start monitoring the Server object immediately, yes.

May 9, 2012
6:15, EEST
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

When I now watch the Server node for new events, I get events from Node A and B, which is the correct behavior. However, when I only subscribe to events from Node B, I also get the events from Node A. The problem will be the implementation of my trigger method.

public void onAfterCreateMonitoredEventItem(ServiceContext sc, Subscription s, MonitoredEventItem mei) {

//Add all items that monitor the same node to the same collection
final String eventItemName = mei.getNode().getDisplayName().getText();
Collection<MonitoredEventItem> c = monitoredItems.get(eventItemName);

if(c == null) {
c = new CopyOnWriteArrayList<MonitoredEventItem>();
monitoredItems.put(eventItemName, c);
}

c.add(mei);

if(logger.isDebugEnabled()) {
logger.debug("nodeId=" + mei.getNodeId() + ", monitoredItems.size()=" + monitoredItems.size());
}
}

public static void triggerMyEvent(MySingleEvent singleEvent) throws StatusException, ParseException {
// Trigger event
final DateTime now = DateTime.currentTime();
byte[] myEventId = getNextUserEventId();
MyObjectNode mon = collItems.get(singleEvent.getName());

collItems.get(singleEvent.getPointName());

MyEventType me = mon.getMyEventType();

me.setSource(mon);
me.setSourceNode(mon.getNodeId());
me.setMessage("Event occured");

Calendar cal = Calendar.getInstance();
cal.setTime(singleEvent.getTime());

//Trigger Event
me.triggerEvent(new DateTime(cal), now, myEventId);

logger.info("me " + me.getDisplayName()+ " is monitored: "+ me.isMonitoredForEvents());

for(String s : monitoredItems.keySet()) {
Collection<MonitoredEventItem> c = monitoredItems.get(s);
if(c != null) {
for(MonitoredEventItem item : c) {
if(logger.isDebugEnabled()) {
logger.debug(me.toString());
}

EventData eventData = new EventData(me, myEventId);
eventData.setEventType(MyNodeManager.getMyEventTypeNode());
item.onEvent(mon, eventData);
}
}
}
}

Do I have to use EventFilter in order to get the correct results?

Thanks

May 9, 2012
7:21, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

fred said

When I now watch the Server node for new events, I get events from Node A and B, which is the correct behavior. However, when I only subscribe to events from Node B, I also get the events from Node A. The problem will be the implementation of my trigger method.


item.onEvent(mon, eventData);

I did not locate where you select the item for which you call onEvent – you should only use the ones that are monitoring the node that you trigger the event for (or one connected to it with an inverse HasEventSource etc. reference).

Do I have to use EventFilter in order to get the correct results?

No, the filter is not used to define the “hierarchy filtering” – only filtering based on EventData contents.

May 9, 2012
12:00, EEST
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Right now I use a HashMap (collItems) where each Node (something stored in a database generating events) is listed. The server polls a database table in which events are stored and also new events are added. These events are retrieved by the OPC-UA Server and for each event I will trigger a event of a certain type. Out of the database I also get the information on the name of the node to map the event to.

=> item is a MonitoredEventItem which was put on the list with method onAfterCreateMonitoredEventItem(…)

Does this mean that I only have to compare the name included in the event from the database, with the names of the MonitoredEventItems and if they are equal, just call onEvent on this item? This is what I have done before and it was ok whenever I watch Node A or Node B.

The only problem is, if the name of the MonitoredEventItem is “SERVER” beaucse one has chosen to subscribe to all events in server -which in fact are all, my comparison will never return true and NO event will be forwarded.

To shorten, how will I now that someone who subscribed to node “Server” is interested of both, events from Node A, and Node B or in other words, how to I send the correct items to the following clients (only having a list of MonitoredEventItems with names of nodes):

Client A: Subscribed to Node A
Client B: Subscribed to Node B
Client C: Subscribed to Node SERVER

Additional Info: I also trigger data item changes. This works different as far as I understand (I only call triggerEvent for the corresponding type within the node), but this works correctly when I subscribe to server.

May 9, 2012
12:20, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Server object is of course easy, since you can trigger all events for items that are monitoring the Server.

But if there are items monitoring “parents” of Node A or Node B, you must be able to find them as well.

So, in practice, you must keep the hierarchy information as well in your own structures, so that you find all the items that are actually interested in Node A, for example.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 678

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6259

Newest Members:

DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1