Class: TestClient
- Inherits:
-
DangoClientFramework
- Object
- DangoClientFramework
- TestClient
- Defined in:
- lib/dango/tester/dango_tester_client.rb
Overview
テスト接続用のクラス
Constant Summary collapse
- SendReceiveSleepIntervalSec =
データ送信後の順の際のタイムアウトチェック間隔秒
0.1
- ReceiveWaitTimeoutSec =
データ受信確認の待ち秒数
10
- ReceiveTrapTimeoutSec =
データ受信確認のトラップの秒数
0
Constants inherited from DangoClientFramework
DangoClientFramework::HeartBeatSendIntervalSec
Constants included from DangoFrameworkModule
DangoFrameworkModule::CommMaxDigit, DangoFrameworkModule::DefaultEncodeType, DangoFrameworkModule::EncodeTypeJSON, DangoFrameworkModule::EncodeTypeMarshal, DangoFrameworkModule::EncodeTypeYAML, DangoFrameworkModule::MaxLenRecv, DangoFrameworkModule::MaxLenSend, DangoFrameworkModule::ReadTimeoutSec
Instance Attribute Summary collapse
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#send_receive_shared ⇒ Object
readonly
Returns the value of attribute send_receive_shared.
Attributes inherited from DangoClientFramework
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
データ保管用の場所を作っておく.
-
#clear_receive(notice_name = nil, options = {}) ⇒ Object
clear_receive notice_nameを省略するとchacheにあるものすべて削除.
-
#dango_client_init ⇒ Object
起動処理.
-
#get_receive_cache ⇒ Object
send_receive_sharedの中身を返すメソッド.
-
#initialize(env, config, c_name) ⇒ TestClient
constructor
A new instance of TestClient.
-
#method_missing(name, *args) ⇒ Object
データ受信時の処理をするためにmethod_missingを定義.
-
#send(name, send_obj = {}) ⇒ Object
テストサーバー.
-
#send_receive_shared_init ⇒ Object
dango_client_send_receive_data用の共有メモリ.
-
#wait_receive(notice_name, options = {}) ⇒ Object
wait_receive.
Methods inherited from DangoClientFramework
#dango_client_close, #dango_client_notice_shared, #dango_client_notice_shared_init, #dango_client_receive_decrypt, #dango_client_send_encrypt, #dango_heart_beat_thread_init, #dango_receive__heart_beat, #dango_receive__notice_sid, #dango_receive__notice_system_message, #dango_session_closed, #receive_decrypt, #send_action, #send_action_return_notice, #send_encrypt, #send_return_shared, #send_return_shared_init
Methods included from DangoFrameworkModule
#dango_receive_data, #dango_send_data, #debug_print, #error_print
Methods included from DangoLoggerModule
Methods included from ErrorMessage
Constructor Details
#initialize(env, config, c_name) ⇒ TestClient
Returns a new instance of TestClient.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/dango/tester/dango_tester_client.rb', line 158 def initialize(env, config, c_name) @config = config @client_name = c_name # クライアント名 @client_data = {} # データ保管用 @receive_cache_auto_delete_sec = config['tester']['receive_cache_auto_delete_sec'] super(env, config) send_receive_shared_init() send_receive_shared[:receive_cache] = [] # 受信データ用のキャッシュ初期化 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
データ受信時の処理をするためにmethod_missingを定義
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/dango/tester/dango_tester_client.rb', line 209 def method_missing(name, *args) if name.to_s =~ /^dango_receive_/ && args.length == 1 ret_obj = args[0] logger.debug "ret_obj:#{name}:" + ret_obj.inspect + " " + Time.now_to_s send_receive_shared.transaction(:receive_cache) do |receive_cache| receive_cache.push([name, ret_obj, Time.now]) receive_cache send_receive_shared.commit(receive_cache) end else logger.info "method not found. #{name.inspect} #{args.inspect}" raise(NoMethodError, "method not found. #{name.inspect} #{args.inspect}") end end |
Instance Attribute Details
#client_name ⇒ Object
Returns the value of attribute client_name.
173 174 175 |
# File 'lib/dango/tester/dango_tester_client.rb', line 173 def client_name @client_name end |
#send_receive_shared ⇒ Object (readonly)
Returns the value of attribute send_receive_shared.
187 188 189 |
# File 'lib/dango/tester/dango_tester_client.rb', line 187 def send_receive_shared @send_receive_shared end |
Instance Method Details
#[](key) ⇒ Object
179 180 181 |
# File 'lib/dango/tester/dango_tester_client.rb', line 179 def [](key) @client_data[key] end |
#[]=(key, value) ⇒ Object
データ保管用の場所を作っておく
176 177 178 |
# File 'lib/dango/tester/dango_tester_client.rb', line 176 def []=(key, value) @client_data[key] = value end |
#clear_receive(notice_name = nil, options = {}) ⇒ Object
clear_receive notice_nameを省略するとchacheにあるものすべて削除
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/dango/tester/dango_tester_client.rb', line 286 def clear_receive(notice_name = nil, = {}) logger.debug "wait_receive_data:#{notice_name}:" # 結果を削除しておく send_receive_shared.transaction(:receive_cache) do |receive_cache| receive_cache.delete_if do |one_rec_data| true if (! notice_name) || (notice_name && one_rec_data[0] == notice_name) end receive_cache send_receive_shared.commit(receive_cache) end end |
#dango_client_init ⇒ Object
起動処理
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dango/tester/dango_tester_client.rb', line 190 def dango_client_init # サーバー接続情報など @connection_client_host = @config["network"]["host"] # 自動でこのホスト名でサーバー開始 @connection_client_port = @config["network"]["port"] # 自動でこのポートでサーバー開始 # ログ出力情報 @connection_client_log_file = @config["log"]["log_file"] @connection_client_log_level = @config["log"]["log_level"] @connection_client_log_max_size = @config["log"]["log_max_size"] @connection_client_log_shift_age = @config["log"]["log_shift_age"] end |
#get_receive_cache ⇒ Object
send_receive_sharedの中身を返すメソッド
226 227 228 |
# File 'lib/dango/tester/dango_tester_client.rb', line 226 def get_receive_cache send_receive_shared[:receive_cache] end |
#send(name, send_obj = {}) ⇒ Object
テストサーバー
203 204 205 206 |
# File 'lib/dango/tester/dango_tester_client.rb', line 203 def send(name, send_obj = {}) logger.info("tester.send:name=#{name}:send_obj=#{send_obj.inspect} ") send_action(name, send_obj) end |
#send_receive_shared_init ⇒ Object
dango_client_send_receive_data用の共有メモリ
184 185 186 |
# File 'lib/dango/tester/dango_tester_client.rb', line 184 def send_receive_shared_init @send_receive_shared = SharedMemoryStore.new({}) end |
#wait_receive(notice_name, options = {}) ⇒ Object
wait_receive
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/dango/tester/dango_tester_client.rb', line 232 def wait_receive(notice_name, = {}) logger.debug "wait_receive_data:#{notice_name}:" timeout = [:timeout] || ReceiveWaitTimeoutSec # データ受信待ち receive_data = nil receive_idx = nil end_reserved_time = Time.now + timeout # 0以上ならタイムアウト時間決定 loop do logger.debug "wait_receive_data:loop:#{send_receive_shared[:receive_cache].inspect}" send_receive_shared[:receive_cache].each_with_index do |rec_data, i| if rec_data[0].to_s == "dango_receive_" + notice_name.to_s receive_data = rec_data.deep_dup receive_idx = i break end end break if receive_data != nil break if end_reserved_time < Time.now sleep SendReceiveSleepIntervalSec # スリープ end # タイムアウトなら if receive_data == nil raise(DangoFrameworkTimeoutException, "timeout:timeout_sec=#{timeout}: \n client_name=#{@client_name}(#{self.sid}) \n :notice_name=#{notice_name} \n") end # 結果を削除しておく send_receive_shared.transaction(:receive_cache) do |receive_cache| receive_cache.delete_at(receive_idx) receive_cache send_receive_shared.commit(receive_cache) end # 古いreceive_cacheを削除しておく send_receive_shared.transaction(:receive_cache) do |receive_cache| receive_cache = receive_cache.select do |one_receive_cache| # true one_receive_cache[2] > Time.now - @receive_cache_auto_delete_sec end receive_cache send_receive_shared.commit(receive_cache) end receive_data[1] end |