Class: InternetHakai::NonBlockScenarioExecuter

Inherits:
ScenarioExecuter show all
Defined in:
lib/internethakai/hakairev/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ScenarioExecuter

#on_complete, #run, #set_on_complete

Constructor Details

#initializeNonBlockScenarioExecuter

Returns a new instance of NonBlockScenarioExecuter.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/internethakai/hakairev/executor.rb', line 3

def initialize
    super
    @request_pool = BaseHandler::get_handler(@config['request_pool'])
    @concurrency = @config['concurrency']
    @max_request = @config['max_request']
    @request_counter = @max_request
    @acts = []
    @timer = nil
    @queue = BaseHandler::get_handler('TaskQueue')
    @method_dispatch_next = method(:dispatch_next)
    @method_run_one = method(:run_one)
end

Instance Attribute Details

#timerObject

Returns the value of attribute timer.



15
16
17
# File 'lib/internethakai/hakairev/executor.rb', line 15

def timer
  @timer
end

Instance Method Details

#dispatch_nextObject



24
25
26
# File 'lib/internethakai/hakairev/executor.rb', line 24

def dispatch_next
    @queue.add(@method_run_one)
end

#on_action_complete(&block) ⇒ Object

max_request分のactionが終了



17
18
19
20
21
22
23
# File 'lib/internethakai/hakairev/executor.rb', line 17

def on_action_complete &block
    if block
        @on_action_complete_callback = block
    elsif @on_action_complete_callback
        @on_action_complete_callback.call
    end
end

#run_oneObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/internethakai/hakairev/executor.rb', line 27

def run_one
    act = @request_pool.get
    #puts "act: #{act.class} :#{act.object_id}" if act!=-1 && act
    if act.nil?
        dispatch_next
        return
    elsif act == -1
            #-1が返ったらおわり
        #dispatch_next
        return
    end
    #actionのcallbackに次の実行を設定
    act.set_on_complete(&@method_dispatch_next) unless act.has_on_complete?
    act.run
end