locked
Throttling Service Notifications RRS feed

  • General discussion

  • I posted an update on the DSS Wiki page that describes how you can use CCR task execution policy, for managing periodic notifications. You can basically have the CCR do the work of keeping your service with only one queued task, only for the most recent notification.

     

    Check it out here, towards the bottom

     

    http://channel9.msdn.com/wiki/default.aspx/Channel9.DssPatterns

     

    Here is the code snippet as well

     

    Let assume you have the usual code snippet where you subscribe to a sensor, and supply a notification port to receive the update messages. I cut and pasted a simple example from robotics Tutorial 2 (as is):

     

    Code Snippet

            void SubscribeToBumpers()

            {

                // Create bumper notification port

                bumper.ContactSensorArrayOperations bumperNotificationPort = new

                    bumper.ContactSensorArrayOperations();

     

                // Subscribe to the bumper service, send notifications to

                // bumperNotificationPort

                _bumperPort.Subscribe(bumperNotificationPort);

     

                // Start listening for Bumper Replace notifications

                Activate(

                    Arbiter.Receive<BUMPER.Update>

                        (true, bumperNotificationPort, BumperHandler));

            }

     

    I would modify it as follows (see boldface text below):

     

    Code Snippet

            void SubscribeToBumpers()

            {

                // Create bumper notification port

                bumper.ContactSensorArrayOperations bumperNotificationPort = new

                    bumper.ContactSensorArrayOperations();

     

                // Subscribe to the bumper service, send notifications to

                // bumperNotificationPort

                _bumperPort.Subscribe(bumperNotificationPort);

     

                DispatcherQueue notifyTaskQueue = new DispatcherQueue("bumperNotifyQueue",

                    TaskQueue.Dispatcher, // use same dispatcher as service

                    TaskExecutionPolicy.ConstrainQueueDepthDiscardTasks,

                    1 // maximum depth set to 1, will discard anything but latest

                );

     

                // Start listening for Bumper Replace notifications

                Arbiter.Activate(

                    notifyTaskQueue,

                    Arbiter.Receive<BUMPER.Update>

                        (true, bumperNotificationPort, BumperHandler));

            }

     

     

    Friday, June 1, 2007 7:55 PM