View Full Version : Pushing with UpdateRoomVariableRequest
11-21-2010, 09:49 AM
Consider a sortof whiteboard application...
I want to have a RoomVariable which has an array with all of the drawing movements set so far. This way, when a new user joins, they grab a copy of this RoomVariable and simply process all of the commands and they can see the same whiteboard as everyone else.
But now when I want to add a new command (say new drawing movement), I need to update the array- but it seems to me that UpdateRoomVariableRequest() is the only way to do it, and this resends the whole array!
How can I just push a new value onto the global array? Thanks!
Is there a more efficient method I'm missing?
11-21-2010, 12:48 PM
A far better design for this type of thing is to have a room plugin for the room. Send each drawing movement to the plugin as a plugin request, and the plugin then sends a plugin message about the drawing movement to the entire room. If the drawing movements are going to be flying fast and furious, send them using queued messaging (which prevents Flash player from crashing due to too many socket messages in too short a period of time).
The plugin maintains a concurrent data structure of the drawing movements. When a new user enters the room, his client sends a plugin request asking for the full set of drawing movements.
Room variables are good for information that rarely changes, but if the info is changing constantly a plugin is a much better choice.
11-23-2010, 09:57 AM
I'm also curious about the queued message system, but it's a little tough to understand the docs on the server api.
Can you point me in the right direction for implementing the queued messaging? Messages will be flying fast and furious, and they can't be missed (i.e. at 40fps, many short drawing movements may occur by multiple users... and they must all be received to show the continuous curve)
11-23-2010, 10:07 AM
Also- for testing purposes, it's far easier/faster for me to develop in actionscript than java.
Is there a huge performance difference for this sort of thing (toggling the message queue and storing an array of drawing movements) ?
11-23-2010, 12:53 PM
The ES4 explanation (http://www.es-wiki.com/index.php?title=Queued_messages) is the same as ES5. When the next version of ES5 is released, there will be an article specifically on queued messaging. If you look at the source code for the RealTimeTankGame, the plugin uses queued messages.
Don't store an array. You need to use a concurrent data structure. The most flexible is a ConcurrentHashMap but there are lots of choices.
The AS1 performance depends on what you are trying to do. Toggling the message queue won't be a performance hit at all, but processing all those plugin requests will add up. You would use the same Java concurrent data structure but would need to include the full package name when you declare it because there's no way to add an import line. For initial development you can just mark the plugin as synchronized and use an ArrayList - this will be quite slow for a production server but shouldn't be a problem for development.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.