Check in code for an object's notification subscriptions on

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by cnwrjp1 >> Tue, 13 Jan 2009 22:58:26 GMT

Hi all,

I am trying to put together a generic notification framework for handling the registering and firing of notifications in my system.
As part of this I am keeping an array of objects that have been registered for a variety of notification events for a particular receiver. I need to be able to do endNotifications on all these objects at a certain point in this process, so is there a way of finding out a list all the notification events registered on an object for a given receiver?

Thanks
Roland

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Allistar >> Tue, 13 Jan 2009 23:14:45 GMT

I don't think there is any direct way of doing that, you'll probably need to create your own structure for storing that information and create/delete the objects that represent the registered notifications when you being/end them.
--
A.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Alan >> Wed, 14 Jan 2009 8:49:05 GMT

You could try having a look at system.getNotes method

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Murray Symon >> Wed, 14 Jan 2009 8:13:21 GMT

What about Object::endNotificationForSubscriber(subscriber: Object)?

This terminates all notifications on the specified subscriber.

e.g.
foreach obj in objArray do
endNotificationForSubscriber(obj);
endforeach;

HTH,
Murray.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by cnwrjp1 >> Wed, 14 Jan 2009 21:42:55 GMT

Hi Murray,

I don't think example you show here would work for me as I have an object array with receiver objects, and endnotificationForSubscriber works on the other end of the notification.
The other issue with endNotificationForSubscriber is that I was hoping to only stop the notes on the subscriber for those receiver objects I have been told to manage notifications for, and in some cases, only for specific events. The given subscriber may have other notifications on other receivers which I am not responsible for and I don't want to go terminating notes for those too.

So here is the scenario I was working to.

A form is loaded and a 'notificationHandler' object is created with the form instance set as the subscriber for all notes to be received via it's userNotiy and/or sysNotify methods.
In the process of the form being used, various objects are passed to the notificationHandler with an associated 'notify' event to be either started or stopped.
It was my plan to just store the supplied receiver objects in an array so I could check the given object was already in my array and if it was, I could query the notifications it was subscribed to and either start or stop them depending on the method call. Once the last notification on an object was stopped, I would remove it from the array. When the form unloads or the notificationHandler instance is deleted, I do an 'endNotificationForSubscriber' which should terminate all my notes anyway. From looking at system.getNotes as suggested by Alan I see I can find all the entries where target and subscriber match up to the Objects I am dealing with, but this would seem a rather inefficient way of doing things, especially on a system with a large number of notes. I was hoping there was a way of saying "I will give you a subscriber and receiver and you give me a list of all the notification events registered" :-)
Wishful thinking perhaps?

Roland

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Murray Symon >> Thu, 15 Jan 2009 7:03:19 GMT

Have you considered maintaining your own ExternalKeyDictionary or MemberKeyDictionary with appropriate key values, instead of the
current ObjectArray? Then you can access objects in the manner you describe, rather than just search the array each time.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Torrie Moore >> Thu, 15 Jan 2009 23:05:22 GMT

Hi

If you want to record which notifications are started, you could consider reimplementing the beginNotification call on the form class and then add to the external dictionary as was suggested.

Regards

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by cnwrjp1 >> Sun, 18 Jan 2009 20:03:26 GMT

Yes, I suspect maintaining my own dictionary may be the most efficient option.
Hmm, I will need to handle one shot notes that have been registered with me, but already fired. Perhaps an exception handler for these situations would suffice.

Thanks everyone for your input here. Much appreciated.

Roland

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Check in code for an object's notification subscriptions on

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Allistar >> Sun, 18 Jan 2009 20:44:26 GMT

I would have a singleton controller object that manages your collection of notification objects, and have all received notifications handled by that controller object. So your notification object can look something like this:

NotificationObject:
myController: Controller; (child - manual)
myReceiverObject: Object;
notificationType: Integer; (1=Class, 2=object, 3=timer)
eventTag: String;
.....any other properties you may need
myCallbackMethod: JadeMethod;

when the controller receives a notification, make the "eventTag" be the NotificationObject, and then it can call the "myCallbackMethod" method on the "myReceiverObject" with the appropriate parameters. This was all notifications are handled by your framework and you can easily deal with things like one shot timers. You'd need to handle for the situation when the receiver object no longer exists.
--
A.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 12 guests