Class: Droonga::Session
- Inherits:
-
Object
- Object
- Droonga::Session
- Defined in:
- lib/droonga/session.rb
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(id, dispatcher, collector, tasks, inputs) ⇒ Session
constructor
A new instance of Session.
- #receive(name, value) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(id, dispatcher, collector, tasks, inputs) ⇒ Session
Returns a new instance of Session.
18 19 20 21 22 23 24 25 |
# File 'lib/droonga/session.rb', line 18 def initialize(id, dispatcher, collector, tasks, inputs) @id = id @dispatcher = dispatcher @collector = collector @tasks = tasks @n_dones = 0 @inputs = inputs end |
Instance Method Details
#done? ⇒ Boolean
27 28 29 |
# File 'lib/droonga/session.rb', line 27 def done? @n_dones == @tasks.size end |
#receive(name, value) ⇒ Object
43 44 45 46 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 |
# File 'lib/droonga/session.rb', line 43 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 component = task["component"] type = component["type"] command = "collector_" + type n_of_expects = component["n_of_expects"] = { "task"=>task, "name"=>name, "value"=>value } @collector.process(command, ) return if task["n_of_inputs"] < n_of_expects #the task is done result = task["values"] post = component["post"] @dispatcher.reply("body" => result) if post component["descendants"].each do |name, routes| = { "id" => @id, "input" => name, "value" => result[name] } routes.each do |route| @dispatcher.dispatch(, route) end end @n_dones += 1 end end |
#start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/droonga/session.rb', line 31 def start tasks = @inputs[nil] tasks.each do |task| = { "id" => @id, "task" => task, } @dispatcher.() @n_dones += 1 end end |