dango 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt
CHANGED
@@ -0,0 +1,171 @@
|
|
1
|
+
#!ruby -Ku
|
2
|
+
|
3
|
+
=begin
|
4
|
+
= コネクション型サーバーフレームワーク
|
5
|
+
=end
|
6
|
+
|
7
|
+
require 'dango/client_framework' # コネクションクライアントフレームワークの呼び出し
|
8
|
+
|
9
|
+
# テスタークラス
|
10
|
+
class DangoTesterClient
|
11
|
+
# テスターのイニシャライズ
|
12
|
+
def initialize
|
13
|
+
@client_conns = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# クライアントを1個接続
|
17
|
+
def new_client(c_name, serv_info)
|
18
|
+
config = {
|
19
|
+
"network" => {
|
20
|
+
"host"=>serv_info["host"],
|
21
|
+
"port"=>serv_info["port"],
|
22
|
+
},
|
23
|
+
}
|
24
|
+
env = "development"
|
25
|
+
|
26
|
+
# 接続
|
27
|
+
client_conn = TestClient.new(env, config)
|
28
|
+
|
29
|
+
# client_nameメソッド作成とclient_nameを定義
|
30
|
+
client_conn.client_name = c_name
|
31
|
+
|
32
|
+
# 接続を入れて
|
33
|
+
@client_conns[c_name] = client_conn
|
34
|
+
|
35
|
+
# 接続インスタンスを返す
|
36
|
+
client_conn
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader(:client_conns)
|
40
|
+
end
|
41
|
+
|
42
|
+
# テスト接続用のクラス
|
43
|
+
class TestClient < DangoClientFramework
|
44
|
+
SendReceiveSleepIntervalSec = 0.1 # データ送信後の順の際のタイムアウトチェック間隔秒
|
45
|
+
SendReceiveTimeoutSec = 5 # データ送信後の順の際のタイムアウトチェック間隔秒
|
46
|
+
|
47
|
+
def initialize(env, config)
|
48
|
+
@config = config
|
49
|
+
super(env, config)
|
50
|
+
|
51
|
+
@receive_mutex = Mutex.new # 送受信用の排他処理
|
52
|
+
@receive_arr = []
|
53
|
+
@receive_defined_names = []
|
54
|
+
|
55
|
+
@client_name = nil # クライアント名
|
56
|
+
|
57
|
+
send_receive_shared_init()
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor(:client_name)
|
61
|
+
|
62
|
+
# cs_client_send_receive_data用の共有メモリ
|
63
|
+
def send_receive_shared_init
|
64
|
+
@send_receive_shared = SharedMemoryStore.new
|
65
|
+
end
|
66
|
+
attr_reader(:send_receive_shared)
|
67
|
+
|
68
|
+
# 起動処理
|
69
|
+
def cs_client_init
|
70
|
+
# サーバー接続情報など
|
71
|
+
@connection_client_host = @config["network"]["host"] # 自動でこのホスト名でサーバー開始
|
72
|
+
@connection_client_port = @config["network"]["port"] # 自動でこのポートでサーバー開始
|
73
|
+
|
74
|
+
# ログ出力情報
|
75
|
+
@connection_client_log_file = "log/lt_client_base.log" # 自動でこのログファイル名を使う
|
76
|
+
@connection_client_log_level = Logger::DEBUG # 自動でこのログレベルになる
|
77
|
+
end
|
78
|
+
|
79
|
+
# テストサーバー
|
80
|
+
def send(name, send_obj = {})
|
81
|
+
cs_logger.debug("tester.send:send_obj=#{send_obj.inspect} #{Time.now}")
|
82
|
+
cs_client_send_data(name, send_obj)
|
83
|
+
end
|
84
|
+
|
85
|
+
# make_receive_stack
|
86
|
+
def make_receive_stack(receive_name, options = {})
|
87
|
+
timeout = options[:timeout] || SendReceiveTimeoutSec
|
88
|
+
|
89
|
+
@receive_defined_names.push(receive_name)
|
90
|
+
|
91
|
+
Thread.start do
|
92
|
+
send_receive_shared[receive_name] = nil
|
93
|
+
end_reserved_time = Time.now + timeout
|
94
|
+
|
95
|
+
# 戻ってきたデータのチェック
|
96
|
+
receive_name_sym = (receive_name.class == Symbol) ? (":"+receive_name.to_s) : ('"'+receive_name+'"')
|
97
|
+
instance_method_name = "cs_receive_#{receive_name}"
|
98
|
+
expr = <<-EOF
|
99
|
+
def self.#{instance_method_name}(ret_obj)
|
100
|
+
cs_logger.debug "ret_obj:" + ret_obj.inspect
|
101
|
+
send_receive_shared[#{receive_name_sym}] = ret_obj
|
102
|
+
end
|
103
|
+
EOF
|
104
|
+
instance_eval expr
|
105
|
+
|
106
|
+
# タイムアウトチェック
|
107
|
+
(timeout.to_f / SendReceiveSleepIntervalSec).to_i.times do
|
108
|
+
if Time.now > end_reserved_time
|
109
|
+
raise(DangoFrameworkTimeoutError, "timeout:client_name=#{@client_name}:receive_name=#{receive_name}")
|
110
|
+
end
|
111
|
+
|
112
|
+
# 戻ってきたデータがあれば
|
113
|
+
if send_receive_shared[receive_name]
|
114
|
+
cs_logger.debug "receive_name:#{send_receive_shared[receive_name].inspect}"
|
115
|
+
break
|
116
|
+
end
|
117
|
+
|
118
|
+
sleep SendReceiveSleepIntervalSec # スリープ
|
119
|
+
end
|
120
|
+
|
121
|
+
if !send_receive_shared[receive_name] # 戻ってきたデータがあるかどうかチェック
|
122
|
+
raise(DangoFrameworkError, "received data is none")
|
123
|
+
end
|
124
|
+
|
125
|
+
@receive_mutex.synchronize do
|
126
|
+
@receive_arr.push([receive_name, send_receive_shared[receive_name]])
|
127
|
+
# p @receive_arr
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# wait_receive_data
|
133
|
+
def wait_receive_data(receive_name, options = {})
|
134
|
+
timeout = options[:timeout] || SendReceiveTimeoutSec
|
135
|
+
|
136
|
+
# データ受信待ち
|
137
|
+
receive_data = nil
|
138
|
+
(timeout.to_f / SendReceiveSleepIntervalSec).to_i.times do
|
139
|
+
@receive_mutex.synchronize do
|
140
|
+
receive_data = @receive_arr.find{|r| r[0] == receive_name}.deep_dup
|
141
|
+
# p @receive_arr
|
142
|
+
end
|
143
|
+
break if receive_data != nil
|
144
|
+
sleep SendReceiveSleepIntervalSec # スリープ
|
145
|
+
end
|
146
|
+
|
147
|
+
# タイムアウトなら
|
148
|
+
if receive_data == nil
|
149
|
+
raise(DangoFrameworkTimeoutError, "timeout:client_name=#{@client_name}:receive_name=#{receive_name}")
|
150
|
+
end
|
151
|
+
|
152
|
+
# 結果を削除しておく
|
153
|
+
@receive_mutex.synchronize do
|
154
|
+
@receive_arr.delete_if{|r| r[0] == receive_name}
|
155
|
+
end
|
156
|
+
|
157
|
+
receive_data[1]
|
158
|
+
end
|
159
|
+
|
160
|
+
# receive_arrの状態確認
|
161
|
+
def receive_arr
|
162
|
+
receive_arr = nil
|
163
|
+
@receive_mutex.synchronize do
|
164
|
+
receive_arr = @receive_arr.deep_dup
|
165
|
+
end
|
166
|
+
receive_arr
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
data/lib/dango/version.rb
CHANGED
metadata
CHANGED
@@ -3,7 +3,7 @@ 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.
|
6
|
+
version: 0.0.10
|
7
7
|
date: 2007-10-15 00:00:00 +09:00
|
8
8
|
summary: Ruby - Flash conneciton network flamework
|
9
9
|
require_paths:
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/dango/script/dango_server.rb
|
39
39
|
- lib/dango/shared/memory_store.rb
|
40
40
|
- lib/dango/tasks/dango_rake.rb
|
41
|
+
- lib/dango/tester/dango_tester_client.rb
|
41
42
|
- lib/dango/version.rb
|
42
43
|
- setup.rb
|
43
44
|
- test/test_helper.rb
|