Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Object pooling of notifications  (Read 3702 times)
Jiri
Jr. Member
**
Posts: 13


View Profile Email
« 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
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #1 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 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>
Logged
Pages: [1]
Print