dango 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dango/client_framework.rb +56 -56
- data/lib/dango/framework_base.rb +31 -31
- data/lib/dango/monitor/dango_monitor_client.rb +19 -13
- data/lib/dango/monitor/server_monitor_action.rb +20 -20
- data/lib/dango/server_framework.rb +87 -85
- data/lib/dango/tasks/dango_rake.rb +2 -2
- data/lib/dango/tester/dango_tester_client.rb +42 -36
- data/lib/dango/version.rb +1 -1
- metadata +2 -2
@@ -12,20 +12,20 @@ class DangoClientFramework
|
|
12
12
|
|
13
13
|
SendReceiveSleepIntervalSec = 0.1 # データ送信後の順の際のタイムアウトチェック間隔秒
|
14
14
|
|
15
|
-
#
|
16
|
-
def
|
17
|
-
@
|
15
|
+
# send_action_return_notice用の共有メモリ
|
16
|
+
def send_return_shared_init
|
17
|
+
@send_return_shared = SharedMemoryStore.new
|
18
18
|
end
|
19
|
-
def
|
20
|
-
@
|
19
|
+
def send_return_shared
|
20
|
+
@send_return_shared
|
21
21
|
end
|
22
22
|
|
23
23
|
# 起動処理
|
24
|
-
def
|
24
|
+
def dango_client_init
|
25
25
|
end
|
26
26
|
|
27
27
|
# セッションが切れると呼ばれる処理
|
28
|
-
def
|
28
|
+
def dango_session_closed
|
29
29
|
end
|
30
30
|
|
31
31
|
# メイン処理
|
@@ -54,20 +54,20 @@ class DangoClientFramework
|
|
54
54
|
exit!
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
dango_client_init() # 初期設定読み込み
|
58
58
|
|
59
59
|
@log_file = @connection_client_log_file
|
60
60
|
@log_level = @connection_client_log_level
|
61
61
|
|
62
62
|
# loggerの準備
|
63
|
-
|
63
|
+
logger.debug("-------client initialize")
|
64
64
|
|
65
65
|
# データ送受信用の共有メモリ初期化
|
66
|
-
|
66
|
+
send_return_shared_init()
|
67
67
|
@send_receive_mutex = Mutex.new # 送受信用の排他処理
|
68
68
|
|
69
69
|
# 通知共有メモリの初期化
|
70
|
-
|
70
|
+
dango_client_notice_shared_init()
|
71
71
|
|
72
72
|
# ソケットの準備
|
73
73
|
@sock = nil
|
@@ -83,7 +83,7 @@ class DangoClientFramework
|
|
83
83
|
@sock.binmode
|
84
84
|
@sock.sync = true
|
85
85
|
@tmutex = Mutex.new # sockの排他処理用
|
86
|
-
|
86
|
+
logger.debug("addr:#{@sock.addr.inspect}")
|
87
87
|
|
88
88
|
@sid = nil # 接続して決まるsidを保持
|
89
89
|
|
@@ -99,44 +99,44 @@ class DangoClientFramework
|
|
99
99
|
loop do
|
100
100
|
begin
|
101
101
|
if @sock
|
102
|
-
|
102
|
+
logger.debug "start dango_receive_data #{@sid}"
|
103
103
|
ret_obj = nil
|
104
104
|
begin
|
105
|
-
ret_obj =
|
105
|
+
ret_obj = dango_receive_data(@sock) # データ受信処理
|
106
106
|
rescue DangoFrameworkConnectionError
|
107
|
-
|
107
|
+
logger.debug "sock error #{@sid}:#{error_message($!, 'u')}"
|
108
108
|
throw(:session_closed)
|
109
109
|
rescue DangoFrameworkError
|
110
|
-
|
110
|
+
logger.debug "sock error #{@sid}:#{error_message($!, 'u')}"
|
111
111
|
throw(:session_closed)
|
112
112
|
end
|
113
|
-
|
113
|
+
logger.debug "finished dango_receive_data:#{ret_obj.inspect} #{@sid}"
|
114
114
|
|
115
115
|
if !(ret_obj && ret_obj["notice"])
|
116
|
-
|
116
|
+
logger.info "no notice:#{ret_obj["notice"].inspect} #{@sid}"
|
117
117
|
end
|
118
118
|
|
119
119
|
# メソッド呼び出し
|
120
|
-
|
120
|
+
logger.info "calling method=#{ret_obj["notice"].inspect} #{@sid} #{Time.now_to_s}"
|
121
121
|
begin
|
122
|
-
__send__("
|
122
|
+
__send__("dango_receive_#{ret_obj["notice"]}", ret_obj)
|
123
123
|
rescue
|
124
|
-
|
124
|
+
logger.error "error in dango_receive_#{ret_obj["notice"]} #{@sid} #{Time.now_to_s}\n#{error_message($!, 'u')}"
|
125
125
|
ensure
|
126
126
|
# データの受信の送信返し
|
127
127
|
response_notice_name = "_response"
|
128
128
|
send_obj = {"_id" => ret_obj["_id"]}
|
129
|
-
|
130
|
-
|
129
|
+
send_action(response_notice_name, send_obj)
|
130
|
+
logger.debug "response_notice_name=#{response_notice_name.inspect} #{@sid} #{Time.now_to_s}"
|
131
131
|
end
|
132
|
-
|
132
|
+
logger.debug "called method=#{ret_obj["notice"].inspect} #{@sid} #{Time.now_to_s}"
|
133
133
|
|
134
134
|
else
|
135
135
|
sleep 0.01
|
136
136
|
end
|
137
137
|
|
138
138
|
rescue Exception
|
139
|
-
|
139
|
+
logger.debug "#{@sid}:#{error_message($!, 'u')}"
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
@@ -146,16 +146,16 @@ class DangoClientFramework
|
|
146
146
|
private :thread_main
|
147
147
|
|
148
148
|
# 接続直後のsid通知なら
|
149
|
-
def
|
149
|
+
def dango_receive__notice_sid(rec_obj)
|
150
150
|
@sid = rec_obj["_sid"]
|
151
151
|
end
|
152
152
|
|
153
153
|
# システムからのメッセージ通知なら
|
154
|
-
def
|
154
|
+
def dango_receive__notice_system_message(rec_obj)
|
155
155
|
end
|
156
156
|
|
157
157
|
# ユーザーが終了させたい時に呼び出すメソッド(セッションを切る)
|
158
|
-
def
|
158
|
+
def dango_client_close
|
159
159
|
client_quit() # クライアントの終了処理
|
160
160
|
end
|
161
161
|
|
@@ -165,13 +165,13 @@ class DangoClientFramework
|
|
165
165
|
begin
|
166
166
|
@sock.close if @sock
|
167
167
|
rescue
|
168
|
-
|
168
|
+
logger.debug "sock close failed. #{$!}"
|
169
169
|
end
|
170
170
|
@sock = nil
|
171
171
|
|
172
172
|
@is_session_closed = true
|
173
|
-
|
174
|
-
|
173
|
+
logger.info "calling dango_session_closed()"
|
174
|
+
dango_session_closed() # セッションが切れると呼ばれる処理
|
175
175
|
|
176
176
|
@is_close = true
|
177
177
|
end
|
@@ -179,54 +179,54 @@ class DangoClientFramework
|
|
179
179
|
private :client_quit
|
180
180
|
|
181
181
|
# クライアントの暗号化処理
|
182
|
-
def
|
182
|
+
def dango_client_send_encrypt(str) # 継承用
|
183
183
|
str
|
184
184
|
end
|
185
|
-
def
|
186
|
-
|
185
|
+
def dango_send_encrypt(str) # フレームワークから呼ばれる部分
|
186
|
+
dango_client_send_encrypt(str)
|
187
187
|
end
|
188
188
|
|
189
189
|
# クライアントの復号化処理
|
190
|
-
def
|
190
|
+
def dango_client_receive_decrypt(str) # 継承用
|
191
191
|
str
|
192
192
|
end
|
193
|
-
def
|
194
|
-
|
193
|
+
def dango_receive_decrypt(str) # フレームワークから呼ばれる部分
|
194
|
+
dango_client_receive_decrypt(str)
|
195
195
|
end
|
196
196
|
|
197
197
|
# クライアントからサーバーへのデータ送信
|
198
|
-
def
|
199
|
-
|
198
|
+
def send_action(action_name, send_obj)
|
199
|
+
logger.debug "send_action(#{action_name.inspect}, #{send_obj['_id']}) #{Time.now_to_s}"
|
200
200
|
send_obj_dup = send_obj.dup
|
201
201
|
send_obj_dup["action"] = action_name.to_s
|
202
|
-
|
202
|
+
dango_send_data(@sock, send_obj_dup)
|
203
203
|
end
|
204
204
|
|
205
205
|
# サーバーからクライアントへのデータ送信
|
206
|
-
# 自動でreturn_nameに対応した
|
206
|
+
# 自動でreturn_nameに対応したdango_receive_メソッドが出来上がるので注意
|
207
207
|
# options = {:return_name=> :timeout => }
|
208
208
|
# return_nameは省略時は、action_nameの頭にreturnを付けたもののシンボルになる
|
209
209
|
# timeoutは省略時は6秒
|
210
|
-
def
|
211
|
-
#
|
212
|
-
#
|
210
|
+
def send_action_return_notice(action_name, send_obj, options = {})
|
211
|
+
# logger.debug "send_action_return_notice(#{action_name.inspect})"
|
212
|
+
# logger.debug "send_action_return_notice(#{action_name.inspect}, #{send_obj.inspect}, #{options.inspect})"
|
213
213
|
|
214
214
|
return_name = options[:return_name] || ("return_" + action_name.to_s).to_sym
|
215
215
|
timeout = options[:timeout] || 6
|
216
216
|
|
217
217
|
@send_receive_mutex.synchronize do
|
218
|
-
|
218
|
+
send_return_shared[action_name] = nil
|
219
219
|
|
220
220
|
receive_thread = nil
|
221
221
|
end_reserved_time = Time.now + timeout
|
222
222
|
|
223
223
|
# 戻ってきたデータのチェック
|
224
224
|
action_name_sym = (action_name.class == Symbol) ? (":"+action_name.to_s) : ('"'+action_name+'"')
|
225
|
-
instance_method_name = "
|
225
|
+
instance_method_name = "dango_receive_#{return_name}"
|
226
226
|
expr = <<-EOF
|
227
227
|
def self.#{instance_method_name}(ret_obj)
|
228
|
-
#
|
229
|
-
|
228
|
+
# logger.debug "ret_obj:" + ret_obj.inspect
|
229
|
+
send_return_shared[#{action_name_sym}] = ret_obj
|
230
230
|
end
|
231
231
|
EOF
|
232
232
|
instance_eval expr
|
@@ -238,26 +238,26 @@ class DangoClientFramework
|
|
238
238
|
# 送信スレッドが開始していなければ開始
|
239
239
|
if !receive_thread
|
240
240
|
receive_thread = Thread.start(action_name, send_obj) do
|
241
|
-
|
241
|
+
send_action(action_name, send_obj)
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
245
|
# 戻ってきたデータがあれば
|
246
|
-
if
|
247
|
-
|
246
|
+
if send_return_shared[action_name]
|
247
|
+
logger.debug "action_name:#{send_return_shared[action_name].inspect}"
|
248
248
|
break
|
249
249
|
end
|
250
250
|
|
251
251
|
sleep SendReceiveSleepIntervalSec # スリープ
|
252
252
|
end
|
253
253
|
|
254
|
-
if !
|
254
|
+
if !send_return_shared[action_name] # 戻ってきたデータがあるかどうかチェック
|
255
255
|
raise(DangoFrameworkError, "received data is none")
|
256
256
|
end
|
257
257
|
|
258
258
|
#remove_method(instance_method_name) # 定義したインスタンスメソッドを削除しておく
|
259
259
|
|
260
|
-
|
260
|
+
send_return_shared[action_name]
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
@@ -270,15 +270,15 @@ class DangoClientFramework
|
|
270
270
|
def []=(key, value) # キーに対する書き込み(読み込みはないぞ)
|
271
271
|
action_name = "action_notice_shared_#{key}"
|
272
272
|
send_obj = {:data => value}
|
273
|
-
@parent.
|
273
|
+
@parent.send_action(action_name, send_obj)
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
-
def
|
277
|
+
def dango_client_notice_shared_init # 通知共有メモリの初期化
|
278
278
|
@client_notice_shared = ClientNoticeShared.new(self)
|
279
279
|
end
|
280
280
|
|
281
|
-
def
|
281
|
+
def dango_client_notice_shared # 通知共有メモリ
|
282
282
|
@client_notice_shared
|
283
283
|
end
|
284
284
|
|
data/lib/dango/framework_base.rb
CHANGED
@@ -106,33 +106,33 @@ module DangoFrameworkModule
|
|
106
106
|
# 2 = Marshal
|
107
107
|
|
108
108
|
# デバッグ出力用のメソッド
|
109
|
-
def
|
110
|
-
|
109
|
+
def debug_print(str)
|
110
|
+
logger.debug str
|
111
111
|
puts str if $VERBOSE
|
112
112
|
end
|
113
113
|
|
114
114
|
# ロガーの定義
|
115
|
-
def
|
116
|
-
# if !@
|
117
|
-
if !self.instance_variables.find{|iv| iv == '@
|
115
|
+
def logger
|
116
|
+
# if !@logger # これだと警告が出てうざいので
|
117
|
+
if !self.instance_variables.find{|iv| iv == '@logger'} # @loggerが未定義なら
|
118
118
|
if @log_file != ""
|
119
119
|
log_dir = File.dirname(@log_file)
|
120
120
|
Dir.mkdir(log_dir) if !File.exist?(log_dir)
|
121
|
-
@
|
122
|
-
@
|
123
|
-
@
|
124
|
-
# @
|
125
|
-
@
|
121
|
+
@logger = Logger.new(@log_file)
|
122
|
+
@logger.level = @log_level
|
123
|
+
@logger.datetime_format = "%Y-%m-%dT%H:%M:%S"
|
124
|
+
# @logger.datetime_format = "aaaaa"
|
125
|
+
@logger.progname = "toid=#{Thread.current.object_id}"
|
126
126
|
end
|
127
127
|
end
|
128
|
-
@
|
128
|
+
@logger
|
129
129
|
end
|
130
130
|
|
131
131
|
# データ受信処理
|
132
|
-
def
|
132
|
+
def dango_receive_data(sock)
|
133
133
|
ret_data = ""
|
134
134
|
|
135
|
-
#
|
135
|
+
# logger.debug "dango_receive_data(#{sock})"
|
136
136
|
|
137
137
|
begin
|
138
138
|
# size_str = sock.readpartial(CommMaxDigit + 1)
|
@@ -152,9 +152,9 @@ module DangoFrameworkModule
|
|
152
152
|
|
153
153
|
## Flash のpolicyファイルだった場合(特殊)
|
154
154
|
if size_str == "<polic"
|
155
|
-
|
155
|
+
logger.debug "size_str=#{size_str.inspect}"
|
156
156
|
receive_data = sock.recv(18)
|
157
|
-
|
157
|
+
logger.debug "dango_receive_data:receive_data=#{receive_data}"
|
158
158
|
raise(DangoFrameworkFlashPolicyError)
|
159
159
|
end
|
160
160
|
|
@@ -171,7 +171,7 @@ module DangoFrameworkModule
|
|
171
171
|
raise(DangoFrameworkConnectionError, "too big... size=#{size}:size_str=#{size_str.inspect}")
|
172
172
|
end
|
173
173
|
|
174
|
-
#
|
174
|
+
# logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
175
175
|
|
176
176
|
ret_data_orig = ""
|
177
177
|
|
@@ -186,16 +186,16 @@ module DangoFrameworkModule
|
|
186
186
|
end
|
187
187
|
|
188
188
|
ret_data_orig += this_ret_data_orig
|
189
|
-
#
|
189
|
+
# logger.debug "size:#{size.inspect}:this_ret_data_orig:#{this_ret_data_orig.inspect}"
|
190
190
|
|
191
191
|
size -= this_ret_data_orig.size
|
192
|
-
#
|
192
|
+
# logger.debug "size:#{size.inspect}"
|
193
193
|
end
|
194
194
|
|
195
|
-
#
|
195
|
+
# logger.debug "ret_data_orig:#{ret_data_orig.inspect}"
|
196
196
|
|
197
|
-
ret_data =
|
198
|
-
#
|
197
|
+
ret_data = dango_receive_decrypt(ret_data_orig[0..-2])
|
198
|
+
# logger.debug "ret_data:#{ret_data.inspect}"
|
199
199
|
|
200
200
|
@recv_count += 1 if @recv_count # 受信回数カウント
|
201
201
|
|
@@ -215,8 +215,8 @@ module DangoFrameworkModule
|
|
215
215
|
end
|
216
216
|
|
217
217
|
# データ送信処理
|
218
|
-
def
|
219
|
-
#
|
218
|
+
def dango_send_data(sock, send_obj, options = {})
|
219
|
+
# logger.debug "dango_send_data:send_obj=#{send_obj.inspect}"
|
220
220
|
|
221
221
|
dtype = options[:type] || DefaultDataType
|
222
222
|
|
@@ -230,11 +230,11 @@ module DangoFrameworkModule
|
|
230
230
|
send_data_orig = Marshal.dump(send_obj)
|
231
231
|
end
|
232
232
|
|
233
|
-
send_data =
|
234
|
-
# send_data =
|
235
|
-
# send_data =
|
233
|
+
send_data = dango_send_encrypt(send_data_orig) + "\n"
|
234
|
+
# send_data = dango_send_encrypt(send_data_orig) + "\r\n"
|
235
|
+
# send_data = dango_send_encrypt(send_data_orig) + "\015\012"
|
236
236
|
|
237
|
-
#
|
237
|
+
# logger.debug "start dango_send_data:#{send_data.inspect}"
|
238
238
|
|
239
239
|
size = send_data.size
|
240
240
|
|
@@ -246,10 +246,10 @@ module DangoFrameworkModule
|
|
246
246
|
# size_str = sprintf("%0#{CommMaxDigit}d", size)
|
247
247
|
|
248
248
|
size_str = [dtype, size].pack("cN")
|
249
|
-
#
|
249
|
+
# logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
250
250
|
|
251
251
|
send_buf = size_str + "\n" + send_data
|
252
|
-
#
|
252
|
+
# logger.debug "send_buf:#{send_buf.inspect}"
|
253
253
|
|
254
254
|
begin
|
255
255
|
sock.write send_buf
|
@@ -263,8 +263,8 @@ module DangoFrameworkModule
|
|
263
263
|
end
|
264
264
|
|
265
265
|
@send_count += 1 if @send_count # 受信回数カウント
|
266
|
-
#
|
267
|
-
#
|
266
|
+
# logger.debug "finish dango_send_data:#{send_data.inspect}"
|
267
|
+
# logger.debug "finish dango_send_data:#{Time.now_to_s}:toid=#{Thread.current.object_id} #{sock} #{sock.closed?}"
|
268
268
|
|
269
269
|
sock
|
270
270
|
end
|
@@ -25,7 +25,7 @@ class DangoMonitorClient < DangoClientFramework
|
|
25
25
|
public
|
26
26
|
|
27
27
|
# 起動処理
|
28
|
-
def
|
28
|
+
def dango_client_init
|
29
29
|
# ログ出力情報
|
30
30
|
@connection_client_log_file = "#{RAILS_ROOT}/log/dango_monitor_#{@env}.log"
|
31
31
|
@connection_client_log_level = Logger::DEBUG
|
@@ -37,44 +37,50 @@ class DangoMonitorClient < DangoClientFramework
|
|
37
37
|
|
38
38
|
# サーバーの全情報取得
|
39
39
|
def get_all_info
|
40
|
-
|
40
|
+
logger.debug "DangoMonitorClient:get_all_info:#{ENV['RAILS_ROOT']}"
|
41
41
|
begin
|
42
|
-
ret_obj =
|
42
|
+
ret_obj = send_action_return_notice('_monitor_all_info', {})
|
43
|
+
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
44
|
+
return(ret_obj['all_info'])
|
43
45
|
rescue DangoFrameworkConnectionError
|
44
46
|
raise("monitor_all_info Connection error")
|
45
47
|
rescue DangoFrameworkTimeoutError
|
46
48
|
raise("monitor_all_info Timeout error")
|
49
|
+
ensure
|
50
|
+
dango_client_close
|
47
51
|
end
|
48
|
-
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
49
|
-
ret_obj['all_info']
|
50
52
|
end
|
51
53
|
|
52
54
|
# サーバーのデータリロード
|
53
55
|
def server_reload
|
54
|
-
|
56
|
+
logger.debug "DangoMonitorClient:server_reload"
|
55
57
|
begin
|
56
|
-
ret_obj =
|
58
|
+
ret_obj = send_action_return_notice('_monitor_server_reload', {})
|
59
|
+
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
60
|
+
return(true)
|
57
61
|
rescue DangoFrameworkConnectionError
|
58
62
|
raise("monitor_server_reload Connection error")
|
59
63
|
rescue DangoFrameworkTimeoutError
|
60
64
|
raise("monitor_server_reload Timeout error")
|
65
|
+
ensure
|
66
|
+
dango_client_close
|
61
67
|
end
|
62
|
-
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
63
|
-
true
|
64
68
|
end
|
65
69
|
|
66
70
|
# システムメッセージの送信
|
67
71
|
def send_system_message(message = "")
|
68
|
-
|
72
|
+
logger.debug "DangoMonitorClient:send_system_message"
|
69
73
|
begin
|
70
|
-
ret_obj =
|
74
|
+
ret_obj = send_action_return_notice('_monitor_send_system_message', {:message=>message})
|
75
|
+
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
76
|
+
return(true)
|
71
77
|
rescue DangoFrameworkConnectionError
|
72
78
|
raise("monitor_send_system_message Connection error")
|
73
79
|
rescue DangoFrameworkTimeoutError
|
74
80
|
raise("monitor_send_system_message Timeout error")
|
81
|
+
ensure
|
82
|
+
dango_client_close
|
75
83
|
end
|
76
|
-
raise("code is not 0 (faild). :code=#{ret_obj['code']}") if ret_obj['code'] != 0
|
77
|
-
true
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
@@ -12,7 +12,7 @@ class ServerMonitorAction
|
|
12
12
|
@parent = parent
|
13
13
|
@config = config
|
14
14
|
|
15
|
-
@
|
15
|
+
@logger = @parent.logger
|
16
16
|
@shared = @parent.shared
|
17
17
|
@session = @parent.session
|
18
18
|
@socket_list = @parent.socket_list
|
@@ -21,30 +21,30 @@ class ServerMonitorAction
|
|
21
21
|
# アクション名
|
22
22
|
action_name = ret_obj["action"].to_s
|
23
23
|
|
24
|
-
|
24
|
+
dango_check_monitor_error(sock, action_name)
|
25
25
|
|
26
26
|
if action_name == '_monitor_all_info' # メンテナンスアクション名なら
|
27
|
-
|
27
|
+
dango_server_monitor_all_info(ret_obj)
|
28
28
|
|
29
29
|
elsif action_name == '_monitor_server_reload' # メンテナンスアクション名なら
|
30
|
-
|
30
|
+
dango_server_monitor_server_reload(ret_obj)
|
31
31
|
|
32
32
|
elsif action_name == '_monitor_send_system_message' # メンテナンスアクション名なら
|
33
|
-
|
33
|
+
dango_server_monitor_send_system_message(ret_obj)
|
34
34
|
|
35
35
|
else
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
attr_reader(:
|
39
|
+
attr_reader(:logger, :shared, :session, :socket_list, :session_list)
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
43
|
# メンテナンスコマンド:エラーの場合
|
44
|
-
def
|
44
|
+
def dango_check_monitor_error(sock, action_name)
|
45
45
|
peerhost, peeraddr = sock.peeraddr[2, 2]
|
46
46
|
backdoor_host = @config['server']['backdoor_host']
|
47
|
-
|
47
|
+
logger.debug "dango_check_monitor_error:peerhost=#{peerhost.inspect} peeraddr=#{peeraddr.inspect} backdoor_host=#{backdoor_host.inspect}"
|
48
48
|
|
49
49
|
match = false
|
50
50
|
if peerhost == backdoor_host # ホスト名で書いてある時の一致確認
|
@@ -62,14 +62,14 @@ class ServerMonitorAction
|
|
62
62
|
if !match
|
63
63
|
notice_name = "return_" + action_name
|
64
64
|
send_obj = {'code'=>1, 'message'=>"error your ip address"}
|
65
|
-
@parent.
|
65
|
+
@parent.send_notice(session[:sid], notice_name, send_obj, :type=>2)
|
66
66
|
raise(DangoFrameworkMonitorSecurityError)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
# メンテナンスコマンド:サーバーからクライアントへのデータ送信
|
71
|
-
def
|
72
|
-
|
71
|
+
def dango_server_monitor_all_info(ret_obj)
|
72
|
+
logger.debug "dango_server_monitor_all_info:#{ret_obj.inspect}"
|
73
73
|
all_info = {
|
74
74
|
'shareds' => shared.to_hash,
|
75
75
|
'socket_list' => socket_list.keys,
|
@@ -86,31 +86,31 @@ class ServerMonitorAction
|
|
86
86
|
}
|
87
87
|
|
88
88
|
send_obj = {'code'=>0, 'all_info'=>all_info}
|
89
|
-
@parent.
|
89
|
+
@parent.send_notice(session[:sid], 'return__monitor_all_info', send_obj, :type=>2)
|
90
90
|
end
|
91
91
|
|
92
92
|
# メンテナンスコマンド:サーバーデータ再読み込み
|
93
|
-
def
|
94
|
-
|
93
|
+
def dango_server_monitor_server_reload(ret_obj)
|
94
|
+
logger.debug "dango_server_monitor_server_reload"
|
95
95
|
@server_reload = true
|
96
|
-
|
96
|
+
logger.debug "@server_reload=#{@server_reload.inspect}"
|
97
97
|
send_obj = {'code'=>0, 'message'=>'success'}
|
98
|
-
@parent.
|
98
|
+
@parent.send_notice(session[:sid], 'return__monitor_server_reload', send_obj, :type=>2)
|
99
99
|
end
|
100
100
|
|
101
101
|
# メンテナンスコマンド:接続者全員へメッセージ送信
|
102
|
-
def
|
103
|
-
|
102
|
+
def dango_server_monitor_send_system_message(ret_obj)
|
103
|
+
logger.debug "dango_server_monitor_send_system_message:#{ret_obj.inspect}"
|
104
104
|
|
105
105
|
# 全員へ_notice_system_messageを通知
|
106
106
|
socket_list.keys.each do |sid|
|
107
107
|
next if session[:sid] == sid
|
108
108
|
send_obj = { "message" => ret_obj["message"] }
|
109
|
-
@parent.
|
109
|
+
@parent.send_notice(sid, '_notice_system_message', send_obj)
|
110
110
|
end
|
111
111
|
|
112
112
|
send_obj = {'code'=>0, }
|
113
|
-
@parent.
|
113
|
+
@parent.send_notice(session[:sid], 'return__monitor_send_system_message', send_obj, :type=>2)
|
114
114
|
end
|
115
115
|
|
116
116
|
end
|
@@ -81,12 +81,12 @@ class DangoServerFramework
|
|
81
81
|
def server_start()
|
82
82
|
set_server_variables() # 各種サーバー仕様の変数設定
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
logger.debug("===== server initialize =====") # loggerの準備
|
85
|
+
logger.debug("#{Time.now_to_s}")
|
86
|
+
logger.debug("Process.pid=#{Process.pid}")
|
87
|
+
logger.debug("port=#{@connection_server_port}")
|
88
|
+
logger.debug("host=#{@connection_server_host}")
|
89
|
+
logger.debug("max_connections=#{@connection_server_max_connections}")
|
90
90
|
|
91
91
|
open("tmp/pids/dango.pid", "wb"){|fh| fh.write Process.pid.to_s }
|
92
92
|
|
@@ -96,7 +96,7 @@ class DangoServerFramework
|
|
96
96
|
socket_list_init() # ソケット一覧を初期化
|
97
97
|
mutex_socket_list_init() # ソケット毎用のmutexを初期化
|
98
98
|
@mutex_proc_thread = Mutex.new # スレッドが同時起動しないようにするためのMutex
|
99
|
-
|
99
|
+
dango_server_init() # 初期設定読み込み
|
100
100
|
heart_beat_thread_start() # ハートビートスレッドの開始
|
101
101
|
|
102
102
|
@mutex_send_response = Mutex.new # 送信レスポンス用のMutex
|
@@ -111,7 +111,7 @@ class DangoServerFramework
|
|
111
111
|
@gserver.start
|
112
112
|
rescue Exception
|
113
113
|
error_msg = "#{$!.class} #{$!.message} #{$!.backtrace.pretty_inspect}"
|
114
|
-
|
114
|
+
logger.error error_msg
|
115
115
|
puts error_msg
|
116
116
|
end
|
117
117
|
end
|
@@ -125,9 +125,9 @@ class DangoServerFramework
|
|
125
125
|
puts "-- stopping server"
|
126
126
|
|
127
127
|
# 強制的に接続しているsocketをクローズ
|
128
|
-
|
128
|
+
logger.debug "socket_list.keys:#{socket_list.keys.inspect}"
|
129
129
|
socket_list.keys.each do |sk|
|
130
|
-
|
130
|
+
logger.debug "sk:#{socket_list[sk].inspect}"
|
131
131
|
socket_list[sk].close if ! socket_list[sk].closed?
|
132
132
|
socket_list[sk]
|
133
133
|
end
|
@@ -138,7 +138,7 @@ class DangoServerFramework
|
|
138
138
|
while(!@gserver.stopped?) do
|
139
139
|
sleep 1
|
140
140
|
puts "waiting... #{@gserver.stopped?}"
|
141
|
-
|
141
|
+
logger.debug "waiting... #{@gserver.stopped?} #{@gserver.connections}"
|
142
142
|
end
|
143
143
|
|
144
144
|
@gserver = nil
|
@@ -177,26 +177,26 @@ class DangoServerFramework
|
|
177
177
|
server_start() # サーバー開始
|
178
178
|
end
|
179
179
|
rescue Exception
|
180
|
-
|
180
|
+
logger.error "#{$!.class}:#{$!.message}\n#{$!.backtrace.pretty_inspect}"
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
184
|
# gserver接続開始処理
|
185
185
|
def connecting(sock)
|
186
|
-
|
187
|
-
#
|
186
|
+
logger.debug "connecting:sock=#{sock} peeraddr=#{sock.peeraddr.inspect} addr=#{sock.addr.inspect}"
|
187
|
+
# logger.debug "getpeername=#{Socket.unpack_sockaddr_in(sock.getpeername).inspect} getsockname=#{Socket.unpack_sockaddr_in(sock.getsockname).inspect}"
|
188
188
|
end
|
189
189
|
|
190
190
|
# gserver接続開始処理
|
191
191
|
def disconnecting(port)
|
192
|
-
|
192
|
+
logger.debug "disconnecting:port=#{port} #{Time.now_to_s}"
|
193
193
|
end
|
194
194
|
|
195
195
|
# gserverのserveメソッド:スレッド開始処理
|
196
196
|
def thread_main(sock)
|
197
|
-
|
198
|
-
#
|
199
|
-
|
197
|
+
logger.debug "thread_main:start"
|
198
|
+
# logger.debug "#{sock} is accepted. thread.current=#{Thread.current.object_id} sock_id=#{sock.object_id}"
|
199
|
+
logger.debug "#{sock} is accepted. thread.current=#{Thread.current.object_id}"
|
200
200
|
|
201
201
|
begin
|
202
202
|
sock.binmode
|
@@ -208,12 +208,12 @@ class DangoServerFramework
|
|
208
208
|
socket_list.add(sid, sock)
|
209
209
|
mutex_socket_list.add(sid)
|
210
210
|
|
211
|
-
|
211
|
+
dango_connect() # 接続時メソッド呼び出し
|
212
212
|
|
213
213
|
# 接続直後のsid通知
|
214
214
|
send_obj = {"_sid"=>sid}
|
215
|
-
|
216
|
-
|
215
|
+
send_notice(sid, "_notice_sid", send_obj)
|
216
|
+
logger.debug "_notice_sid #{sid} #{Time.now_to_s}"
|
217
217
|
|
218
218
|
# 誰かが接続したときに60秒以上経った@arr_send_responseを削除
|
219
219
|
@mutex_send_response.synchronize do
|
@@ -223,33 +223,33 @@ class DangoServerFramework
|
|
223
223
|
# メインループ入り
|
224
224
|
loop do
|
225
225
|
if sock.closed?
|
226
|
-
|
226
|
+
logger.debug "#{sock.inspect}:sock is closed..."
|
227
227
|
break
|
228
228
|
end
|
229
229
|
|
230
230
|
ret_obj = nil
|
231
231
|
begin
|
232
|
-
ret_obj =
|
232
|
+
ret_obj = dango_receive_data(sock) # データ受信処理
|
233
233
|
is_flash_policy_file = false
|
234
234
|
rescue DangoFrameworkFlashPolicyError
|
235
235
|
is_flash_policy_file = true
|
236
236
|
end
|
237
237
|
|
238
238
|
if is_flash_policy_file && @policy_file_request # Flashのポリシーファイルが来たら
|
239
|
-
|
239
|
+
logger.debug "is_flash_policy_file #{sid} #{Time.now_to_s}"
|
240
240
|
policy_data = '<?xml version="1.0"?><cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>' + "\0" + "\n"
|
241
|
-
|
241
|
+
logger.debug policy_data
|
242
242
|
sock.write policy_data
|
243
243
|
sock.flush
|
244
244
|
sleep 1
|
245
245
|
raise(DangoFrameworkFlashPolicyError, "policy file sent. disconnectiong...")
|
246
246
|
|
247
247
|
elsif ret_obj == {} # 受信データがなければ
|
248
|
-
#
|
248
|
+
# logger.debug "ret_obj is empty. #{Time.now_to_s}"
|
249
249
|
|
250
250
|
else # 受信データがあれば
|
251
251
|
if !(ret_obj && ret_obj["action"]) # actionが無い場合はエラー
|
252
|
-
|
252
|
+
logger.error "no action error:#{ret_obj.inspect}"
|
253
253
|
raise(DangoFrameworkError, "no action error")
|
254
254
|
end
|
255
255
|
|
@@ -259,19 +259,19 @@ class DangoServerFramework
|
|
259
259
|
@mutex_proc_thread.synchronize do
|
260
260
|
|
261
261
|
if action_name == '_response' # 送信パケットの返事なら
|
262
|
-
#
|
262
|
+
# logger.debug "action_name=#{action_name} #{Time.now_to_s}"
|
263
263
|
action_name_is_response(ret_obj)
|
264
264
|
|
265
265
|
elsif action_name[0, 9] == '_monitor_' # メンテナンスアクション名なら
|
266
266
|
ServerMonitorAction.new(self, @config, sock, ret_obj)
|
267
267
|
|
268
268
|
else # メンテナンスコマンド以外のユーザーアクション名なら
|
269
|
-
|
269
|
+
logger.debug "action_name=#{action_name} #{sid} #{Time.now_to_s}"
|
270
270
|
begin
|
271
|
-
__send__("
|
271
|
+
__send__("dango_receive_#{action_name}", ret_obj)
|
272
272
|
rescue NoMethodError
|
273
273
|
@recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
|
274
|
-
|
274
|
+
logger.error "not find action #{action_name}:#{sid}:#{error_message($!, 'u')}"
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
@@ -281,41 +281,41 @@ class DangoServerFramework
|
|
281
281
|
end # loop
|
282
282
|
|
283
283
|
rescue DangoFrameworkFlashPolicyError
|
284
|
-
|
284
|
+
logger.debug "Flash policy file send. #{sid} #{Time.now_to_s}"
|
285
285
|
|
286
286
|
rescue DangoFrameworkMonitorSecurityError
|
287
|
-
|
287
|
+
logger.debug "Monitor Security Error #{sid} #{Time.now_to_s}"
|
288
288
|
|
289
289
|
rescue DangoFrameworkReadNoDataError
|
290
|
-
|
290
|
+
logger.debug "read no data. maybe client closed. #{sid} #{Time.now_to_s}"
|
291
291
|
|
292
292
|
rescue DangoFrameworkConnectionError
|
293
293
|
@recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
|
294
|
-
|
294
|
+
logger.debug "connection error. #{sid} #{Time.now_to_s}\n#{error_message($!, 'u')}"
|
295
295
|
|
296
296
|
rescue DangoFrameworkError
|
297
|
-
|
297
|
+
logger.debug "DangoFrameworkError. #{sid} #{Time.now_to_s}\n#{error_message($!, 'u')}"
|
298
298
|
|
299
299
|
rescue Exception
|
300
|
-
|
300
|
+
logger.error "Exception #{sid} #{Time.now_to_s} #{error_message($!, 'u')}"
|
301
301
|
|
302
302
|
ensure
|
303
|
-
|
303
|
+
logger.debug "#{sock.inspect} #{sid} is gone"
|
304
304
|
|
305
305
|
@mutex_proc_thread.synchronize do
|
306
306
|
begin
|
307
|
-
|
307
|
+
dango_close() # 接続解除時に呼び出されるメソッド
|
308
308
|
rescue Exception
|
309
|
-
|
309
|
+
logger.error "#{sock.inspect} #{sid} ERROR\n#{error_message($!, 'u')}"
|
310
310
|
ensure
|
311
311
|
socket_list.delete(sid) # ソケットリストから削除
|
312
312
|
begin
|
313
313
|
sock.close if !sock.closed? # ソケットを閉じる
|
314
314
|
rescue IOError
|
315
|
-
|
315
|
+
logger.debug "IOError #{sock} #{sid}"
|
316
316
|
end
|
317
317
|
|
318
|
-
|
318
|
+
logger.debug "#{sock.inspect} #{sid} is gone 2"
|
319
319
|
end
|
320
320
|
|
321
321
|
end
|
@@ -326,7 +326,7 @@ class DangoServerFramework
|
|
326
326
|
|
327
327
|
# action_nameが送信パケットの返事なら
|
328
328
|
def action_name_is_response(ret_obj)
|
329
|
-
#
|
329
|
+
# logger.warn "action_name_is_response:#{ret_obj['_id']} #{session[:sid]} #{Time.now_to_s}"
|
330
330
|
@mutex_send_response.synchronize do
|
331
331
|
@arr_send_response.push({:_id => ret_obj["_id"], :time => Time.now})
|
332
332
|
end
|
@@ -372,7 +372,7 @@ class DangoServerFramework
|
|
372
372
|
|
373
373
|
attr_reader(:start_time, :recv_count, :send_count, :recv_fail_count, :send_fail_count)
|
374
374
|
|
375
|
-
def
|
375
|
+
def dango_server_init # 初期設定
|
376
376
|
end
|
377
377
|
|
378
378
|
# コンフィグのshared_database_managerによる使用クラスの選択
|
@@ -449,10 +449,10 @@ class DangoServerFramework
|
|
449
449
|
|
450
450
|
self[key] = value
|
451
451
|
|
452
|
-
@parent.
|
452
|
+
@parent.logger.debug "self.get_connectables(key):#{self.get_connectables(key).inspect}"
|
453
453
|
|
454
454
|
self.get_connectables(key).each do |sid|
|
455
|
-
@parent.
|
455
|
+
@parent.send_notice(sid, "notice_shared_#{key}".to_sym, value)
|
456
456
|
end
|
457
457
|
end
|
458
458
|
|
@@ -508,26 +508,28 @@ class DangoServerFramework
|
|
508
508
|
attr_accessor(:mutex_socket_list)
|
509
509
|
|
510
510
|
# 接続時に呼び出されるメソッド
|
511
|
-
def
|
511
|
+
def dango_connect
|
512
|
+
end
|
512
513
|
|
513
514
|
# 接続解除時に呼び出されるメソッド
|
514
|
-
def
|
515
|
+
def dango_close
|
516
|
+
end
|
515
517
|
|
516
518
|
|
517
519
|
# サーバーの暗号化処理
|
518
|
-
def
|
520
|
+
def dango_server_send_encrypt(str) # 継承用
|
519
521
|
str
|
520
522
|
end
|
521
|
-
def
|
522
|
-
|
523
|
+
def dango_send_encrypt(str) # フレームワークから呼ばれる部分
|
524
|
+
dango_server_send_encrypt(str)
|
523
525
|
end
|
524
526
|
|
525
527
|
# サーバーの復号化処理
|
526
|
-
def
|
528
|
+
def dango_server_receive_decrypt(str) # 継承用
|
527
529
|
str
|
528
530
|
end
|
529
|
-
def
|
530
|
-
|
531
|
+
def dango_receive_decrypt(str) # フレームワークから呼ばれる部分
|
532
|
+
dango_server_receive_decrypt(str)
|
531
533
|
end
|
532
534
|
|
533
535
|
# ハートビートスレッドの開始
|
@@ -538,29 +540,29 @@ class DangoServerFramework
|
|
538
540
|
sleep @herat_beat_interval_sec
|
539
541
|
|
540
542
|
if ! @gserver.stopped? # gserverが起動していれば
|
541
|
-
|
543
|
+
logger.debug "heart_beat_thread_start #{Time.now_to_s}"
|
542
544
|
|
543
545
|
# 全員へheart_beatパケットを送信
|
544
546
|
socket_list.keys.each do |sid|
|
545
547
|
# sock = socket_list[sid]
|
546
|
-
#
|
547
|
-
#
|
548
|
-
|
549
|
-
|
548
|
+
# logger.debug "heart_beat_thread_start:sid=#{sid} #{sock} #{sock.closed?}"
|
549
|
+
# dango_send_data(sock, {})
|
550
|
+
logger.debug "heart_beat_thread_start:sid=#{sid}"
|
551
|
+
send_notice(sid, "_heart_beat", {}, {:timeout=>@heart_beat_response_wait_sec})
|
550
552
|
end
|
551
553
|
end
|
552
554
|
|
553
555
|
rescue
|
554
|
-
|
556
|
+
logger.error "Exception heart_beat_thread_start #{Time.now_to_s} #{error_message($!, 'u')}"
|
555
557
|
end
|
556
558
|
end
|
557
559
|
end
|
558
560
|
end
|
559
561
|
|
560
562
|
# サーバーからクライアントへのデータ送信
|
561
|
-
def
|
562
|
-
|
563
|
-
#
|
563
|
+
def send_notice(sid, notice_name, send_obj, options = {})
|
564
|
+
logger.debug "send_notice(#{sid.inspect}, #{notice_name.inspect}) #{Time.now_to_s}"
|
565
|
+
# logger.debug "send_notice(#{sid.inspect}, #{notice_name.inspect}, #{send_obj.inspect}, #{options.inspect})"
|
564
566
|
|
565
567
|
raise(DangoFrameworkError, "send_obj is not Hash.") if ! send_obj.is_a?(Hash)
|
566
568
|
|
@@ -569,8 +571,8 @@ class DangoServerFramework
|
|
569
571
|
|
570
572
|
sock = socket_list[sid]
|
571
573
|
if !sock || sock.closed? # sockがないという事はすでに切断済み
|
572
|
-
|
573
|
-
return
|
574
|
+
logger.info "send_notice:already closed socket. sid=#{sid.inspect} sock=#{sock.inspect} #{Time.now_to_s}"
|
575
|
+
return(self)
|
574
576
|
end
|
575
577
|
|
576
578
|
# sidの通知の場合はレスポンスを気にしない
|
@@ -581,8 +583,8 @@ class DangoServerFramework
|
|
581
583
|
send_obj_dup = send_obj.deep_dup
|
582
584
|
send_obj_dup["notice"] = notice_name.to_s
|
583
585
|
|
584
|
-
|
585
|
-
#
|
586
|
+
dango_send_data(sock, send_obj_dup, :type=>dtype) # データ送信
|
587
|
+
# logger.debug "send_notice:finish send data notice_name=#{notice_name.inspect}\n"
|
586
588
|
else
|
587
589
|
Thread.start(sid, notice_name, send_obj, dtype, timeout, sock) do
|
588
590
|
begin
|
@@ -593,7 +595,7 @@ class DangoServerFramework
|
|
593
595
|
send_obj_dup["notice"] = notice_name.to_s
|
594
596
|
|
595
597
|
mutex_socket_list.synchronize(sid) do
|
596
|
-
#
|
598
|
+
# logger.debug "mutex_socket_list:synchronize:#{notice_name} #{sid} #{Time.now_to_s}"
|
597
599
|
|
598
600
|
digest_key = sid.to_s + notice_name.to_s + Time.now.to_f.to_s + rand().to_s
|
599
601
|
send_obj_dup["_id"] = Digest::MD5.hexdigest(digest_key)
|
@@ -601,31 +603,31 @@ class DangoServerFramework
|
|
601
603
|
|
602
604
|
receive_thread = Thread.start(sock, send_obj_dup, dtype) do
|
603
605
|
begin
|
604
|
-
|
605
|
-
#
|
606
|
+
dango_send_data(sock, send_obj_dup, :type=>dtype) # データ送信
|
607
|
+
# logger.debug "send_notice:sent:notice_name=#{send_obj_dup['_id']} #{notice_name.inspect} #{sid} #{Time.now_to_s}"
|
606
608
|
rescue DangoFrameworkConnectionError
|
607
|
-
|
609
|
+
logger.debug "send_notice:DangoFrameworkConnectionError:notice_name=#{notice_name.inspect} #{sid} #{Time.now_to_s}"
|
608
610
|
rescue DangoFrameworkError
|
609
|
-
|
611
|
+
logger.debug "ERROR:send_notice:DangoFrameworkError:notice_name=#{notice_name.inspect} #{sid} #{Time.now_to_s}\n #{error_message($!, 'u')}"
|
610
612
|
end
|
611
613
|
end
|
612
614
|
|
613
615
|
# データ送信スレッドの終了待ち
|
614
616
|
if !receive_thread.join(@send_timeout_sec)
|
615
617
|
# タイムアウトの場合は
|
616
|
-
|
618
|
+
logger.warn "send_notice:send timeout:#{notice_name} #{sid} #{Time.now_to_s}"
|
617
619
|
else
|
618
|
-
#
|
620
|
+
# logger.warn "send_notice:sent after join:#{notice_name} #{sid} #{Time.now_to_s}"
|
619
621
|
end_reserved_time = Time.now + timeout
|
620
622
|
|
621
623
|
# タイムアウトチェック
|
622
624
|
catch(:send_timeout) do
|
623
625
|
(timeout.to_f / @send_receive_sleep_interval_sec).to_i.times do
|
624
626
|
if Time.now > end_reserved_time
|
625
|
-
|
627
|
+
logger.debug "send_notice:receive timeout:#{notice_name}"
|
626
628
|
|
627
629
|
if notice_name.to_s == "_heart_beat" # heart beatだったらsockを止める
|
628
|
-
|
630
|
+
logger.info "!!!! send_notice:heart_beat timeout"
|
629
631
|
sock.close if !sock.closed?
|
630
632
|
end
|
631
633
|
break
|
@@ -635,7 +637,7 @@ class DangoServerFramework
|
|
635
637
|
find_res = @arr_send_response.find{|r| r[:_id] == send_obj_dup["_id"]}
|
636
638
|
|
637
639
|
if find_res
|
638
|
-
|
640
|
+
logger.debug "send_notice:find_res _heart_beat #{sid}" if notice_name.to_s == "_heart_beat"
|
639
641
|
|
640
642
|
@arr_send_response.delete(find_res)
|
641
643
|
have_came_response = true
|
@@ -648,12 +650,12 @@ class DangoServerFramework
|
|
648
650
|
end # catch 終わり
|
649
651
|
|
650
652
|
if !have_came_response # 戻ってきたデータがあるかどうかチェック
|
651
|
-
|
653
|
+
logger.warn "!!! received data is none:#{notice_name} #{sid} #{Time.now_to_s}"
|
652
654
|
end
|
653
655
|
end
|
654
656
|
end # mutex
|
655
657
|
rescue
|
656
|
-
|
658
|
+
logger.debug "send_response_thread error:#{error_message($!, 'u')}"
|
657
659
|
end
|
658
660
|
end # Thread:end
|
659
661
|
|
@@ -664,31 +666,31 @@ class DangoServerFramework
|
|
664
666
|
|
665
667
|
# 必要に応じて追加するメソッド
|
666
668
|
def method_missing(name, *args)
|
667
|
-
if name.to_s =~ /^
|
669
|
+
if name.to_s =~ /^dango_receive_action_notice_shared_(.+)/ # 共有メモリ変更通知なら
|
668
670
|
key = $1
|
669
671
|
method_action_notice_shared(key, name, *args)
|
670
672
|
else
|
671
|
-
|
673
|
+
logger.info "method not found. #{name.inspect} #{args.inspect}"
|
672
674
|
raise(NameError, "method not found. #{name.inspect} #{args.inspect}")
|
673
675
|
end
|
674
676
|
end
|
675
677
|
|
676
678
|
# 共有メモリ変更通知のメソッド
|
677
679
|
def method_action_notice_shared(key, name, *args)
|
678
|
-
|
680
|
+
logger.debug "method_name:#{name}"
|
679
681
|
send_obj = args[0]
|
680
682
|
notice_shared.notice_change(key.to_sym, send_obj)
|
681
683
|
end
|
682
684
|
|
683
685
|
# メインループ用の定義をするためのメソッド
|
684
686
|
def flameloop_thread(loop_method, options={})
|
685
|
-
|
687
|
+
logger.debug "flameloop_thread options:#{options.inspect}"
|
686
688
|
|
687
689
|
options = options.deep_dup
|
688
690
|
options[:rate] ||= 10
|
689
691
|
|
690
692
|
wait_sec = 1.0 / options[:rate]
|
691
|
-
|
693
|
+
logger.debug "flameloop_thread wait_sec:#{wait_sec.inspect}"
|
692
694
|
|
693
695
|
Thread.new do
|
694
696
|
loop do
|
@@ -696,7 +698,7 @@ class DangoServerFramework
|
|
696
698
|
begin
|
697
699
|
__send__(loop_method)
|
698
700
|
rescue
|
699
|
-
|
701
|
+
logger.debug "flameloop_thread error:#{error_message($!, 'u')}"
|
700
702
|
end
|
701
703
|
end
|
702
704
|
sleep wait_sec
|
@@ -72,7 +72,7 @@ namespace :dango do
|
|
72
72
|
begin
|
73
73
|
dm = DangoMonitorClient.new()
|
74
74
|
p dm.server_reload()
|
75
|
-
dm.
|
75
|
+
dm.dango_client_close
|
76
76
|
rescue
|
77
77
|
p $!.class
|
78
78
|
p $!.message
|
@@ -99,7 +99,7 @@ namespace :dango do
|
|
99
99
|
begin
|
100
100
|
dm = DangoMonitorClient.new()
|
101
101
|
p dm.send_system_message(message)
|
102
|
-
dm.
|
102
|
+
dm.dango_client_close
|
103
103
|
rescue
|
104
104
|
p $!.class
|
105
105
|
p $!.message
|
@@ -90,14 +90,14 @@ class TestClient < DangoClientFramework
|
|
90
90
|
|
91
91
|
attr_accessor(:client_name)
|
92
92
|
|
93
|
-
#
|
93
|
+
# dango_client_send_receive_data用の共有メモリ
|
94
94
|
def send_receive_shared_init
|
95
95
|
@send_receive_shared = SharedMemoryStore.new
|
96
96
|
end
|
97
97
|
attr_reader(:send_receive_shared)
|
98
98
|
|
99
99
|
# 起動処理
|
100
|
-
def
|
100
|
+
def dango_client_init
|
101
101
|
# サーバー接続情報など
|
102
102
|
@connection_client_host = @config["network"]["host"] # 自動でこのホスト名でサーバー開始
|
103
103
|
@connection_client_port = @config["network"]["port"] # 自動でこのポートでサーバー開始
|
@@ -109,40 +109,40 @@ class TestClient < DangoClientFramework
|
|
109
109
|
|
110
110
|
# テストサーバー
|
111
111
|
def send(name, send_obj = {})
|
112
|
-
|
113
|
-
|
112
|
+
logger.debug("tester.send:send_obj=#{send_obj.inspect} #{Time.now_to_s}")
|
113
|
+
send_action(name, send_obj)
|
114
114
|
end
|
115
115
|
|
116
116
|
# trap_receive
|
117
|
-
def trap_receive(
|
118
|
-
|
117
|
+
def trap_receive(notice_name, options = {})
|
118
|
+
logger.debug "trap_receive_data:#{notice_name}:#{Time.now_to_s}"
|
119
119
|
timeout = options[:timeout] || ReceiveTrapTimeoutSec
|
120
120
|
trap_proc = options[:proc] || nil
|
121
121
|
trap_loop = options[:loop] || nil # procがある場合のみ有効なフラグ
|
122
122
|
raise(ArgumentError, ":proc is not Proc class.") if trap_proc && ! trap_proc.is_a?(Proc)
|
123
123
|
|
124
124
|
# 戻ってきたデータのチェックメソッド
|
125
|
-
|
125
|
+
notice_name_sym = (notice_name.class == Symbol) ? (":"+notice_name.to_s) : ('"'+notice_name+'"')
|
126
126
|
|
127
|
-
if ! @receive_methods.include?(
|
128
|
-
instance_method_name = "
|
127
|
+
if ! @receive_methods.include?(notice_name_sym)
|
128
|
+
instance_method_name = "dango_receive_#{notice_name}"
|
129
129
|
expr = <<-EOF
|
130
130
|
def self.#{instance_method_name}(ret_obj)
|
131
|
-
|
132
|
-
send_receive_shared[#{
|
131
|
+
logger.debug "ret_obj:" + ret_obj.inspect + " " + Time.now_to_s
|
132
|
+
send_receive_shared[#{notice_name_sym}] = ret_obj
|
133
133
|
end
|
134
134
|
EOF
|
135
135
|
instance_eval expr
|
136
|
-
@receive_methods.push(
|
136
|
+
@receive_methods.push(notice_name_sym)
|
137
137
|
end
|
138
138
|
|
139
139
|
# @trap_thread_hashにスレッド登録
|
140
|
-
if ! @trap_thread_hash.has_key?(
|
140
|
+
if ! @trap_thread_hash.has_key?(notice_name)
|
141
141
|
|
142
142
|
# スレッド開始
|
143
|
-
th = Thread.start(
|
143
|
+
th = Thread.start(notice_name, timeout, trap_proc, trap_loop) do
|
144
144
|
loop do
|
145
|
-
send_receive_shared[
|
145
|
+
send_receive_shared[notice_name] = nil
|
146
146
|
if timeout == 0
|
147
147
|
end_reserved_time = Time.at(0) # 0ならepochを入れる
|
148
148
|
else
|
@@ -152,12 +152,12 @@ class TestClient < DangoClientFramework
|
|
152
152
|
# タイムアウトチェック
|
153
153
|
loop do
|
154
154
|
if end_reserved_time != Time.at(0) && end_reserved_time < Time.now
|
155
|
-
raise(DangoFrameworkTimeoutError, "timeout:timeout_sec=#{timeout}:\nclient_name=#{@client_name}(#{self.sid}):\
|
155
|
+
raise(DangoFrameworkTimeoutError, "timeout:timeout_sec=#{timeout}:\nclient_name=#{@client_name}(#{self.sid}):\nnotice_name=#{notice_name} \n#{Time.now_to_s}")
|
156
156
|
end
|
157
157
|
|
158
158
|
# 戻ってきたデータがあれば
|
159
|
-
if send_receive_shared[
|
160
|
-
|
159
|
+
if send_receive_shared[notice_name]
|
160
|
+
logger.debug "notice_name:#{send_receive_shared[notice_name].inspect} #{Time.now_to_s}"
|
161
161
|
break
|
162
162
|
end
|
163
163
|
|
@@ -165,21 +165,21 @@ class TestClient < DangoClientFramework
|
|
165
165
|
end
|
166
166
|
|
167
167
|
# 戻ってきたデータがあるかどうかチェック
|
168
|
-
if !send_receive_shared[
|
169
|
-
raise(DangoFrameworkError, "received data is none. sid=#{self.sid}
|
168
|
+
if !send_receive_shared[notice_name]
|
169
|
+
raise(DangoFrameworkError, "received data is none. sid=#{self.sid} notice_name=#{notice_name}")
|
170
170
|
end
|
171
171
|
|
172
172
|
# :procが設定されている場合は、それを呼び出す
|
173
173
|
if trap_proc
|
174
|
-
|
175
|
-
trap_proc.call(send_receive_shared[
|
174
|
+
logger.debug "trap_receive_data:trap_proc:#{trap_proc.inspect} #{Time.now_to_s}"
|
175
|
+
trap_proc.call(send_receive_shared[notice_name])
|
176
176
|
break if ! trap_loop # loopする必要がなければスレッド終了
|
177
177
|
|
178
178
|
# :procが設定されていなければ、wait用に@receive_arrに入れておく
|
179
179
|
else
|
180
180
|
@receive_mutex.synchronize do
|
181
|
-
|
182
|
-
@receive_arr.push([
|
181
|
+
logger.debug "notice_name:#{notice_name}:#{send_receive_shared[notice_name].inspect} #{Time.now_to_s}"
|
182
|
+
@receive_arr.push([notice_name, send_receive_shared[notice_name]])
|
183
183
|
end
|
184
184
|
break # スレッド終了
|
185
185
|
|
@@ -187,26 +187,32 @@ class TestClient < DangoClientFramework
|
|
187
187
|
end # loop
|
188
188
|
end # Thread
|
189
189
|
|
190
|
-
@trap_thread_hash[
|
190
|
+
@trap_thread_hash[notice_name] = th
|
191
191
|
else
|
192
192
|
|
193
|
-
|
193
|
+
logger.debug "trap_receive_data:already register trap:notice_name:#{notice_name} #{Time.now_to_s}"
|
194
194
|
end
|
195
195
|
|
196
196
|
end
|
197
197
|
|
198
198
|
# cancel trap_receive
|
199
|
-
def cancel_trap_receive(
|
200
|
-
|
199
|
+
def cancel_trap_receive(notice_name, options = {})
|
200
|
+
logger.debug "cancel_trap_receive:#{notice_name}:#{Time.now_to_s}"
|
201
201
|
|
202
|
-
|
202
|
+
# trapスレッドの削除
|
203
|
+
if @trap_thread_hash[notice_name]
|
204
|
+
@trap_thread_hash[notice_name].kill
|
205
|
+
@trap_thread_hash[notice_name].join
|
206
|
+
|
207
|
+
@trap_thread_hash.delete(notice_name)
|
208
|
+
end
|
203
209
|
|
204
|
-
|
210
|
+
send_receive_shared[notice_name] = nil # 受信データのごみを削除
|
205
211
|
end
|
206
212
|
|
207
213
|
# wait_receive
|
208
|
-
def wait_receive(
|
209
|
-
|
214
|
+
def wait_receive(notice_name, options = {})
|
215
|
+
logger.debug "wait_receive_data:#{notice_name}:#{Time.now_to_s}"
|
210
216
|
timeout = options[:timeout] || ReceiveWaitTimeoutSec
|
211
217
|
|
212
218
|
# データ受信待ち
|
@@ -216,7 +222,7 @@ class TestClient < DangoClientFramework
|
|
216
222
|
|
217
223
|
loop do
|
218
224
|
@receive_mutex.synchronize do
|
219
|
-
receive_data = @receive_arr.find{|r| r[0] ==
|
225
|
+
receive_data = @receive_arr.find{|r| r[0] == notice_name}.deep_dup
|
220
226
|
end
|
221
227
|
|
222
228
|
break if receive_data != nil
|
@@ -227,15 +233,15 @@ class TestClient < DangoClientFramework
|
|
227
233
|
|
228
234
|
# タイムアウトなら
|
229
235
|
if receive_data == nil
|
230
|
-
raise(DangoFrameworkTimeoutError, "timeout:timeout_sec=#{timeout}:\nclient_name=#{@client_name}(#{self.sid})\:
|
236
|
+
raise(DangoFrameworkTimeoutError, "timeout:timeout_sec=#{timeout}:\nclient_name=#{@client_name}(#{self.sid})\:notice_name=#{notice_name} \n#{Time.now_to_s}")
|
231
237
|
end
|
232
238
|
|
233
239
|
# 結果を削除しておく
|
234
240
|
@receive_mutex.synchronize do
|
235
|
-
@receive_arr.delete_if{|r| r[0] ==
|
241
|
+
@receive_arr.delete_if{|r| r[0] == notice_name}
|
236
242
|
end
|
237
243
|
|
238
|
-
@trap_thread_hash.delete(
|
244
|
+
@trap_thread_hash.delete(notice_name)
|
239
245
|
|
240
246
|
receive_data[1]
|
241
247
|
end
|
data/lib/dango/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: dango
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.26
|
7
|
+
date: 2007-11-03 00:00:00 +09:00
|
8
8
|
summary: Realtime communications network framework for Ruby and Flash on Rails.
|
9
9
|
require_paths:
|
10
10
|
- lib
|