| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Adobe Flex SDK
Revision: 3095
Author: matamel@adobe.com
Date: 04 Sep 2008 11:50:31
Changes:Feature: Message throttling - message frequency limits subfeature.
QA: Yes
Doc: Not yet
Checkintests: Pass
Details: This is the BlazeDS client part of the message frequency limits sub-feature of Message throttling feature. This check-in adds the ability for the Consumer to specify a maxFrequency globally or per-subscription.
Files:| ... | ...@@ -172,6 +172,12 @@ | |
| 172 | 172 | */ |
| 173 | 173 | public static const CREDENTIALS_CHARSET_HEADER:String = "DSCredentialsCharset"; |
| 174 | 174 | |
| 175 | /** | |
| 176 | * Header to indicate the maximum number of messages a Consumer wants to | |
| 177 | * receive per second. | |
| 178 | */ | |
| 179 | public static const MAX_FREQUENCY_HEADER:String = "DSMaxFrequency"; | |
| 180 | ||
| 175 | 181 | //-------------------------------------------------------------------------- |
| 176 | 182 | // |
| 177 | 183 | // Private Static Constants for Serialization |
| ... | ...@@ -182,6 +182,40 @@ | |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | //---------------------------------- | |
| 186 | // maxFrequency | |
| 187 | //---------------------------------- | |
| 188 | ||
| 189 | /** | |
| 190 | * @private | |
| 191 | */ | |
| 192 | private var _maxFrequency:uint = 0; | |
| 193 | ||
| 194 | [Bindable(event="propertyChange")] | |
| 195 | /** | |
| 196 | * Determines the maximum number of messages per second the Consumer wants | |
| 197 | * to receive. A server that understands this value will use it as an input | |
| 198 | * while it determines how fast to send messages to the Consumer. Default is 0 | |
| 199 | * which means Consumer does not have a preference for the message rate. | |
| 200 | * Note that this property should be set before the Consumer subscribes and | |
| 201 | * any changes after Consumer subscription will not have any effect until | |
| 202 | * Consumer unsubscribes and resubscribes. | |
| 203 | */ | |
| 204 | public function get maxFrequency():uint | |
| 205 | { | |
| 206 | return _maxFrequency; | |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * @private | |
| 211 | */ | |
| 212 | public function set maxFrequency(value:uint):void | |
| 213 | { | |
| 214 | var event:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(this, "maxFrequency", _maxFrequency, value); | |
| 215 | _maxFrequency = value; | |
| 216 | dispatchEvent(event); | |
| 217 | } | |
| 218 | ||
| 185 | 219 | //---------------------------------- |
| 186 | 220 | // resubscribeAttempts |
| 187 | 221 | //---------------------------------- |
| ... | ...@@ -750,6 +784,8 @@ | |
| 750 | 784 | msg.operation = CommandMessage.SUBSCRIBE_OPERATION; |
| 751 | 785 | msg.clientId = clientId; |
| 752 | 786 | msg.destination = destination; |
| 787 | if (maxFrequency > 0) | |
| 788 | msg.headers[CommandMessage.MAX_FREQUENCY_HEADER] = maxFrequency; | |
| 753 | 789 | return msg; |
| 754 | 790 | } |
| 755 | 791 |
| ... | ...@@ -19,27 +19,38 @@ | |
| 19 | 19 | public class SubscriptionInfo |
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | * The subtopic - if null, represents a subscription for messages directed to the | |
| 22 | * The subtopic. If null, represents a subscription for messages directed to the | |
| 23 | 23 | * destination with no subtopic. |
| 24 | 24 | */ |
| 25 | 25 | public var subtopic:String; |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | * The selector. If null, indicates all messages should be sent. | |
| 28 | * The selector. If null, indicates all messages should be sent. | |
| 29 | 29 | */ |
| 30 | 30 | public var selector:String; |
| 31 | 31 | |
| 32 | /** | |
| 33 | * The maximum number of messages per second the subscription wants to receive. | |
| 34 | * Zero means the subscription has no preference for the number of messages | |
| 35 | * it receives. | |
| 36 | */ | |
| 37 | public var maxFrequency:uint; | |
| 38 | ||
| 32 | 39 | /** Builds a new SubscriptionInfo with the specified subtopic and selector. |
| 33 | 40 | * |
| 34 | 41 | * @param st The subtopic for the subscription. If null, represents a subscription |
| 35 | 42 | * for messages directed to the destination with no subtopic. |
| 36 | 43 | * |
| 37 | 44 | * @param sel The selector. If null, inidcates all messages should be sent. |
| 45 | * | |
| 46 | * @param mi The maximum number of messages per second the subscription wants | |
| 47 | * to receive. Zero means no preference. | |
| 38 | 48 | */ |
| 39 | public function SubscriptionInfo(st:String, sel:String) | |
| 49 | public function SubscriptionInfo(st:String, sel:String, mf:uint = 0) | |
| 40 | 50 | { |
| 41 | 51 | subtopic = st; |
| 42 | 52 | selector = sel; |
| 53 | maxFrequency = mf; | |
| 43 | 54 | } |
| 44 | 55 | } |
| 45 | 56 |
| ... | ...@@ -14,15 +14,13 @@ | |
| 14 | 14 | |
| 15 | 15 | import flash.events.TimerEvent; |
| 16 | 16 | import flash.utils.Timer; |
| 17 | import mx.core.mx_internal; | |
| 17 | ||
| 18 | 18 | import mx.collections.ArrayCollection; |
| 19 | import mx.events.PropertyChangeEvent; | |
| 19 | import mx.core.mx_internal; | |
| 20 | 20 | import mx.events.CollectionEvent; |
| 21 | import mx.logging.ILogger; | |
| 22 | import mx.logging.Log; | |
| 23 | import mx.messaging.events.MessageEvent; | |
| 21 | import mx.events.PropertyChangeEvent; | |
| 24 | 22 | import mx.messaging.errors.MessagingError; |
| 25 | import mx.messaging.messages.AsyncMessage; | |
| 23 | import mx.messaging.events.MessageEvent; | |
| 26 | 24 | import mx.messaging.messages.CommandMessage; |
| 27 | 25 | import mx.messaging.messages.IMessage; |
| 28 | 26 | |
| ... | ...@@ -202,10 +200,14 @@ | |
| 202 | 200 | * @param subtopic The subtopic for the new subscription. |
| 203 | 201 | * |
| 204 | 202 | * @param selector The selector for the new subscription. |
| 203 | * | |
| 204 | * @param maxFrequency The maximum number of messages per second the Consumer wants | |
| 205 | * to receive for the subscription. Note that this value overwrites the Consumer | |
| 206 | * wide maxFrequency. | |
| 205 | 207 | */ |
| 206 | public function addSubscription(subtopic:String = null, selector:String = null):void | |
| 208 | public function addSubscription(subtopic:String = null, selector:String = null, maxFrequency:uint = 0):void | |
| 207 | 209 | { |
| 208 | subscriptions.addItem(new SubscriptionInfo(subtopic, selector)); | |
| 210 | subscriptions.addItem(new SubscriptionInfo(subtopic, selector, maxFrequency)); | |
| 209 | 211 | } |
| 210 | 212 | |
| 211 | 213 | /** |
| ... | ...@@ -367,9 +369,14 @@ | |
| 367 | 369 | for (var i:int = 0; i < subscriptions.length; i++) |
| 368 | 370 | { |
| 369 | 371 | var si:SubscriptionInfo = SubscriptionInfo(subscriptions.getItemAt(i)); |
| 370 | subs[(si.subtopic == null ? "" : si.subtopic) + | |
| 371 | CommandMessage.SUBTOPIC_SEPARATOR + | |
| 372 | (si.selector == null ? "" : si.selector)] = true; | |
| 372 | var temp:String = (si.subtopic == null ? "" : si.subtopic) + | |
| 373 | CommandMessage.SUBTOPIC_SEPARATOR + | |
| 374 | (si.selector == null ? "" : si.selector); | |
| 375 | // Add maxFrequency as another token. | |
| 376 | if (si.maxFrequency > 0) | |
| 377 | temp += CommandMessage.SUBTOPIC_SEPARATOR + si.maxFrequency; | |
| 378 | ||
| 379 | subs[temp] = true; | |
| 373 | 380 | } |
| 374 | 381 | return subs; |
| 375 | 382 | } |