Class: InternetHakai::ScenarioExecuter

Inherits:
Object
  • Object
show all
Defined in:
lib/internethakai/executor.rb

Overview

シナリオを実行するクラス

Direct Known Subclasses

NonBlockScenarioExecuter

Instance Method Summary collapse

Constructor Details

#initializeScenarioExecuter

Returns a new instance of ScenarioExecuter.



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/internethakai/executor.rb', line 84

def initialize
    @scenario_handler = BaseHandler::get_handler("ScenarioHandler")
    @enable = true
    @logger = BaseHandler::get_handler('Logger')
    @config = BaseHandler::get_config
    @max_request = @config['max_request']
    @register = BaseHandler::get_handler(@config['response_handler'])
    client_cls =  BaseHandler::get_class(@config['http_client'])
    cl = client_cls::create(@config['host'], @config['port'])
    cl.timeout = @config['timeout']
    cl.set_headers(@config['header'])
    @client = cl
end

Instance Method Details

#on_completeObject



101
102
103
104
105
106
107
# File 'lib/internethakai/executor.rb', line 101

def on_complete
    return if @scenario_handler.closed?
    if @on_complete_callback
        @scenario_handler.close
        @on_complete_callback.call
    end
end

#runObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/internethakai/executor.rb', line 108

def run
    @request_pool = BaseHandler::get_handler(@config['request_pool'])
    pool = @request_pool
    client = @client
    scenario_handler = @scenario_handler
    register = @register
    count = 0
    while true
        break unless @enable
        if scenario_handler.complete?
            on_complete
        end
        act = pool.get
        break if act.nil? or act==-1
        act.set_client(client)
        act.run
        register.exec
    end
    on_complete
end

#set_on_complete(&block) ⇒ Object

すべてのシナリオの終了時に実行されます



98
99
100
# File 'lib/internethakai/executor.rb', line 98

def set_on_complete &block
    @on_complete_callback = block
end