dango 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dango/client_framework.rb +9 -1
- data/lib/dango/framework_base.rb +20 -17
- data/lib/dango/monitor/dango_monitor_client.rb +1 -1
- data/lib/dango/server_framework.rb +30 -19
- data/lib/dango/tasks/dango_rake.rb +3 -3
- data/lib/dango/tester/dango_tester_client.rb +11 -1
- data/lib/dango/version.rb +2 -2
- data/lib/dango.rb +7 -0
- metadata +4 -3
@@ -32,7 +32,7 @@ class DangoClientFramework
|
|
32
32
|
# メイン処理
|
33
33
|
def initialize(env, config = nil)
|
34
34
|
if !config
|
35
|
-
config = YAML.load(open("#{RAILS_ROOT}/dango
|
35
|
+
config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{env}.yml", "rb"){|fh| fh.read})
|
36
36
|
end
|
37
37
|
|
38
38
|
@config = config
|
@@ -45,6 +45,8 @@ class DangoClientFramework
|
|
45
45
|
# @connection_client_log_level = Logger::DEBUG # 未定義時にこのログレベルになる
|
46
46
|
@connection_client_log_level = Logger::INFO # 未定義時にこのログレベルになる
|
47
47
|
|
48
|
+
@connection_encode_type = EncodeTypeMarshal
|
49
|
+
|
48
50
|
@recv_count = 0 # 受信回数
|
49
51
|
@send_count = 0 # 送信回数
|
50
52
|
|
@@ -100,6 +102,12 @@ class DangoClientFramework
|
|
100
102
|
|
101
103
|
# データ受信用のスレッドの開始
|
102
104
|
@thread_receive = Thread.start{ thread_main() }
|
105
|
+
|
106
|
+
# エンコードタイプ変更を送信
|
107
|
+
send_obj = {"encode_type" => @connection_encode_type}
|
108
|
+
send_action("_change_encode_type", send_obj)
|
109
|
+
logger.info "_change_encode_type=#{@connection_encode_type.inspect}"
|
110
|
+
|
103
111
|
end
|
104
112
|
|
105
113
|
attr_reader(:sid)
|
data/lib/dango/framework_base.rb
CHANGED
@@ -100,13 +100,15 @@ module DangoFrameworkModule
|
|
100
100
|
include ErrorMessage
|
101
101
|
|
102
102
|
CommMaxDigit = 5 # 通信の最大桁数
|
103
|
-
|
103
|
+
MaxLenRecv = 1024 # 通信の一度の送信バイト数
|
104
|
+
MaxLenSend = 1024 # 通信の一度の送信バイト数
|
104
105
|
|
105
|
-
|
106
|
+
EncodeTypeJSON = 0 # エンコードのタイプのJSON
|
107
|
+
EncodeTypeYAML = 1 # エンコードのタイプのYAML
|
108
|
+
EncodeTypeMarshal = 2 # エンコードのタイプのMarshal
|
109
|
+
|
110
|
+
DefaultEncodeType = EncodeTypeJSON # デフォルトのエンコードのタイプ
|
106
111
|
|
107
|
-
# 0 = JSON
|
108
|
-
# 1 = YAML
|
109
|
-
# 2 = Marshal
|
110
112
|
|
111
113
|
# デバッグ出力用のメソッド
|
112
114
|
def debug_print(str)
|
@@ -168,7 +170,7 @@ module DangoFrameworkModule
|
|
168
170
|
end
|
169
171
|
|
170
172
|
## サイズとデータタイプを取得
|
171
|
-
|
173
|
+
encode_type, size = size_str[0, 5].unpack("cN")
|
172
174
|
|
173
175
|
## データがない場合
|
174
176
|
if size == nil || size == 0
|
@@ -185,7 +187,7 @@ module DangoFrameworkModule
|
|
185
187
|
ret_data_orig = ""
|
186
188
|
|
187
189
|
while size > 0
|
188
|
-
read_len =
|
190
|
+
read_len = MaxLenRecv > size ? size : MaxLenRecv
|
189
191
|
begin
|
190
192
|
# this_ret_data_orig = sock.readpartial(read_len)
|
191
193
|
# this_ret_data_orig = sock.sysread(read_len)
|
@@ -211,11 +213,11 @@ module DangoFrameworkModule
|
|
211
213
|
begin
|
212
214
|
if ret_data == "" || ret_data == "{}" # データが空ならparseしない
|
213
215
|
data = []
|
214
|
-
elsif
|
216
|
+
elsif encode_type == EncodeTypeJSON
|
215
217
|
data = JSON.parse(ret_data)
|
216
|
-
elsif
|
218
|
+
elsif encode_type == EncodeTypeYAML
|
217
219
|
data = YAML::load(ret_data)
|
218
|
-
elsif
|
220
|
+
elsif encode_type == EncodeTypeMarshal
|
219
221
|
data = Marshal.load(ret_data)
|
220
222
|
end
|
221
223
|
rescue
|
@@ -225,18 +227,19 @@ module DangoFrameworkModule
|
|
225
227
|
|
226
228
|
# データ送信処理
|
227
229
|
def dango_send_data(sock, send_objs, options = {})
|
228
|
-
|
229
|
-
|
230
|
-
dtype = options[:type] || DefaultDataType
|
230
|
+
encode_type = options[:encode_type] || DefaultEncodeType
|
231
|
+
# logger.debug "dango_send_data:sock=#{sock.inspect} encode_type=#{encode_type}"
|
231
232
|
|
232
233
|
if send_objs == []
|
233
234
|
send_data_orig = ""
|
234
|
-
elsif
|
235
|
+
elsif encode_type == EncodeTypeJSON
|
235
236
|
send_data_orig = JSON.generate(send_objs)
|
236
|
-
elsif
|
237
|
+
elsif encode_type == EncodeTypeYAML
|
237
238
|
send_data_orig = send_objs.to_yaml
|
238
|
-
elsif
|
239
|
+
elsif encode_type == EncodeTypeMarshal
|
239
240
|
send_data_orig = Marshal.dump(send_objs)
|
241
|
+
else
|
242
|
+
send_data_orig = JSON.generate(send_objs)
|
240
243
|
end
|
241
244
|
|
242
245
|
# logger.debug "dango_send_data:#{send_data_orig.inspect}"
|
@@ -257,7 +260,7 @@ module DangoFrameworkModule
|
|
257
260
|
|
258
261
|
# size_str = sprintf("%0#{CommMaxDigit}d", size)
|
259
262
|
|
260
|
-
size_str = [
|
263
|
+
size_str = [encode_type, size].pack("cN")
|
261
264
|
# logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
262
265
|
|
263
266
|
send_buf = size_str + "\n" + send_data
|
@@ -17,7 +17,7 @@ class DangoMonitorClient < DangoClientFramework
|
|
17
17
|
|
18
18
|
def initialize()
|
19
19
|
@env = ENV['RAILS_ENV'] || 'development'
|
20
|
-
config = YAML.load(open("#{RAILS_ROOT}/dango
|
20
|
+
config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{@env}.yml", "rb"){|fh| fh.read})
|
21
21
|
super(@env, config)
|
22
22
|
end
|
23
23
|
|
@@ -298,9 +298,11 @@ class DangoServerFramework
|
|
298
298
|
sid = session[:sid]
|
299
299
|
|
300
300
|
session[:peer_addr] = sock.peeraddr
|
301
|
-
session[:
|
301
|
+
session[:peer_ip_address] = sock.peeraddr[3]
|
302
302
|
session[:peer_host] = sock.peeraddr[2]
|
303
303
|
|
304
|
+
session[:encode_type] = DefaultEncodeType
|
305
|
+
|
304
306
|
logger.debug "thread_main:start_session. sid=#{sid} sock=#{sock} thread.current=#{Thread.current.object_id}"
|
305
307
|
|
306
308
|
socket_list.add(sid, sock)
|
@@ -363,16 +365,6 @@ EOF
|
|
363
365
|
# logger.debug "ret_objs is empty. "
|
364
366
|
|
365
367
|
else # 受信データがあれば
|
366
|
-
if ! session[:connected] # まだdango_connectを呼び出していないなら
|
367
|
-
# 接続直後のsid通知
|
368
|
-
send_obj = {"_sid"=>sid}
|
369
|
-
send_notice("_notice_sid", sid, send_obj)
|
370
|
-
logger.debug "_notice_sid #{sid} "
|
371
|
-
|
372
|
-
dango_connect() # 接続時メソッド呼び出し
|
373
|
-
session[:connected] = true
|
374
|
-
end
|
375
|
-
|
376
368
|
ret_objs.each do |ret_obj| # 受信データループ
|
377
369
|
if !(ret_obj && ret_obj["action"]) # actionが無い場合はエラー
|
378
370
|
logger.warn "no action error:#{ret_obj.inspect}"
|
@@ -399,6 +391,9 @@ EOF
|
|
399
391
|
elsif action_name == '_response' # 送信パケットの返事なら
|
400
392
|
action_name_is_response(ret_obj)
|
401
393
|
|
394
|
+
elsif action_name == '_change_encode_type' # エンコードタイプの変更なら
|
395
|
+
action_name_is_change_encode_type(ret_obj)
|
396
|
+
|
402
397
|
else # メンテナンスコマンド以外のユーザーアクション名なら
|
403
398
|
logger.debug "receive_action:#{sid}:#{action_name}:"
|
404
399
|
begin
|
@@ -415,6 +410,16 @@ EOF
|
|
415
410
|
session.delete(:_action_name)
|
416
411
|
session.delete(:_return)
|
417
412
|
end
|
413
|
+
|
414
|
+
if ! session[:connected] # まだdango_connectを呼び出していないなら
|
415
|
+
# 接続直後のsid通知
|
416
|
+
send_obj = {"_sid"=>sid}
|
417
|
+
send_notice("_notice_sid", sid, send_obj)
|
418
|
+
logger.debug "_notice_sid #{sid} "
|
419
|
+
|
420
|
+
dango_connect() # 接続時メソッド呼び出し
|
421
|
+
session[:connected] = true
|
422
|
+
end
|
418
423
|
end
|
419
424
|
|
420
425
|
end # loop
|
@@ -479,6 +484,12 @@ EOF
|
|
479
484
|
end
|
480
485
|
end
|
481
486
|
|
487
|
+
# action_nameが送信パケットの返事なら
|
488
|
+
def action_name_is_change_encode_type(ret_obj)
|
489
|
+
logger.debug "action_name_is_change_encode_type: #{ret_obj['encode_type'].inspect}"
|
490
|
+
session[:encode_type] = ret_obj['encode_type']
|
491
|
+
end
|
492
|
+
|
482
493
|
# 各種サーバー仕様の変数設定
|
483
494
|
def set_server_variables()
|
484
495
|
# debug
|
@@ -731,7 +742,7 @@ EOF
|
|
731
742
|
raise(DangoFrameworkError, "sids is not Array.") if ! sids.is_a?(Array)
|
732
743
|
|
733
744
|
# timeout = options[:timeout] || @send_receive_timeout_default_sec
|
734
|
-
|
745
|
+
encode_type = options[:encode_type] || 0
|
735
746
|
|
736
747
|
send_obj_dup = send_obj.deep_dup
|
737
748
|
send_obj_dup["notice"] = notice_name.to_s
|
@@ -743,7 +754,7 @@ EOF
|
|
743
754
|
send_id = notice_name.to_s + Time.now.to_f.to_s + rand().to_s
|
744
755
|
send_obj_dup["_id"] = send_id
|
745
756
|
|
746
|
-
@queue_send_notice.push([sid, send_obj_dup,
|
757
|
+
@queue_send_notice.push([sid, send_obj_dup, encode_type].deep_dup)
|
747
758
|
end # end sids.each
|
748
759
|
|
749
760
|
# raise(DangoFrameworkConnectionError, "send_notice:error happened.") if is_error
|
@@ -769,14 +780,14 @@ EOF
|
|
769
780
|
end
|
770
781
|
|
771
782
|
send_data_sid_list = {}
|
772
|
-
|
783
|
+
send_data_encode_type_list = {}
|
773
784
|
send_data_list.each do |one_send_data| # sidごとに分ける
|
774
|
-
sid
|
775
|
-
send_obj
|
776
|
-
|
785
|
+
sid = one_send_data[0]
|
786
|
+
send_obj = one_send_data[1]
|
787
|
+
encode_type = one_send_data[2]
|
777
788
|
send_data_sid_list[sid] = [] if ! send_data_sid_list.has_key?(sid)
|
778
789
|
send_data_sid_list[sid].push(send_obj)
|
779
|
-
|
790
|
+
send_data_encode_type_list[sid] = encode_type
|
780
791
|
end
|
781
792
|
|
782
793
|
# sidごとにデータをまとめ送り
|
@@ -797,7 +808,7 @@ EOF
|
|
797
808
|
|
798
809
|
# logger.debug one_send_data_list.pretty_inspect
|
799
810
|
|
800
|
-
dango_send_data(sock, one_send_data_list, :type=>
|
811
|
+
dango_send_data(sock, one_send_data_list, :type=>send_data_encode_type_list[sid]) # データ送信
|
801
812
|
|
802
813
|
rescue DangoFrameworkConnectionError
|
803
814
|
logger.info "thread_send_notice_queue:failed send. sid=#{sid} sock=#{sock.inspect} #{$!.class}"
|
@@ -91,7 +91,7 @@ def check_dango_connect()
|
|
91
91
|
require 'dango/tester/dango_tester_client'
|
92
92
|
|
93
93
|
# コンフィグから check_dango_process_cmd を取得
|
94
|
-
config = YAML.load(open("dango
|
94
|
+
config = YAML.load(open("config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
|
95
95
|
|
96
96
|
serv_info = {}
|
97
97
|
serv_info["host"] = config['network']['host'] || 'localhost'
|
@@ -157,7 +157,7 @@ namespace :dango do
|
|
157
157
|
is_alive_server = check_dango_connect() if is_pid_exist # サーバーへの通信を使ったチェック
|
158
158
|
|
159
159
|
# コンフィグから check_dango_process_cmd を取得
|
160
|
-
config = YAML.load(open("dango
|
160
|
+
config = YAML.load(open("config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
|
161
161
|
check_dango_process_cmd = config['server']['check_dango_process_cmd'] || nil
|
162
162
|
|
163
163
|
# is_pid_existがないならcheck_dango_process_cmd実行
|
@@ -227,7 +227,7 @@ namespace :dango do
|
|
227
227
|
require "yaml"
|
228
228
|
require 'dango/monitor/dango_monitor_client.rb'
|
229
229
|
|
230
|
-
system_message = YAML.load(open("dango/
|
230
|
+
system_message = YAML.load(open("config/dango/system_message.yml", "rb"){|fh| fh.read})
|
231
231
|
message = system_message[message_type]
|
232
232
|
|
233
233
|
begin
|
@@ -49,7 +49,8 @@ class DangoTesterClient
|
|
49
49
|
rescue
|
50
50
|
client_conn = nil
|
51
51
|
raise("connection error for retry times over.") if i == ConnectionRetryTimes - 1
|
52
|
-
puts "
|
52
|
+
puts "#{$!.class} #{$!.message} #{$!.backtrace.inspect}" if @debug
|
53
|
+
puts "connection failed. sleep #{ConnectionRetryIntervalSec}"
|
53
54
|
sleep ConnectionRetryIntervalSec
|
54
55
|
end
|
55
56
|
end
|
@@ -117,6 +118,7 @@ class TestClient < DangoClientFramework
|
|
117
118
|
def initialize(env, config, c_name)
|
118
119
|
@config = config
|
119
120
|
@client_name = c_name # クライアント名
|
121
|
+
@client_data = {} # データ保管用
|
120
122
|
|
121
123
|
@receive_cache_auto_delete_sec = config['tester']['receive_cache_auto_delete_sec']
|
122
124
|
|
@@ -135,6 +137,14 @@ class TestClient < DangoClientFramework
|
|
135
137
|
|
136
138
|
attr_accessor(:client_name)
|
137
139
|
|
140
|
+
# データ保管用の場所を作っておく
|
141
|
+
def []=(key, value)
|
142
|
+
@client_data[key] = value
|
143
|
+
end
|
144
|
+
def [](key)
|
145
|
+
@client_data[key]
|
146
|
+
end
|
147
|
+
|
138
148
|
# dango_client_send_receive_data用の共有メモリ
|
139
149
|
def send_receive_shared_init
|
140
150
|
@send_receive_shared = SharedMemoryStore.new
|
data/lib/dango/version.rb
CHANGED
data/lib/dango.rb
ADDED
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.
|
4
|
+
version: 0.3.0
|
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-06-
|
12
|
+
date: 2008-06-19 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.
|
31
|
+
version: 0.3.0
|
32
32
|
version:
|
33
33
|
description: Realtime communications network framework for Ruby and Flash on Rails.
|
34
34
|
email: keisuke@rccn.com
|
@@ -41,6 +41,7 @@ extra_rdoc_files:
|
|
41
41
|
files:
|
42
42
|
- README.txt
|
43
43
|
- LICENSE
|
44
|
+
- lib/dango.rb
|
44
45
|
- lib/dango/client_framework.rb
|
45
46
|
- lib/dango/framework_base.rb
|
46
47
|
- lib/dango/server_framework.rb
|