Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Introducing Notifications(Initial discussion and brainstorming)
Introducing Notifications [message #1707486] Sat, 05 September 2015 09:59 Go to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Hi all,

Cfr the various threads left and right, I have compiled some stuff in a basic UML that is up for discussion.

index.php/fa/23154/0/

Here are some quick thoughts of how it could work. I will have certainly missed things.

NotificationPublisher in essence create Notifications (through a NotificationFactory) which they post at the NotificationService (NS). the NS stamps the Notification with a configurable expiration timestamp and a sequential number. the NS then queries all NotificationSubscribers if they have interest in the given Notification (can be based on the Type of the Notification). The Notification and its list of interested Subscribers is then persisted, and the NS calls receiveNotification on all Subscribers.

Subscribers can present the Notification at the user, route it to an external service, whatever. Once a certain action (e.g. user input) is deemed completed, the Subscriber can acknowledge the Notification to the NS. Upon acknowledgment, the NS will then revoke the Notification from the other Subscribers that got the same Notification, and will finally let the NotificationPublisher know that the Notification was acknowledged (onAcknowledgment). At that point, the Notification is canned, but we could also opt to graveyard it in a persistent store for audit trailing purposes (alarm systems!)

Publishers can also, if necessary, revoke Notifications.

The NS constantly monitors the persistent store and prunes any expired notifications (e.g. no acknowledge received before the expiryDateTime of the Notificaiton). If a Notification expires, the Subscribers and the Publishers are signalled. For a subscriber that could mean that for example a UI dialog box is retired, and for example a publisher can take a decision, action to do something else based on the negative acknowledgment.

There is also a EventNotificationBridge that can, probably based on filters, convert Events into Notifications, which then can be routed to external services like PushOver and alike. Subscribers that offer no interactivity with a user or system, e.g. they just take the notification as is, can forego acknowledgment, or will not react on onRevoked, or onExpired. We will have to figure out how the payload of Events can be mapped on to Notifications? maybe Notifications also need a json payload field.


Few thoughts I had:
1. Should the NS track what Subscriber is interested in a given NotificationType, or should it query the Subscribers every time there is a Notification? the former might be more efficient, but the latter allows the Subscriber to change its interest over time, etc
2. Should all this happen in a synchronous way? do we need a sequence number on the Notification to keep things in order?
3. Do we need explicitly NotificationFilters ( and have the NS filter), or do we let that to the Subscriber to decide what it does with a Notification?


Regards
Karel
Re: Introducing Notifications [message #1707514 is a reply to message #1707486] Sun, 06 September 2015 14:09 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
index.php/fa/23156/0/

I made some further tweaks:

- Listing some possible types of notifications
- Include a mechanism to queue Notifications for future delivery

Browsing the web I was wondering if we should base ourselves on Apache Camel for the implementation, or not.

Karel
Re: Introducing Notifications [message #1707589 is a reply to message #1707514] Mon, 07 September 2015 16:48 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Would it make sense to have a getHistory(int number) method to the NotificationService so that any interested party can retrieve the latest <number> of Notifications, and for example display them in a UI ?
Re: Introducing Notifications [message #1707757 is a reply to message #1707589] Wed, 09 September 2015 07:55 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Another point of reflection: The proposal here above is largely based on the current Event infrastructure, which does not follow the "Registry" pattern that is used for Items, Things,.... The question arises wether we should take the former or the latter pattern. Using the latter, we could theoretically get Events whenever a Notification has been added, removed,... Or should we keep Notifications at the same level as the Events, threat them as "equal" and implement the necessary code to bridge from one to another. What are your thoughts?
Re: Introducing Notifications [message #1707985 is a reply to message #1707757] Fri, 11 September 2015 09:00 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Hi Karel,

I have discussed your proposal with Dennis yesterday. Here is some feedback:

The overall architecture looks quite good, but we would suggest to actually start a bit smaller. As a blueprint, we could use the PersistentInbox, since the discovery inbox seems to be a very similar functionality.

An initial implementation could have only 3 main classes (for which we would align the naming with the Android notification API (http://developer.android.com/guide/topics/ui/notifiers/notifications.html)):
- Notification
- NotificationBuilder (your NotificationFactory)
- NotificationManager (your NotificationService)

Let's describe them one by one:

Notification:
- We do not think that we need an expiry date as it will always be tough to come up with one
- The type could be just string instead of enum with constants being defined within the class (similar to Android)
- There should only be getter methods, no setters
- There is no localization feature within Notifications, they have to be created in the correct locale in the first place by the producer.
- As properties, we would hence suggest: String:id, String:title, String:text, String:icon, String:type, int:priority, URI:context, URI:action, boolean:sticky

NotificationBuilder:
- Similar to ThingBuilder or http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html
- Is used to construct Notification instances since they do not have any setters.

NotificationManager:
- has add, remove, update methods, which can be directly used by consumers; no need to have them implement a NotificationPublisher interface.
- sends events (of new Notification event types) whenever anything changes, so we do not need the NotificationSubscriber, since we can simply use the existing EventSubscriber infrastructure.

For producing notifications, we should not have a general EventNotificationBridge, since not all events make sense to have as notification (probably only a small fraction). So we should rather have dedicated notification producers, e.g. for thing offline notifications (which are deleted by this service when a thing gets online again). Such producers could be a second implementation phase, though.

What do you and others think about this approach?

Regards,
Kai
Re: Introducing Notifications [message #1708042 is a reply to message #1707985] Fri, 11 September 2015 16:51 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Just some thoughts:

- if not getters on Notification, how to read out properties? public members?
- great idea to leverage Events for Notifications, but this presumes a get(someNoficiationUID) method on NotificationManager in order to retrieve the notification after being signalled a new one is available
- Notification:id extends/implements UID.java?
- No sequence numbers for the Notifications? quid out of order processing, or notification "workflows" in that case? NotificationManager will use an ordered set to track Notifications? in that case, do we need getFirst(NotificationType), getLast(NotificationType), getCount(NotificationType) methods on NotificationManager?
- Could we not apply an EventFilter on the EventNotificationBridge to select what the end-user is interested in to receive? the use case might be different for everyone. Some are interested in Item updates, some maybe in ThingStatus for only specific Things and so forth
- no needsAcknowledgement / isAcknowledged property on Notification? Is the assumption here that the first EvenSubscriber acknowledging the Notification does that by remove()ing it from the NotificationManager and/or triggers a NotificationAcknowledgedEvent? Or does everyone Notification needs to be acknowlegded by default?
- who can remove() Notifications from the NotificationManager? the instance that add()ed it? everyone? or do we have an ageing mechanism that will automatically prune Notification from the NM ?
- do not fully agree on not having an expiry timestamp on the Notification: some processed expect interaction within a given time, in order to decide some action. Use case for example: alarm system un-arming

Regards
Karel
Re: Introducing Notifications [message #1708190 is a reply to message #1708042] Mon, 14 September 2015 12:43 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
- if not getters on Notification, how to read out properties? public members?

I said "no setters", not "no getters" Smile

- great idea to leverage Events for Notifications, but this presumes a get(someNoficiationUID) method on NotificationManager in order to retrieve the notification after being signalled a new one is available

No, the payload of the event would already contain the full notification; no need to get it from the NotificationManager. There is only a getAll for notifications that you might have missed in the past because you weren't listening to events.

- Notification:id extends/implements UID.java?

I would go for a simple String as I don't think that we need hierarchical IDs. And UID is currently in a thing package, so we would have to refactor that...

- No sequence numbers for the Notifications?

No, simply have an ordered list returned by getAll() - that should be imho enough (at least for a start)

- Could we not apply an EventFilter on the EventNotificationBridge to select what the end-user is interested in to receive?

My point was that you would want some custom code to transform events into notifications: You might want to aggregate, localize or enrich them. So we will probably need different specific "producers", which all could be configured by the user to define whether he is interested, what kind of notification he prefers etc. I would leave this implementation out of scope for the first step.

- no needsAcknowledgement / isAcknowledged property on Notification?

Yes, notifications would simple be removed (and subscribers are informed about that through an event)

- who can remove() Notifications from the NotificationManager?

Anybody.

- some processed expect interaction within a given time, in order to decide some action.

So this process is free at any time to delete the notification again Smile

Regards,
Kai
Re: Introducing Notifications [message #1708198 is a reply to message #1708190] Mon, 14 September 2015 14:57 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
No, the payload of the event would already contain the full notification; no need to get it from the NotificationManager. There is only a getAll for notifications that you might have missed in the past because you weren't listening to events.

-> So, there will be no way to change a Notification once it is generated/posted. Any change would then be done through a remove(), add() sequence, and thus generate a new Notification that might not be in sequence anymore. Just thinking out loud if that would be an issue for some use cases


- Notification:id extends/implements UID.java?

I would go for a simple String as I don't think that we need hierarchical IDs. And UID is currently in a thing package, so we would have to refactor that...

-> Could be something similar, with different parts separated by a : . We could include for example the name of the instance that generated the Notification. Ok for me to have a free-format id, but it will certainly not be unique then? Could that lead to duplicate Notifications, and would that be an issue?


- Could we not apply an EventFilter on the EventNotificationBridge to select what the end-user is interested in to receive?

My point was that you would want some custom code to transform events into notifications: You might want to aggregate, localize or enrich them. So we will probably need different specific "producers", which all could be configured by the user to define whether he is interested, what kind of notification he prefers etc. I would leave this implementation out of scope for the first step.

-> Whatever we decide to do, I will certainly contribute some implementation of this kind as I need it anyways in my setup, unless we are Ok that one can listen for Events instead, and inject these in an external system (cfr my pull request). If the route is to go for Notification as the "exit" strategy, then we would at least some Notification generators somewhere, no?


Regards
K
Re: Introducing Notifications [message #1708318 is a reply to message #1708198] Tue, 15 September 2015 13:18 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
> So, there will be no way to change a Notification once it is generated/posted. Any change would then be done through a remove(), add() sequence

No, just like the Inbox, the add would either add or update Notifications (using the id for comparison). To make it clear, the method might better be called addOrUpdate. If a Notification does not have an id, it is always considered to be a new one and an id can be automatically generated for it.

> Ok for me to have a free-format id, but it will certainly not be unique then?

Right, but we did the same for the new rules as well. I think if we have the convention that people should prefix there notifications with some suitable string, the risk to run into duplicates is neglectable.

> If the route is to go for Notification as the "exit" strategy, then we would at least some Notification generators somewhere, no?

Yes, of course. I only suggested to discuss their details as a second step as I consider them to be the "extensions" to the framework that we are discussion right now.
Re: Introducing Notifications [message #1708344 is a reply to message #1708318] Tue, 15 September 2015 17:31 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
I will try to make some time to write some .java that captures the discussion here above, using PersistentInbox etc as template. Once that is fleshed out a bit, we can rehash the discussion to solve whatever quirks I ran into
Re: Introducing Notifications [message #1708395 is a reply to message #1708344] Wed, 16 September 2015 08:52 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Just some comments after an initial round of coding Wink

- I have added a timestamp to the Notification, as I am using a StorageService to store them (currently mapDB) but which does not store order. So, with a custom comparator, Notifications returned from the store are ordered in a sequential order based on the timestamp. Also, a producer can use this timestamp later on to decide if a Notification has to be revoked/expired/remove()d
- I think we have to add a String:source property to the Notification, in order to let a producer of Notifications query/get() its own Notifications. Since we have the freetext UID property, we might introduce a "Source:ID" UID? If a no go, then we might have to add a get(Pattern) method to query based on a Pattern that the producer know of (e.g. cfr comment on pre-pending the UID with some text set by the producer)

Karel
Re: Introducing Notifications [message #1708417 is a reply to message #1708395] Wed, 16 September 2015 11:53 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Good point about the timestamp, I actually missed that in my list of properties above, but definitely wanted it as well Smile I assume the timestamp is optional and if not filled by the producer, it is automatically set by the manager?

Regarding a "source" property: Yes, this would be somewhat overlapping to the id prefix. What use cases do you see where a producer wants to query its notifications?
Re: Introducing Notifications [message #1708456 is a reply to message #1708417] Wed, 16 September 2015 17:09 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Kai Kreuzer wrote on Wed, 16 September 2015 07:53
Good point about the timestamp, I actually missed that in my list of properties above, but definitely wanted it as well Smile I assume the timestamp is optional and if not filled by the producer, it is automatically set by the manager?


Yes, it is even not possible to set by the producer, but set at instantiation of the Notification (by the NotificationBuilder)

Quote:

Regarding a "source" property: Yes, this would be somewhat overlapping to the id prefix. What use cases do you see where a producer wants to query its notifications?


I have implemented NotificationFilterCriteria to query the stored Notifications. Imagine that a producer needs to update a lingering notification, then it would have to traverse the all the Notifications (getAll()) if no filtering would be possible. In one of the producers classes, I use ' serviceID + ":" + idCounter ' as UID for the Notifications for now, but since these producers are a kind of "set-and-forget" producers, I do not have a need currently to query the store. But you could also imagine that at startup of a producer, the producer wants to query the store for any notifications it generated previously, and if necessary prune those to start with a clean slate.

Karel
Re: Introducing Notifications [message #1708503 is a reply to message #1708456] Thu, 17 September 2015 08:24 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Kai, I can not find back where we discussed the addition of XText to the ESH runtime in the IDE, but I just started a new clean ESH clean environment, did a clean projects and several "perform setup tasks", but I end up with errors in all the org.eclipse.smarthome.model packages. The setup task returns "Error: Could not find or load main class org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher". Seems something is missing after al?
"
Re: Introducing Notifications [message #1708520 is a reply to message #1708503] Thu, 17 September 2015 09:34 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
I am not aware of any problems - please open a separate topic, so that we do not clutter this one with off-topic stuff.
Re: Introducing Notifications [message #1708571 is a reply to message #1708520] Thu, 17 September 2015 14:36 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Quote:
But you could also imagine that at startup of a producer, the producer wants to query the store for any notifications it generated previously, and if necessary prune those to start with a clean slate.


Ok, that's a valid case, since we would not require the producers to store the state themselves. So e.g. at startup an "OFFLINE"-notification producer can check whether devices have come online again and delete the old notifications.
How does your NotificationFilterCriteria look like? Sounds much more complicated than just simply using a source property?
Re: Introducing Notifications [message #1708577 is a reply to message #1708571] Thu, 17 September 2015 15:16 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
As of now the FilterCriteria do not yet support the source property. Have things like type and priority in there, nothing fancy yet.
Re: Introducing Notifications [message #1708641 is a reply to message #1708577] Fri, 18 September 2015 10:07 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
FYI, because the ID of the Notifications are not unique, I ran into the case that at re-start, one of the Producers was producing Notifications with IDs that were previously used by Notifications there not yet delivered (e.g. halted debugger, so they linger in the mapDB), resulting in rather "updates" instead of "adding" them to the database. Pruning them at startup is far more cleaner, so I have added a free text source field
Re: Introducing Notifications [message #1708647 is a reply to message #1707486] Fri, 18 September 2015 11:28 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
If you guys have nothing to do over the weekend (which I doubt, but anyways), I have a running implementation of what we have discussed up to now, plus I have added an implementation of the pushover stuff I had in the first PR as a kind of technology preview of the Notification framework. Just ping me if you want me to prepare a PR
It will certainly need some refactoring to get all packages in the right plug-in but for discussion purposes I have grouped everything together in a minimal amount of plugins

Karel
Re: Introducing Notifications [message #1708653 is a reply to message #1708647] Fri, 18 September 2015 12:04 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
You are quick Smile
Creating a PR cannot harm, but I do not want to promise that I will find over the weekend to look at it in detail.
But anyhow, we can continue the discussion on the PR directly then. Having some real code as a basis for discussion is always good.
Re: Introducing Notifications [message #1708655 is a reply to message #1708653] Fri, 18 September 2015 12:36 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
https://github.com/eclipse/smarthome/pull/459
Re: Introducing Notifications [message #1712463 is a reply to message #1708655] Sun, 25 October 2015 13:00 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Anyone having any thoughts or inputs on the above? Would like to push this to a round "2"
Re: Introducing Notifications [message #1712477 is a reply to message #1712463] Sun, 25 October 2015 19:03 Go to previous message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
I'd suggest to continue the discussion on the PR itself (where this has already half-heartedly started....
Previous Topic:New Modular Rule Concept
Next Topic:Smarthome development
Goto Forum:
  


Current Time: Fri Apr 26 07:26:49 GMT 2024

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

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

Back to the top