PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: Jiri on June 24, 2009, 03:04:24



Title: Object pooling of notifications
Post by: Jiri on June 24, 2009, 03:04:24
I have the following case. There is a TimeProxy, which is sending a notification every 100 ms to a lot of Mediators. The notification that is send only has an int , the current time, as the note its body object.
I was wondering how to optimize this and if it was possible or advisable to create something like an object pool for the notification in this case.

Could some body shed some light on this idea.

much appreciated.

Jiri


Title: Re: Object pooling of notifications
Post by: Helmut Granda on June 25, 2009, 03:06:42
from the docs:

Some good rules of thumb are:
 
o If a number of other Mediators must be involved in
the overall response to an Event, then update a
common Proxy or send a Notification, which is
responded to by interested Mediators, all of whom
respond appropriately. 
 
o If a great amount of coordinated interaction with
other Mediators is required, a good practice is to use
a Command to encode the steps in one place.


Title: Re: Object pooling of notifications
Post by: puremvc on June 28, 2009, 09:18:34
Notifications, like commands are meant to be instantiated, have a brief life and then go away. Pooling is an optimization you could try to make, but I highly doubt it would buy you a lot.

If you're just wanting this optimization for the TimeProxy, then simply override the sendNotification method of the TimeProxy and do something like this:

:
override public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void
{
   var note:INotification = this.getNextPooledNote();
   note.setBody( body );
   facade.notifyObservers( note );
}

You have to pass note name to sendNotification, and we're ignoring it here, presumably it's already set on the pooled note that the TimeProxy is managing.

Or you could skip the override and just make your own method:
:
override public function sendTimeNote( now:Number ):void
{
   var note:INotification = this.getNextPooledNote();
   note.setBody( now );
   facade.notifyObservers( note );
}

-=Cliff>