jvermillard / leshan

OMA Lightweight M2M java implementation - LWM2M
40 stars 25 forks source link

experimental extension point for intercepting events #26

Closed andrau closed 10 years ago

andrau commented 10 years ago

intended for non-intrusive extensions of leshan, comments welcome

jvermillard commented 10 years ago

ping @msangoi @sbernard31 can you review it? I'm off next days :)

sbernard31 commented 10 years ago

I just have a look to your code, but I'm not sure to understand what you aim with this contribution. Can you help me by adding here more details, please ? :)

andrau commented 10 years ago

The intention is to intercept events like registration/deregistration or observe notification for extending leshan without intrusive changes to the existing classes, e.g. for logging or displaying data in a special way. Of course, the EventServlet itself could be dispatching the events, but that would seem a little strange. In my case, I use the events for logging and monitoring what devices do, but other applications like updating a custom UI are also conceivable. Basically, the point is to be able to extend leshan without creating a dependency from leshan to the extension in order to still being able to follow core development because the extension point is well-defined. I can implement the formal changes suggested by jvermillard if you give me a go ;-)

andrau commented 10 years ago

OK, I have made the changes as per the comments and merged with core, what's next?

sbernard31 commented 10 years ago

Leshan is composed of 2 parts :

To be clear leshan-standalone is not really intended to be reused. So we don't aim to make it extensible without modification. But If you still want to reuse it, you could create your own LeshanMain and reuse our servlets. In this case, you could add listener directly on ClientRegistry. For observation, you point an issue, we could only have one listener by observation. We should propose a better API for that. Maybe by adding listeners on ObservationRegistry.

andrau commented 10 years ago

Understood, but since leshan-standalone is a very nice and useful sample which you keep working on, it would still be great to be able to extend it as suggested. Given that the extension is quite simple, I would appreciate if you could integrate it. BTW, I also have an idea for an extension point on the UI side and by prominently offering the possibility for extensions, you might inspire people to build interesting extensions, don't you think?

msangoi commented 10 years ago

Hello Andreas,

I agree with Simon point since the core part already provides a listener mechanism to be notified of client registrations/deregistrations and resource observations. From my point of view, the standalone part is not really meant to be extended. It is a simple web-app on top of leshan-core that can be used as an example to build your own application. If you want to use leshan-standalone as a starting point for you own webapp, you could probably fork it and do some minor changes (or write your own main method) to use the current leshan-core API. What do you think ?

As mentioned by Simon, the current mechanism for listening observation events should be enhanced to provide a way to register several listeners. Would it match your use case ?

Manu