-
Notifications
You must be signed in to change notification settings - Fork 9
multiple synchronous requests now possible; additional ObjectID stuff #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericsoco
wants to merge
3
commits into
s9tpepper:master
Choose a base branch
from
ericsoco:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package as3.mongo.wire { | ||
| import as3.mongo.wire.cursor.Cursor; | ||
| import as3.mongo.wire.messages.IMessage; | ||
| import as3.mongo.wire.messages.database.OpReply; | ||
| import as3.mongo.wire.messages.database.OpReplyLoader; | ||
|
|
||
| import com.transmote.utils.time.Timeout; | ||
|
|
||
| import flash.events.ErrorEvent; | ||
| import flash.events.Event; | ||
| import flash.events.EventDispatcher; | ||
| import flash.events.IOErrorEvent; | ||
| import flash.events.SecurityErrorEvent; | ||
| import flash.net.Socket; | ||
|
|
||
| public class RequestSequence extends EventDispatcher { | ||
| private var query:IMessage; | ||
| private var replyLoader:OpReplyLoader; | ||
| private var socket:Socket; | ||
| private var cursor:Cursor; | ||
|
|
||
| public function RequestSequence (query:IMessage, replyLoader:OpReplyLoader, cursor:Cursor=null) { | ||
| this.query = query; | ||
| this.replyLoader = replyLoader; | ||
| this.cursor = cursor; | ||
|
|
||
| init(); | ||
| } | ||
|
|
||
| public function begin (host:String, port:int) :void { | ||
| if (!socket.connected) { | ||
| socket.connect(host, port); | ||
| } else { | ||
| // force asynchronicity | ||
| var beginTimeout:Timeout = new Timeout(beginSequence, 1); | ||
| } | ||
| } | ||
|
|
||
| private function init () :void { | ||
| initSocket(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //-----<REQUEST SEQUENCE>------------------------------------// | ||
| private function beginSequence () :void { | ||
| initReplyLoader(); | ||
| doQuery(); | ||
| } | ||
|
|
||
| private function initReplyLoader () :void { | ||
| replyLoader.initializeOpReplyLoader(socket); | ||
| replyLoader.LOADED.addOnce(onReplyLoaded); | ||
| } | ||
|
|
||
| private function doQuery () :void { | ||
| socket.writeBytes(query.toByteArray()); | ||
| socket.flush(); | ||
| } | ||
|
|
||
| private function onReplyLoaded (reply:OpReply) :void { | ||
| if (cursor) { | ||
| cursor.onReplyLoaded(reply); | ||
| } | ||
|
|
||
| closeSocket(); | ||
| dispatchEvent(new Event(Event.COMPLETE)); | ||
| } | ||
| //-----</REQUEST SEQUENCE>-----------------------------------// | ||
|
|
||
|
|
||
|
|
||
| //-----<SOCKET MANAGEMENT>-----------------------------------// | ||
| private function initSocket () :void { | ||
| socket = new Socket(); | ||
| socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketReady); | ||
| socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSocketReady); | ||
| socket.addEventListener(Event.CONNECT, onSocketReady); | ||
| } | ||
|
|
||
| private function onSocketReady (evt:Event) :void { | ||
| var socket:Socket = evt.target as Socket; | ||
| if (!socket) { return; } | ||
| socket.removeEventListener(IOErrorEvent.IO_ERROR, onSocketReady); | ||
| socket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSocketReady); | ||
| socket.removeEventListener(Event.CONNECT, onSocketReady); | ||
|
|
||
| if (evt is ErrorEvent) { | ||
| dispatchEvent(evt); | ||
| return; | ||
| } | ||
|
|
||
| beginSequence(); | ||
| } | ||
|
|
||
| private function closeSocket () :void { | ||
| try { | ||
| socket.close(); | ||
| } catch (e:Error) {} | ||
|
|
||
| socket = null; | ||
| } | ||
| //-----</SOCKET MANAGEMENT>----------------------------------// | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I had to add this Document class is because the authentication command sent to MongoDB has to have the keys encoded in the correct order. Ideally I wanted to use plain Object type to create command structures to send to MongoDB, but because Object is a dynamic class the properties can not be iterated in a predictable order, so I made this Document object w/ the put() method.
Do you have any suggestions for an alternate solution that would let the driver enumerate over keys in an ordinal manner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes! sorry. didn't mean to leave that comment in, it was in a moment of frustration...i apologize.
i'm not working with authentication, so hadn't run across that issue. in the meantime, please let me remove that comment.
so sorry about that. really appreciate the work you did on this project, it's a huge leap forward from ActionMongo.
-eric
On Apr 5, 2012, at 2:49 PM, Omar Gonzalez wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine, I share a bit of the frustration with creating command structures with this Document object. I have some ideas for alleviating some of that, I think I will add those when I merge your pull request. Its a good discussion to have though, if we can find a different solution around this Document object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll try to give this some more thorough thought soon, probably tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, i'm pretty new to github (this is my first pull request) -- it looks like the commit that removed that comment is automatically added to the pull request. can you confirm?
and, not sure if you want the method i added or not, up to you. i think you understand where my frustration came from tho -- if Document were just an Object getValueByKey would just be doc[key].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing -- after a quick look at the authentication concern you wrote above, i wonder: can't you just manually pull out the specific keys needed for authentication and push those into the ByteArray first? then, remove them from the object you're parsing into the ByteArray, and serialize the remainder of the document object in a non-determinate way (e.g. for-in).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather find a solution that worked across the board. I only found out about the ordinal expectation from MongoDB because the authentication commands were failing. I would assume there are other commands that require to be serialized in the correct key order.