Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » OM2M » Plugin for data monitoring
Plugin for data monitoring [message #1725645] Sat, 05 March 2016 17:58 Go to next message
Matej AA is currently offline Matej AAFriend
Messages: 23
Registered: February 2016
Junior Member
Hello,

i would like to create om2m plugin which will get (intercept) inserted data after new contentInstance and do something with it.

I was thinking about subscribing on application but i want this for all applications and i need get this data as fast as possible (dont want to loose to much time between new contentInstance and getting this data in my plugin). Is there any option that i could use ServiceTracker on SCL service or something like that?

I would rly appreciate your help.

M.

Re: Plugin for data monitoring [message #1725660 is a reply to message #1725645] Sun, 06 March 2016 00:30 Go to previous messageGo to next message
Matej AA is currently offline Matej AAFriend
Messages: 23
Registered: February 2016
Junior Member
Oh another question Smile Should i use Monitor and subscriptions instead of ServiceTracker? I would like insert this data in another database.

[Updated on: Sun, 06 March 2016 00:31]

Report message to a moderator

Re: Plugin for data monitoring [message #1725728 is a reply to message #1725660] Mon, 07 March 2016 10:26 Go to previous messageGo to next message
Francois AissaouiFriend
Messages: 38
Registered: April 2015
Member
Hello Matej,

In my point of view, you have multiple options to perform this operation.

The first one, as you pointed out, is making subscriptions on every container you are interested in and make your own computation in your plugin (push to another database as you mentioned). But this can be hard to make as, depending on your installation and deployment, you can have a lot of applications/containers and you have to create a lot of subscriptions.
Then, talking about the duration, the subscription is not that slow to be sent and is good enough for your intent. (it can be slow if you have a lot of subscriptions, depends on your configuration)

Another possibility, if you are brave enough to look at the ContentInstanceController in the core plugin, is to add directly a call to your plugin at the end of the creation of a ContentInstance (Threaded call of course to let the response of the request to be sent back). In that case, your plugin will be directly called and you will not have to make subscriptions.
Furthermore, you will have to use the ServiceTracker to find your plugin (you have some example in the platform, you just have to look at Activator classes).
The main concern in that case is that you have to change a part of code in the core plugin of the platform. This can be annoying to maintain as this is the main plugin that we change and update (for bug fix, enhancement, etc).

So the choice is yours but still, I would advise the first one which is more maintainable in my point of view.

Hope this can help,
François
Re: Plugin for data monitoring [message #1725804 is a reply to message #1725728] Mon, 07 March 2016 18:14 Go to previous messageGo to next message
Matej AA is currently offline Matej AAFriend
Messages: 23
Registered: February 2016
Junior Member
Thanks for your fast reply Smile Will try possibility with ContentInstanceController. So if i understand correct: if i use 'subscriptions' i must wait for data to be inserted in H2. So my insert in another database wont be faster then insert in H2?

Edited:
Checked ContentInstanceController.java and i see that code:
// Notify the subscribers
Notifier.notify(StatusCode.STATUS_CREATED, contentInstance);

execute before:
em.getTransaction().commit(); 

so my theory is wrong? Smile Notify happenes before insert in DB?

Edited2: Can i use ServiceTracker for my problem? Its possible that OM2M execute my logic in plugin after new contentInstance is added? I dont want to change any logic in core. So can i attach listener on SCL service(?) or something like that.

Thanks for help.

[Updated on: Mon, 07 March 2016 21:29]

Report message to a moderator

Re: Plugin for data monitoring [message #1725883 is a reply to message #1725804] Tue, 08 March 2016 09:36 Go to previous messageGo to next message
Francois AissaouiFriend
Messages: 38
Registered: April 2015
Member
As you said, the notification routine is started before the commit in the database. It does not really mean that the data is not yet in the database because EclipseLink provides a cache so the information can (maybe) be retrieved already.
Another point is that the notification mechanism is threaded, so the call to the notifier just start the thread and goes back to the Controller.

For your concern, you will have to create a new Service in your plugin that will implement an Interface that you will have to provide. So yes, you will have to use the ServiceTracker in the core Activator class to retrieve your service.
You will be able to store your service wherever you want (static way in ContentInstance controller for instance). Just remind to remove the reference in the "removedService" method on the ServiceTracker.
And then, when a ContentInstance is created, you will have to call your plugin using the reference you stored in the ContentInstance class.

Regards,
François

[Updated on: Tue, 08 March 2016 09:37]

Report message to a moderator

Re: Plugin for data monitoring [message #1725977 is a reply to message #1725883] Tue, 08 March 2016 18:31 Go to previous messageGo to next message
Matej AA is currently offline Matej AAFriend
Messages: 23
Registered: February 2016
Junior Member
Thanks for your reply. So if i understand correctly. I create new plugin, create new interface and implementation of this interface and in my plugin Activator method add:
bundleContext.registerService(MyService.class.getName(), new MyServiceImpl(), null);

Then in Core/Activator.java add:
 new ServiceTracker<Object, Object>(bundleContext, MyService.class.getName(), null) ....

and after that (as you said) when ContentInstance is created i call custom logic from my plugin.

So after all i have two options. If i modify core i can use option above, if i dont want to modify core i can use option with notifications. Is there any third option without core modifications and without notifications? Sry for bothering, just want to explore all possibilities Smile
Re: Plugin for data monitoring [message #1726050 is a reply to message #1725977] Wed, 09 March 2016 09:47 Go to previous messageGo to next message
Francois AissaouiFriend
Messages: 38
Registered: April 2015
Member
That is it for the service registration and the Service Tracker Smile

A "third" method would be to "poll" resources in all containers but this is not really efficient in your case.
In my point of view, you have the two methods that are the most efficient. That all for me, so I will let someone else suggest you something more!
Re: Plugin for data monitoring [message #1726145 is a reply to message #1725645] Thu, 10 March 2016 07:07 Go to previous message
Matej AA is currently offline Matej AAFriend
Messages: 23
Registered: February 2016
Junior Member
Ok, thanks for all your help.

Best regards,
Matej
Previous Topic:OM2M debugging - Eclipse
Next Topic:phidget connected to om2m
Goto Forum:
  


Current Time: Thu Apr 25 15:43:33 GMT 2024

Powered by FUDForum. Page generated in 0.03193 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top