Class: Droonga::Session
- Inherits:
-
Object
- Object
- Droonga::Session
- Includes:
- Loggable
- Defined in:
- lib/droonga/session.rb
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(id, dispatcher, collector_runner, tasks, inputs) ⇒ Session
constructor
A new instance of Session.
- #receive(name, value) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(id, dispatcher, collector_runner, tasks, inputs) ⇒ Session
Returns a new instance of Session.
22 23 24 25 26 27 28 29 |
# File 'lib/droonga/session.rb', line 22 def initialize(id, dispatcher, collector_runner, tasks, inputs) @id = id @dispatcher = dispatcher @collector_runner = collector_runner @tasks = tasks @n_dones = 0 @inputs = inputs end |
Instance Method Details
#done? ⇒ Boolean
31 32 33 |
# File 'lib/droonga/session.rb', line 31 def done? @n_dones == @tasks.size end |
#receive(name, value) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/droonga/session.rb', line 47 def receive(name, value) tasks = @inputs[name] unless tasks #TODO: result arrived before its query return end tasks.each do |task| task["n_of_inputs"] += 1 step = task["step"] command = step["type"] n_of_expects = step["n_of_expects"] = { "task"=>task, "name"=>name, "value"=>value } @collector_runner.collect() return if task["n_of_inputs"] < n_of_expects #the task is done result = task["values"] post = step["post"] if post # XXX: It is just a workaround. # Remove me when super step is introduced. if result["errors"] reply_body = result elsif command == "search_gather" reply_body = result else reply_body = result["result"] end @dispatcher.reply("body" => reply_body) end send_to_descendantas(step["descendants"], result) @n_dones += 1 end end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/droonga/session.rb', line 35 def start tasks = @inputs[nil] || [] tasks.each do |task| = { "id" => @id, "task" => task, } @dispatcher.() @n_dones += 1 end end |