dango 0.3.6 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dango/client_framework.rb +19 -14
- data/lib/dango/framework_base.rb +31 -22
- data/lib/dango/monitor/dango_monitor_client.rb +6 -6
- data/lib/dango/server_framework.rb +31 -30
- data/lib/dango/shared/memory_store.rb +4 -4
- data/lib/dango/tasks/dango_rake.rb +6 -0
- data/lib/dango/tester/dango_tester_client.rb +20 -12
- data/lib/dango/version.rb +1 -1
- metadata +2 -2
@@ -64,7 +64,7 @@ class DangoClientFramework
|
|
64
64
|
rescue
|
65
65
|
message = "failed in dango_client_init. #{error_message($!, 'u')}"
|
66
66
|
logger.error message
|
67
|
-
raise
|
67
|
+
raise DangoFrameworkException, message
|
68
68
|
end
|
69
69
|
|
70
70
|
@log_file = @connection_client_log_file
|
@@ -74,6 +74,10 @@ class DangoClientFramework
|
|
74
74
|
|
75
75
|
# loggerの準備
|
76
76
|
logger.debug("-------client initialize host=#{@connection_client_host} port=#{@connection_client_port}")
|
77
|
+
logger.info("@log_file = #{@log_file}")
|
78
|
+
logger.info("@log_level = #{@log_level}")
|
79
|
+
logger.info("@log_max_size = #{@log_max_size}")
|
80
|
+
logger.info("@log_shift_age = #{@log_shift_age}")
|
77
81
|
|
78
82
|
# データ送受信用の共有メモリ初期化
|
79
83
|
send_return_shared_init()
|
@@ -90,7 +94,7 @@ class DangoClientFramework
|
|
90
94
|
begin
|
91
95
|
@sock = TCPSocket.new(@connection_client_host, @connection_client_port)
|
92
96
|
rescue Errno::EBADF, Exception
|
93
|
-
raise
|
97
|
+
raise DangoFrameworkConnectionException
|
94
98
|
end
|
95
99
|
|
96
100
|
@sock.binmode
|
@@ -125,26 +129,27 @@ class DangoClientFramework
|
|
125
129
|
ret_objs = nil
|
126
130
|
begin
|
127
131
|
ret_objs = dango_receive_data(@sock) # データ受信処理
|
128
|
-
rescue
|
132
|
+
rescue DangoFrameworkConnectionException
|
129
133
|
logger.debug "sock error #{@sid}:#{error_message($!, 'u')}"
|
130
134
|
throw(:session_closed)
|
131
|
-
rescue
|
135
|
+
rescue DangoFrameworkException
|
132
136
|
logger.debug "sock error #{@sid}:#{error_message($!, 'u')}"
|
133
137
|
throw(:session_closed)
|
134
138
|
end
|
135
139
|
logger.debug "finished dango_receive_data:#{ret_objs.inspect} #{@sid}"
|
136
140
|
|
137
141
|
ret_objs.each do |ret_obj| # 受信データひとつごとに処理
|
138
|
-
if !(ret_obj && ret_obj["
|
139
|
-
logger.info "no
|
142
|
+
if !(ret_obj && ret_obj["_notice_name"])
|
143
|
+
logger.info "no notice_name:#{ret_obj.inspect} #{@sid}"
|
140
144
|
end
|
141
145
|
|
142
146
|
# メソッド呼び出し
|
143
|
-
|
147
|
+
notice_name = ret_obj["_notice_name"]
|
148
|
+
logger.info "calling method=#{notice_name.inspect} #{@sid} "
|
144
149
|
begin
|
145
|
-
__send__("dango_receive_#{
|
150
|
+
__send__("dango_receive_#{notice_name}", ret_obj)
|
146
151
|
rescue
|
147
|
-
logger.error "error in dango_receive_#{
|
152
|
+
logger.error "error in dango_receive_#{notice_name} #{@sid} \n#{error_message($!, 'u')}"
|
148
153
|
ensure
|
149
154
|
# データの受信の送信返し
|
150
155
|
response_notice_name = "_response"
|
@@ -152,7 +157,7 @@ class DangoClientFramework
|
|
152
157
|
send_action(response_notice_name, send_obj)
|
153
158
|
logger.debug "response_notice_name=#{response_notice_name.inspect} #{@sid} "
|
154
159
|
end
|
155
|
-
logger.debug "called method=#{
|
160
|
+
logger.debug "called method=#{notice_name.inspect} #{@sid} "
|
156
161
|
end
|
157
162
|
|
158
163
|
else
|
@@ -207,7 +212,7 @@ class DangoClientFramework
|
|
207
212
|
# 必要に応じて追加するメソッド
|
208
213
|
def method_missing(name, *args)
|
209
214
|
logger.info "method not found. #{name.inspect} #{args.inspect}"
|
210
|
-
raise(
|
215
|
+
raise(NoMethodError, "method not found. #{name.inspect} #{args.inspect}")
|
211
216
|
end
|
212
217
|
|
213
218
|
# ユーザーが終了させたい時に呼び出すメソッド(セッションを切る)
|
@@ -254,7 +259,7 @@ class DangoClientFramework
|
|
254
259
|
def send_action(action_name, send_obj)
|
255
260
|
logger.debug "send_action(#{action_name.inspect}, #{send_obj['_id']}) "
|
256
261
|
send_obj_dup = send_obj.dup
|
257
|
-
send_obj_dup["
|
262
|
+
send_obj_dup["_action_name"] = action_name.to_s
|
258
263
|
dango_send_data(@sock, [send_obj_dup])
|
259
264
|
end
|
260
265
|
|
@@ -289,7 +294,7 @@ class DangoClientFramework
|
|
289
294
|
|
290
295
|
# タイムアウトチェック
|
291
296
|
(timeout.to_f / SendReceiveSleepIntervalSec).to_i.times do
|
292
|
-
raise(
|
297
|
+
raise(DangoFrameworkTimeoutException, "timeout:#{action_name}") if Time.now > end_reserved_time
|
293
298
|
|
294
299
|
# 送信スレッドが開始していなければ開始
|
295
300
|
if !receive_thread
|
@@ -308,7 +313,7 @@ class DangoClientFramework
|
|
308
313
|
end
|
309
314
|
|
310
315
|
if !send_return_shared[action_name] # 戻ってきたデータがあるかどうかチェック
|
311
|
-
raise(
|
316
|
+
raise(DangoFrameworkException, "received data is none")
|
312
317
|
end
|
313
318
|
|
314
319
|
send_return_shared[action_name]
|
data/lib/dango/framework_base.rb
CHANGED
@@ -51,13 +51,13 @@ class Time
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# 例外定義
|
54
|
-
class
|
55
|
-
class
|
56
|
-
class
|
57
|
-
class
|
58
|
-
class
|
59
|
-
class
|
60
|
-
class
|
54
|
+
class DangoFrameworkException < StandardError; end
|
55
|
+
class DangoFrameworkTimeoutException < DangoFrameworkException; end
|
56
|
+
class DangoFrameworkConnectionException < DangoFrameworkException; end
|
57
|
+
class DangoFrameworkDisconnectException < DangoFrameworkException; end
|
58
|
+
class DangoFrameworkReadNoDataException < DangoFrameworkException; end
|
59
|
+
class DangoFrameworkFlashPolicyException < DangoFrameworkException; end
|
60
|
+
class DangoFrameworkMonitorSecurityException < DangoFrameworkException; end
|
61
61
|
|
62
62
|
# エラー出力用モジュール
|
63
63
|
module ErrorMessage
|
@@ -101,7 +101,7 @@ module DangoFrameworkModule
|
|
101
101
|
|
102
102
|
CommMaxDigit = 5 # 通信の最大桁数
|
103
103
|
MaxLenRecv = 1024 # 通信の一度の送信バイト数
|
104
|
-
MaxLenSend = 1024
|
104
|
+
MaxLenSend = 1024 * 1024 # 通信の一度の送信バイト数
|
105
105
|
|
106
106
|
EncodeTypeJSON = 0 # エンコードのタイプのJSON
|
107
107
|
EncodeTypeYAML = 1 # エンコードのタイプのYAML
|
@@ -126,7 +126,16 @@ module DangoFrameworkModule
|
|
126
126
|
def logger
|
127
127
|
# if !@dango_logger # これだと警告が出てうざいので
|
128
128
|
if !self.instance_variables.find{|iv| iv == '@dango_logger'} # @dango_loggerが未定義なら
|
129
|
-
|
129
|
+
|
130
|
+
if @log_file == "" # ログを取らない設定の場合は
|
131
|
+
@dango_logger = "LOG NONE"
|
132
|
+
def @dango_logger.fatal(str); end
|
133
|
+
def @dango_logger.error(str); end
|
134
|
+
def @dango_logger.info(str) ; end
|
135
|
+
def @dango_logger.warn(str) ; end
|
136
|
+
def @dango_logger.debug(str); end
|
137
|
+
|
138
|
+
else # ログを取る設定の場合は
|
130
139
|
log_dir = File.dirname(@log_file)
|
131
140
|
Dir.mkdir(log_dir) if !File.exist?(log_dir)
|
132
141
|
@dango_logger = Logger.new(@log_file, @log_shift_age, @log_max_size)
|
@@ -156,15 +165,14 @@ module DangoFrameworkModule
|
|
156
165
|
# size_str = sock.sysread(CommMaxDigit + 1)
|
157
166
|
size_str = sock.recv(CommMaxDigit + 1)
|
158
167
|
rescue EOFError, IOError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNABORTED
|
159
|
-
# 接続終了時の切断と思われるものは
|
160
|
-
|
161
|
-
raise(DangoFrameworkDisconnectError, "failed to read sock for EOF reached (and so on). sock=#{sock.inspect} #{$!.class} toid=#{Thread.current.object_id}")
|
168
|
+
# 接続終了時の切断と思われるものはDangoFrameworkConnectionExceptionにしない
|
169
|
+
raise(DangoFrameworkDisconnectException, "failed to read sock for EOF reached (and so on). sock=#{sock.inspect} #{$!.class} toid=#{Thread.current.object_id}")
|
162
170
|
rescue
|
163
|
-
raise(
|
171
|
+
raise(DangoFrameworkConnectionException, "failed to read sock. sock=#{sock.inspect} toid=#{Thread.current.object_id}\n#{error_message($!, 'u')}")
|
164
172
|
end
|
165
173
|
|
166
174
|
if size_str == ""
|
167
|
-
raise(
|
175
|
+
raise(DangoFrameworkReadNoDataException, "toid=#{Thread.current.object_id}:size_str=#{size_str.inspect}")
|
168
176
|
end
|
169
177
|
|
170
178
|
## Flash のpolicyファイルだった場合(特殊)
|
@@ -172,7 +180,7 @@ module DangoFrameworkModule
|
|
172
180
|
logger.debug "size_str=#{size_str.inspect}"
|
173
181
|
receive_data = sock.recv(18)
|
174
182
|
logger.info "flash policy file: dango_receive_data:receive_data=#{receive_data}"
|
175
|
-
raise(
|
183
|
+
raise(DangoFrameworkFlashPolicyException)
|
176
184
|
end
|
177
185
|
|
178
186
|
## サイズとデータタイプを取得
|
@@ -180,12 +188,12 @@ module DangoFrameworkModule
|
|
180
188
|
|
181
189
|
## データがない場合
|
182
190
|
if size == nil || size == 0
|
183
|
-
raise(
|
191
|
+
raise(DangoFrameworkConnectionException, "toid=#{Thread.current.object_id}:size=#{size}:size_str=#{size_str.inspect}")
|
184
192
|
end
|
185
193
|
|
186
194
|
## データが大きすぎる場合
|
187
195
|
if size >= 1886350441
|
188
|
-
raise(
|
196
|
+
raise(DangoFrameworkConnectionException, "too big... size=#{size}:size_str=#{size_str.inspect}")
|
189
197
|
end
|
190
198
|
|
191
199
|
# logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
@@ -199,7 +207,7 @@ module DangoFrameworkModule
|
|
199
207
|
# this_ret_data_orig = sock.sysread(read_len)
|
200
208
|
this_ret_data_orig = sock.recv(read_len)
|
201
209
|
rescue
|
202
|
-
raise(
|
210
|
+
raise(DangoFrameworkConnectionException, "failed to read sock(data).\n#{error_message($!, 'u')}")
|
203
211
|
end
|
204
212
|
|
205
213
|
ret_data_orig += this_ret_data_orig
|
@@ -227,7 +235,7 @@ module DangoFrameworkModule
|
|
227
235
|
data = Marshal.load(ret_data)
|
228
236
|
end
|
229
237
|
rescue
|
230
|
-
raise(
|
238
|
+
raise(DangoFrameworkConnectionException, "data parse error.#{$!.class}\nret_data=#{ret_data}")
|
231
239
|
end
|
232
240
|
end
|
233
241
|
|
@@ -261,8 +269,9 @@ module DangoFrameworkModule
|
|
261
269
|
size = send_data.size
|
262
270
|
|
263
271
|
# if size >= 4294967296 # 本当はuint最大値なんだけれど、policyファイルの都合で変えてある
|
264
|
-
if size >= 1886350440
|
265
|
-
|
272
|
+
# if size >= 1886350440
|
273
|
+
if size >= MaxLenSend
|
274
|
+
raise(DangoFrameworkException, "max size over. size:#{size} >= #{MaxLenSend}")
|
266
275
|
end
|
267
276
|
|
268
277
|
# size_str = sprintf("%0#{CommMaxDigit}d", size)
|
@@ -281,7 +290,7 @@ module DangoFrameworkModule
|
|
281
290
|
# sock.flush
|
282
291
|
|
283
292
|
rescue
|
284
|
-
raise(
|
293
|
+
raise(DangoFrameworkConnectionException, "sock write failed.\n#{error_message($!, 'u')}")
|
285
294
|
end
|
286
295
|
|
287
296
|
@send_count += 1 if @send_count # 受信回数カウント
|
@@ -39,9 +39,9 @@ class DangoMonitorClient < DangoClientFramework
|
|
39
39
|
logger.debug "get_server_info_common:ret_obj=#{ret_obj.inspect}"
|
40
40
|
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
41
41
|
return(ret_obj[monitor_action_name])
|
42
|
-
rescue
|
42
|
+
rescue DangoFrameworkConnectionException
|
43
43
|
raise("#{monitor_action_name} Connection error")
|
44
|
-
rescue
|
44
|
+
rescue DangoFrameworkTimeoutException
|
45
45
|
raise("#{monitor_action_name} Timeout error")
|
46
46
|
ensure
|
47
47
|
dango_client_close
|
@@ -75,9 +75,9 @@ class DangoMonitorClient < DangoClientFramework
|
|
75
75
|
ret_obj = send_action_return_notice('_monitor_server_reload', {})
|
76
76
|
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
77
77
|
return(true)
|
78
|
-
rescue
|
78
|
+
rescue DangoFrameworkConnectionException
|
79
79
|
raise("monitor_server_reload Connection error")
|
80
|
-
rescue
|
80
|
+
rescue DangoFrameworkTimeoutException
|
81
81
|
raise("monitor_server_reload Timeout error")
|
82
82
|
ensure
|
83
83
|
dango_client_close
|
@@ -91,9 +91,9 @@ class DangoMonitorClient < DangoClientFramework
|
|
91
91
|
ret_obj = send_action_return_notice('_monitor_send_system_message', {:message=>message})
|
92
92
|
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
93
93
|
return(true)
|
94
|
-
rescue
|
94
|
+
rescue DangoFrameworkConnectionException
|
95
95
|
raise("monitor_send_system_message Connection error")
|
96
|
-
rescue
|
96
|
+
rescue DangoFrameworkTimeoutException
|
97
97
|
raise("monitor_send_system_message Timeout error")
|
98
98
|
ensure
|
99
99
|
dango_client_close
|
@@ -128,7 +128,7 @@ class DangoServerFramework
|
|
128
128
|
|
129
129
|
# 終了処理を登録しておく(これが無いとWindowsではエラーが出てもプロセスが落ちないことがある)
|
130
130
|
at_exit do
|
131
|
-
logger.
|
131
|
+
logger.info "at_exit ERROR\n#{caller(0).pretty_inspect}"
|
132
132
|
stop_gserver() # gserverの停止
|
133
133
|
exit_process() # プロセス終了処理
|
134
134
|
end
|
@@ -335,7 +335,7 @@ class DangoServerFramework
|
|
335
335
|
begin
|
336
336
|
ret_objs = dango_receive_data(sock) # データ受信処理
|
337
337
|
is_flash_policy_file = false
|
338
|
-
rescue
|
338
|
+
rescue DangoFrameworkFlashPolicyException
|
339
339
|
is_flash_policy_file = true
|
340
340
|
end
|
341
341
|
|
@@ -366,20 +366,20 @@ EOF
|
|
366
366
|
|
367
367
|
# この部分はポリシーファイルを返す設定に関係なく実行する部分
|
368
368
|
sleep 0.1
|
369
|
-
raise(
|
369
|
+
raise(DangoFrameworkFlashPolicyException, "requested policy file. disconnectiong...")
|
370
370
|
|
371
371
|
elsif ret_objs == [] # 受信データがなければ
|
372
372
|
# logger.debug "ret_objs is empty. "
|
373
373
|
|
374
374
|
else # 受信データがあれば
|
375
375
|
ret_objs.each do |ret_obj| # 受信データループ
|
376
|
-
if !(ret_obj && ret_obj["
|
377
|
-
logger.warn "no
|
378
|
-
raise(
|
376
|
+
if !(ret_obj && ret_obj["_action_name"]) # action_nameが無い場合はエラー
|
377
|
+
logger.warn "no action_name error:#{ret_obj.inspect}"
|
378
|
+
raise(DangoFrameworkException, "no action_name error")
|
379
379
|
end
|
380
380
|
|
381
381
|
# アクション名
|
382
|
-
action_name = ret_obj["
|
382
|
+
action_name = ret_obj["_action_name"].to_s
|
383
383
|
session[:_action_name] = action_name
|
384
384
|
|
385
385
|
# 自動返信用データ
|
@@ -431,25 +431,25 @@ EOF
|
|
431
431
|
|
432
432
|
end # loop
|
433
433
|
|
434
|
-
rescue
|
434
|
+
rescue DangoFrameworkFlashPolicyException
|
435
435
|
logger.info "Flash policy file #{sid} "
|
436
436
|
|
437
|
-
rescue
|
437
|
+
rescue DangoFrameworkMonitorSecurityException
|
438
438
|
logger.warn "Monitor Security Error #{sid} "
|
439
439
|
|
440
|
-
rescue
|
440
|
+
rescue DangoFrameworkReadNoDataException
|
441
441
|
@recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
|
442
442
|
logger.debug "read no data. maybe client closed. #{sid} "
|
443
443
|
|
444
|
-
rescue
|
444
|
+
rescue DangoFrameworkConnectionException
|
445
445
|
@recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
|
446
446
|
logger.debug "connection error. #{sid} \n#{error_message($!, 'u')}"
|
447
447
|
|
448
|
-
rescue
|
449
|
-
logger.debug "
|
448
|
+
rescue DangoFrameworkDisconnectException
|
449
|
+
logger.debug "DangoFrameworkDisconnectException. #{sid} \n#{error_message($!, 'u')}"
|
450
450
|
|
451
|
-
rescue
|
452
|
-
logger.debug "
|
451
|
+
rescue DangoFrameworkException
|
452
|
+
logger.debug "DangoFrameworkException. #{sid} \n#{error_message($!, 'u')}"
|
453
453
|
|
454
454
|
rescue Exception
|
455
455
|
logger.error "Exception #{sid} #{error_message($!, 'u')}"
|
@@ -472,8 +472,9 @@ EOF
|
|
472
472
|
# sock.close if !sock.closed? # ソケットを閉じる
|
473
473
|
sock.close # ソケットを閉じる
|
474
474
|
rescue IOError
|
475
|
-
|
476
|
-
|
475
|
+
logger.info "IOError #{sock.inspect} #{sid}"
|
476
|
+
rescue Exception
|
477
|
+
logger.error "#{sock.inspect} #{sid} Exception\n#{error_message($!, 'u')}"
|
477
478
|
end
|
478
479
|
|
479
480
|
logger.info "#{sock.inspect} #{sid} is closed"
|
@@ -705,6 +706,8 @@ EOF
|
|
705
706
|
# sock.close if !sock.closed?
|
706
707
|
begin
|
707
708
|
sock.close
|
709
|
+
rescue IOError
|
710
|
+
logger.debug "heart_beat_thread_start:maybe already closed. IOError:#{sid}:#{sock}"
|
708
711
|
rescue
|
709
712
|
logger.warn "heart_beat_thread_start:failed close socket:#{error_message($!, 'u')}"
|
710
713
|
end
|
@@ -736,7 +739,7 @@ EOF
|
|
736
739
|
|
737
740
|
# クライアントから来たheart_beatなら
|
738
741
|
def dango_receive__notice_heart_beat(ret_obj)
|
739
|
-
|
742
|
+
logger.debug "dango_receive__notice_heart_beat:#{session[:sid]}:#{ret_obj['_hb_id']} "
|
740
743
|
|
741
744
|
shared.transaction(:_heart_beat_time_hash) do |heart_beat_time_hash|
|
742
745
|
heart_beat_time_hash[session[:sid]] = Time.now
|
@@ -748,8 +751,8 @@ EOF
|
|
748
751
|
def send_return(send_obj, options = {})
|
749
752
|
logger.info "send_return(#{session[:sid].inspect}) "
|
750
753
|
|
751
|
-
raise(
|
752
|
-
raise(
|
754
|
+
raise(DangoFrameworkException, "session[:sid] is not exist.") if ! session[:sid]
|
755
|
+
raise(DangoFrameworkException, "session[:_action_name] is not exist.") if ! session[:_action_name]
|
753
756
|
|
754
757
|
send_notice("return_#{session[:_action_name]}", session[:sid], send_obj, options)
|
755
758
|
end
|
@@ -758,17 +761,17 @@ EOF
|
|
758
761
|
def send_notice(notice_name, sids, send_obj, options = {})
|
759
762
|
logger.info "send_notice(#{notice_name.inspect}, #{sids.inspect}) "
|
760
763
|
|
761
|
-
raise(
|
764
|
+
raise(DangoFrameworkException, "send_obj is not Hash.") if ! send_obj.is_a?(Hash)
|
762
765
|
|
763
766
|
sids = [sids] if sids.is_a?(Integer)
|
764
|
-
raise(
|
767
|
+
raise(DangoFrameworkException, "sids is not Array.") if ! sids.is_a?(Array)
|
765
768
|
|
766
769
|
# timeout = options[:timeout] || @send_receive_timeout_default_sec
|
767
770
|
encode_type = options[:encode_type] || 0
|
768
771
|
|
769
772
|
send_obj_dup = send_obj.deep_dup
|
770
|
-
send_obj_dup["
|
771
|
-
send_obj_dup["
|
773
|
+
send_obj_dup["_notice_name"] = notice_name.to_s
|
774
|
+
send_obj_dup["_server_time"] = Time.now_to_s
|
772
775
|
|
773
776
|
sids.each do |sid|
|
774
777
|
# send_id = Digest::MD5.hexdigest(sid.to_s + notice_name.to_s + Time.now.to_f.to_s + rand().to_s)
|
@@ -779,8 +782,6 @@ EOF
|
|
779
782
|
@queue_send_notice.push([sid, send_obj_dup, encode_type].deep_dup)
|
780
783
|
end # end sids.each
|
781
784
|
|
782
|
-
# raise(DangoFrameworkConnectionError, "send_notice:error happened.") if is_error
|
783
|
-
|
784
785
|
self
|
785
786
|
end
|
786
787
|
|
@@ -826,13 +827,13 @@ EOF
|
|
826
827
|
end
|
827
828
|
|
828
829
|
begin
|
829
|
-
logger.debug "thread_send_notice_queue:dango_send_data:sid=#{sid} sock=#{sock.inspect} #{one_send_data_list.collect{|d| d['
|
830
|
+
logger.debug "thread_send_notice_queue:dango_send_data:sid=#{sid} sock=#{sock.inspect} #{one_send_data_list.collect{|d| d['_notice_name'] + ','}}"
|
830
831
|
# logger.debug "thread_send_notice_queue:one_send_data_list=#{one_send_data_list.inspect}"
|
831
832
|
# logger.debug one_send_data_list.pretty_inspect
|
832
833
|
|
833
834
|
dango_send_data(sock, one_send_data_list, :type=>send_data_encode_type_list[sid]) # データ送信
|
834
835
|
|
835
|
-
rescue
|
836
|
+
rescue DangoFrameworkConnectionException
|
836
837
|
logger.info "thread_send_notice_queue:failed send. sid=#{sid} sock=#{sock.inspect} #{$!.class}"
|
837
838
|
end
|
838
839
|
end
|
@@ -851,8 +852,8 @@ EOF
|
|
851
852
|
key = $1
|
852
853
|
method_action_notice_shared(key, name, *args)
|
853
854
|
else
|
854
|
-
logger.error "method not found. #{name.inspect} #{args.inspect}"
|
855
|
-
raise(
|
855
|
+
# logger.error "method not found. #{name.inspect} #{args.inspect}"
|
856
|
+
raise(NoMethodError, "method not found. #{name.inspect} #{args.inspect}")
|
856
857
|
end
|
857
858
|
end
|
858
859
|
|
@@ -28,7 +28,7 @@ module DangoFrameworkModule
|
|
28
28
|
|
29
29
|
def transaction(key) # トランザクション処理ブロックを作る
|
30
30
|
if !@mutex.has_key?(key) # 未定義キーならエラー
|
31
|
-
raise(
|
31
|
+
raise(DangoFrameworkException, "Shared key is not exist.")
|
32
32
|
end
|
33
33
|
@mutex[key].synchronize do
|
34
34
|
# data = yield(@data[key].deep_dup)
|
@@ -39,7 +39,7 @@ module DangoFrameworkModule
|
|
39
39
|
|
40
40
|
def synchronize(key) # 排他処理ブロック用
|
41
41
|
if !@mutex.has_key?(key) # 未定義キーならエラー
|
42
|
-
raise(
|
42
|
+
raise(DangoFrameworkException, "Shared key is not exist.")
|
43
43
|
end
|
44
44
|
@mutex[key].synchronize do
|
45
45
|
yield
|
@@ -53,7 +53,7 @@ module DangoFrameworkModule
|
|
53
53
|
def [](key)
|
54
54
|
if !@mutex.has_key?(key) # 未定義キーならエラー
|
55
55
|
return(nil)
|
56
|
-
# raise(
|
56
|
+
# raise(DangoFrameworkException, "Shared key is not exist.")
|
57
57
|
end
|
58
58
|
|
59
59
|
# ロックしてデータを読む
|
@@ -70,7 +70,7 @@ module DangoFrameworkModule
|
|
70
70
|
def []=(key, value)
|
71
71
|
# キーはString Symbolのみ
|
72
72
|
if key.class != String && key.class != Symbol
|
73
|
-
raise(
|
73
|
+
raise(DangoFrameworkException, "Shared key is not String or Symbol.")
|
74
74
|
end
|
75
75
|
|
76
76
|
# 未定義なら定義する
|
@@ -97,6 +97,11 @@ def check_dango_connect()
|
|
97
97
|
serv_info = {}
|
98
98
|
serv_info["host"] = config['network']['host'] || 'localhost'
|
99
99
|
serv_info["port"] = config['network']['port'] || 15000
|
100
|
+
serv_info["log_file"] = ""
|
101
|
+
serv_info["log_level"] = Logger::WARN
|
102
|
+
serv_info["log_max_size"] = 10000000
|
103
|
+
serv_info["log_shift_age"] = 10
|
104
|
+
|
100
105
|
# pp serv_info
|
101
106
|
|
102
107
|
tester = DangoTesterClient.new # 開始
|
@@ -166,6 +171,7 @@ namespace :dango do
|
|
166
171
|
stop_process(pid) if pid # pidがあればプロセス停止
|
167
172
|
end
|
168
173
|
|
174
|
+
# サーバーが止まっているので起動処理をかける
|
169
175
|
if check_dango_process_cmd && ((! is_pid_exist) || (! is_alive_server))
|
170
176
|
puts "check_dango_process_cmd=#{check_dango_process_cmd}" if $is_verbose
|
171
177
|
system(check_dango_process_cmd)
|
@@ -16,10 +16,12 @@ class DangoTesterClient
|
|
16
16
|
ReceiveCacheAutoDeleteSec = 30.0 # receive_cacheを自動で消すタイミング
|
17
17
|
|
18
18
|
# テスターのイニシャライズ
|
19
|
-
def initialize(
|
20
|
-
|
19
|
+
def initialize(options = {})
|
20
|
+
options = {:debug => true} if options.class != Hash
|
21
21
|
|
22
|
-
|
22
|
+
@debug = options[:debug]
|
23
|
+
|
24
|
+
original_print("Dango Version=#{Dango::VERSION::STRING}\n") if @debug
|
23
25
|
|
24
26
|
@client_conns = {}
|
25
27
|
Thread.abort_on_exception = true
|
@@ -61,8 +63,14 @@ class DangoTesterClient
|
|
61
63
|
"port"=>serv_info["port"],
|
62
64
|
},
|
63
65
|
"tester" => {
|
64
|
-
"receive_cache_auto_delete_sec"=> serv_info["receive_cache_auto_delete_sec"] || ReceiveCacheAutoDeleteSec,
|
65
|
-
}
|
66
|
+
"receive_cache_auto_delete_sec" => serv_info["receive_cache_auto_delete_sec"] || ReceiveCacheAutoDeleteSec,
|
67
|
+
},
|
68
|
+
"log" => {
|
69
|
+
"log_file" => serv_info["log_file"] || "log/tester_#{Process.pid}_#{c_name}.log",
|
70
|
+
"log_level" => serv_info["log_level"] || Logger::INFO,
|
71
|
+
"log_max_size" => serv_info["log_max_size"] || 10000000,
|
72
|
+
"log_shift_age" => serv_info["log_shift_age"] || 99,
|
73
|
+
},
|
66
74
|
}
|
67
75
|
env = ENV['RAILS_ENV'] || 'development'
|
68
76
|
|
@@ -76,7 +84,7 @@ class DangoTesterClient
|
|
76
84
|
client_conn = nil
|
77
85
|
raise("connection error for retry times over.") if i == ConnectionRetryTimes - 1
|
78
86
|
puts "#{$!.class} #{$!.message} #{$!.backtrace.inspect}" if @debug
|
79
|
-
puts "connection failed. sleep #{ConnectionRetryIntervalSec}"
|
87
|
+
puts "connection failed. sleep #{ConnectionRetryIntervalSec}. #{$!.class}"
|
80
88
|
sleep ConnectionRetryIntervalSec
|
81
89
|
end
|
82
90
|
end
|
@@ -190,10 +198,10 @@ class TestClient < DangoClientFramework
|
|
190
198
|
@connection_client_port = @config["network"]["port"] # 自動でこのポートでサーバー開始
|
191
199
|
|
192
200
|
# ログ出力情報
|
193
|
-
@connection_client_log_file
|
194
|
-
@connection_client_log_level =
|
195
|
-
@connection_client_log_max_size =
|
196
|
-
@connection_client_log_shift_age =
|
201
|
+
@connection_client_log_file = @config["log"]["log_file"]
|
202
|
+
@connection_client_log_level = @config["log"]["log_level"]
|
203
|
+
@connection_client_log_max_size = @config["log"]["log_max_size"]
|
204
|
+
@connection_client_log_shift_age = @config["log"]["log_shift_age"]
|
197
205
|
end
|
198
206
|
|
199
207
|
# テストサーバー
|
@@ -214,7 +222,7 @@ class TestClient < DangoClientFramework
|
|
214
222
|
|
215
223
|
else
|
216
224
|
logger.info "method not found. #{name.inspect} #{args.inspect}"
|
217
|
-
raise(
|
225
|
+
raise(NoMethodError, "method not found. #{name.inspect} #{args.inspect}")
|
218
226
|
end
|
219
227
|
end
|
220
228
|
|
@@ -254,7 +262,7 @@ class TestClient < DangoClientFramework
|
|
254
262
|
|
255
263
|
# タイムアウトなら
|
256
264
|
if receive_data == nil
|
257
|
-
raise(
|
265
|
+
raise(DangoFrameworkTimeoutException, "timeout:timeout_sec=#{timeout}: \n client_name=#{@client_name}(#{self.sid}) \n :notice_name=#{notice_name} \n")
|
258
266
|
end
|
259
267
|
|
260
268
|
# 結果を削除しておく
|
data/lib/dango/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dango
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keisuke Minami
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-05 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|