Throttling Service Notifications

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 (seeboldface 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 =newDispatcherQueue("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));

}

[8806 byte] By [GeorgeChrysanthakopoulos] at [2008-1-4]

Microsoft Robotics Studio

Site Classified