bayserver-core 2.3.2 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
- data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
- data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
- data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
- data/lib/baykit/bayserver/agent/letter.rb +30 -0
- data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
- data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
- data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
- data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
- data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
- data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
- data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
- data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
- data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
- data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
- data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
- data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
- data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
- data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
- data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
- data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
- data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
- data/lib/baykit/bayserver/bay_log.rb +1 -0
- data/lib/baykit/bayserver/bayserver.rb +32 -28
- data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
- data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
- data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
- data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
- data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
- data/lib/baykit/bayserver/common/postpone.rb +15 -0
- data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
- data/lib/baykit/bayserver/common/recipient.rb +24 -0
- data/lib/baykit/bayserver/common/vehicle.rb +24 -0
- data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
- data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
- data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
- data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
- data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
- data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
- data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
- data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
- data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
- data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
- data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
- data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
- data/lib/baykit/bayserver/docker/city.rb +27 -13
- data/lib/baykit/bayserver/docker/club.rb +8 -8
- data/lib/baykit/bayserver/docker/docker.rb +9 -1
- data/lib/baykit/bayserver/docker/harbor.rb +184 -22
- data/lib/baykit/bayserver/docker/permission.rb +7 -6
- data/lib/baykit/bayserver/docker/port.rb +39 -11
- data/lib/baykit/bayserver/docker/secure.rb +11 -9
- data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
- data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
- data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
- data/lib/baykit/bayserver/docker/town.rb +31 -15
- data/lib/baykit/bayserver/docker/trouble.rb +17 -5
- data/lib/baykit/bayserver/docker/warp.rb +34 -0
- data/lib/baykit/bayserver/mem_usage.rb +9 -9
- data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
- data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
- data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
- data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
- data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
- data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
- data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
- data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
- data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
- data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
- data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
- data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
- data/lib/baykit/bayserver/tours/tour.rb +2 -2
- data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
- data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
- data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
- data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
- data/lib/baykit/bayserver/train/train_runner.rb +17 -13
- data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
- data/lib/baykit/bayserver/util/executor_service.rb +11 -7
- data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
- data/lib/baykit/bayserver/util/locale.rb +1 -1
- data/lib/baykit/bayserver/util/selector.rb +24 -5
- data/lib/baykit/bayserver/util/sys_util.rb +6 -6
- data/lib/baykit/bayserver/version.rb +1 -1
- metadata +37 -18
- data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
- data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
- data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
- data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
- data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
- data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
- data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
- /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'baykit/bayserver/common/recipient'
|
2
|
+
require 'baykit/bayserver/rudders/rudder'
|
3
|
+
require 'baykit/bayserver/rudders/io_rudder'
|
4
|
+
|
5
|
+
require 'baykit/bayserver/agent/multiplexer/multiplexer_base'
|
6
|
+
require 'baykit/bayserver/agent/timer_handler'
|
7
|
+
|
8
|
+
module Baykit
|
9
|
+
module BayServer
|
10
|
+
module Agent
|
11
|
+
module Multiplexer
|
12
|
+
class SpinMultiplexer < Baykit::BayServer::Agent::Multiplexer::MultiplexerBase
|
13
|
+
include Baykit::BayServer::Agent::TimerHandler #implements
|
14
|
+
|
15
|
+
include Baykit::BayServer::Rudders
|
16
|
+
include Baykit::BayServer::Util
|
17
|
+
|
18
|
+
class Lapper # abstract class
|
19
|
+
|
20
|
+
attr :state
|
21
|
+
attr :last_access
|
22
|
+
|
23
|
+
def initialize(state)
|
24
|
+
@state = state
|
25
|
+
access
|
26
|
+
end
|
27
|
+
|
28
|
+
def access
|
29
|
+
@last_access = Time.now.tv_sec
|
30
|
+
end
|
31
|
+
|
32
|
+
def lap()
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def next
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
other.state == @state
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class ReadIOLapper < Lapper
|
46
|
+
|
47
|
+
attr :agent
|
48
|
+
|
49
|
+
def initialize(agt, st)
|
50
|
+
super(st)
|
51
|
+
@agent = agt
|
52
|
+
st.rudder.set_non_blocking
|
53
|
+
end
|
54
|
+
|
55
|
+
def lap
|
56
|
+
spun = false
|
57
|
+
|
58
|
+
begin
|
59
|
+
infile = @state.rudder.io
|
60
|
+
eof = false
|
61
|
+
|
62
|
+
begin
|
63
|
+
n = @state.rudder.read(@state.read_buf, @state.buf_size)
|
64
|
+
#infile.sysread(@state.buf_size, @state.read_buf)
|
65
|
+
rescue EOFError => e
|
66
|
+
@state.read_buf.clear
|
67
|
+
eof = true
|
68
|
+
rescue Errno::EAGAIN => e
|
69
|
+
BayLog.debug("%s %s", @agent, e)
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
|
73
|
+
if @state.read_buf.length == 0
|
74
|
+
if !eof
|
75
|
+
return true
|
76
|
+
else
|
77
|
+
BayLog.debug("%s Spin read: EOF\\(^o^)/ rd=%s", @agent, infile)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
@agent.send_read_letter(@state, @state.read_buf.length, nil, nil, false)
|
82
|
+
return false
|
83
|
+
|
84
|
+
rescue Exception => e
|
85
|
+
BayLog.error_e(e, "%s Error", @agent)
|
86
|
+
@agent.send_close_req_letter(@state, false)
|
87
|
+
return false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def next
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
attr :spin_count
|
98
|
+
attr :running_list
|
99
|
+
attr :running_list_lock
|
100
|
+
|
101
|
+
def initialize(agt)
|
102
|
+
super(agt)
|
103
|
+
@spin_count = 0
|
104
|
+
@running_list = []
|
105
|
+
@running_list_lock = Mutex.new
|
106
|
+
@agent.add_timer_handler(self)
|
107
|
+
end
|
108
|
+
def to_s
|
109
|
+
return "SpnMpx[#{@agent}]"
|
110
|
+
end
|
111
|
+
|
112
|
+
#########################################
|
113
|
+
# Implements Multiplexer
|
114
|
+
#########################################
|
115
|
+
|
116
|
+
def req_accept(rd)
|
117
|
+
raise NotImplementedError.new
|
118
|
+
end
|
119
|
+
|
120
|
+
def req_connect(rd, adr)
|
121
|
+
raise NotImplementedError.new
|
122
|
+
end
|
123
|
+
|
124
|
+
def req_read(rd)
|
125
|
+
st = get_rudder_state(rd)
|
126
|
+
if st == nil
|
127
|
+
BayLog.error("%s Invalid rudder", self)
|
128
|
+
return
|
129
|
+
end
|
130
|
+
|
131
|
+
need_read = false
|
132
|
+
st.reading_lock.synchronize do
|
133
|
+
if not st.reading
|
134
|
+
need_read = true
|
135
|
+
st.reading = true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
if need_read
|
140
|
+
next_read(st)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def req_write(rd, buf, len, adr, tag, lis)
|
145
|
+
st = get_rudder_state(rd)
|
146
|
+
if st == nil
|
147
|
+
raise IOError("Invalid rudder")
|
148
|
+
end
|
149
|
+
|
150
|
+
unt = WriteUnit.new(buf, adr, tag, lis)
|
151
|
+
st.write_queue_lock.synchronize do
|
152
|
+
st.write_queue << unt
|
153
|
+
end
|
154
|
+
st.access
|
155
|
+
|
156
|
+
need_write = false
|
157
|
+
st.writing_lock.synchronize do
|
158
|
+
if not st.writing
|
159
|
+
need_write = true
|
160
|
+
st.writing = true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
if need_write
|
165
|
+
next_write(st)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def req_end(rd)
|
170
|
+
st = get_rudder_state(rd)
|
171
|
+
st.finale = true
|
172
|
+
end
|
173
|
+
|
174
|
+
def req_close(rd)
|
175
|
+
st = get_rudder_state(rd)
|
176
|
+
st.closing = true
|
177
|
+
@agent.send_close_req_letter(st, false)
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def shutdown
|
182
|
+
wakeup
|
183
|
+
end
|
184
|
+
|
185
|
+
def is_non_blocking
|
186
|
+
return false
|
187
|
+
end
|
188
|
+
|
189
|
+
def use_async_api
|
190
|
+
return false
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
def cancel_read(st)
|
195
|
+
st.reading_lock.synchronize do
|
196
|
+
BayLog.debug("%s Reading off %s", agent, st.rudder)
|
197
|
+
st.reading = false
|
198
|
+
end
|
199
|
+
remove_from_running_list(st)
|
200
|
+
end
|
201
|
+
|
202
|
+
def cancel_write(st)
|
203
|
+
end
|
204
|
+
|
205
|
+
def next_accept(st)
|
206
|
+
end
|
207
|
+
|
208
|
+
def next_read(st)
|
209
|
+
lpr = ReadIOLapper.new(@agent, st)
|
210
|
+
lpr.next
|
211
|
+
|
212
|
+
add_to_running_list(lpr)
|
213
|
+
end
|
214
|
+
|
215
|
+
def next_write(st)
|
216
|
+
end
|
217
|
+
|
218
|
+
def on_busy
|
219
|
+
BayLog.debug("%s onBusy", agent)
|
220
|
+
BayServer::anchorable_port_map.keys.each do |rd|
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def on_free
|
226
|
+
BayLog.debug("%s onFree aborted=%s", agent, agent.aborted);
|
227
|
+
if agent.aborted
|
228
|
+
return
|
229
|
+
end
|
230
|
+
|
231
|
+
BayServer.anchorable_port_map.keys.each do |rd|
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def close_rudder(st)
|
237
|
+
remove_from_running_list(st)
|
238
|
+
super
|
239
|
+
end
|
240
|
+
|
241
|
+
#########################################
|
242
|
+
# Implements TimerHandler
|
243
|
+
#########################################
|
244
|
+
|
245
|
+
def on_timer
|
246
|
+
#stop_timeout_spins
|
247
|
+
end
|
248
|
+
|
249
|
+
#########################################
|
250
|
+
# Custom methods
|
251
|
+
#########################################
|
252
|
+
def is_empty
|
253
|
+
return @running_list.empty?
|
254
|
+
end
|
255
|
+
|
256
|
+
def process_data
|
257
|
+
if is_empty
|
258
|
+
return false
|
259
|
+
end
|
260
|
+
|
261
|
+
all_spun = true
|
262
|
+
remove_list = []
|
263
|
+
@running_list.length.downto(1) do |i|
|
264
|
+
lpr = @running_list[i-1]
|
265
|
+
st = lpr.state
|
266
|
+
spun = lpr.lap
|
267
|
+
st.access
|
268
|
+
|
269
|
+
all_spun = all_spun & spun
|
270
|
+
end
|
271
|
+
|
272
|
+
if all_spun
|
273
|
+
@spin_count += 1
|
274
|
+
if @spin_count > 10
|
275
|
+
sleep(0.01)
|
276
|
+
else
|
277
|
+
@spin_count = 0
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
return true
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
#########################################
|
286
|
+
# Private methods
|
287
|
+
#########################################
|
288
|
+
private
|
289
|
+
|
290
|
+
def remove_from_running_list(st)
|
291
|
+
BayLog.debug("remove: %s", st.rudder)
|
292
|
+
@running_list_lock.synchronize do
|
293
|
+
@running_list.delete_if do |lpr |
|
294
|
+
lpr.state == st
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def add_to_running_list(lpr)
|
300
|
+
BayLog.debug("add: %s", lpr.state.rudder)
|
301
|
+
@running_list_lock.synchronize do
|
302
|
+
if !@running_list.include?(lpr)
|
303
|
+
@running_list << lpr
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'baykit/bayserver/sink'
|
2
|
+
require 'baykit/bayserver/rudders/io_rudder'
|
3
|
+
|
4
|
+
require 'baykit/bayserver/agent/multiplexer/multiplexer_base'
|
5
|
+
require 'baykit/bayserver/taxi/taxi'
|
6
|
+
require 'baykit/bayserver/taxi/taxi_runner'
|
7
|
+
|
8
|
+
|
9
|
+
module Baykit
|
10
|
+
module BayServer
|
11
|
+
module Agent
|
12
|
+
module Multiplexer
|
13
|
+
class TaxiMultiplexer < MultiplexerBase
|
14
|
+
|
15
|
+
class TaxiForMpx < Baykit::BayServer::Taxi::Taxi
|
16
|
+
attr :rudder_state
|
17
|
+
attr :for_read
|
18
|
+
def initialize(st, for_read)
|
19
|
+
@rudder_state = st
|
20
|
+
@for_read = for_read
|
21
|
+
end
|
22
|
+
def depart
|
23
|
+
if @for_read
|
24
|
+
@rudder_state.multiplexer.do_next_read(@rudder_state)
|
25
|
+
else
|
26
|
+
@rudder_state.multiplexer.do_next_write(@rudder_state)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_timer
|
31
|
+
if @rudder_state.transporter != nil
|
32
|
+
@rudder_state.transporter.check_timeout(@rudder_state.rudder, -1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
include Baykit::BayServer::Agent::Multiplexer
|
38
|
+
|
39
|
+
include Baykit::BayServer
|
40
|
+
include Baykit::BayServer::Rudders
|
41
|
+
include Baykit::BayServer::Util
|
42
|
+
include Baykit::BayServer::Taxi
|
43
|
+
|
44
|
+
def initialize(agt)
|
45
|
+
super
|
46
|
+
end
|
47
|
+
def to_s
|
48
|
+
return "TaxiMpx[#{@agent}]"
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
#########################################
|
53
|
+
# Implements Multiplexer
|
54
|
+
#########################################
|
55
|
+
|
56
|
+
def req_accept(rd)
|
57
|
+
raise Sink.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def req_connect(rd, adr)
|
61
|
+
raise Sink.new
|
62
|
+
end
|
63
|
+
|
64
|
+
def req_read(rd)
|
65
|
+
st = get_rudder_state(rd)
|
66
|
+
if st == nil
|
67
|
+
return
|
68
|
+
end
|
69
|
+
|
70
|
+
BayLog.debug("%s reqRead rd=%s state=%s", @agent, st.rudder, st);
|
71
|
+
need_read = false
|
72
|
+
st.reading_lock.synchronize do
|
73
|
+
if !st.reading
|
74
|
+
need_read = true
|
75
|
+
st.reading = true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if need_read
|
80
|
+
next_run(st, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
st.access
|
84
|
+
end
|
85
|
+
|
86
|
+
def req_write(rd, buf, adr, tag, lis)
|
87
|
+
st = get_rudder_state(rd)
|
88
|
+
BayLog.debug("%s reqWrite st=%s", @agent, st)
|
89
|
+
|
90
|
+
if st == nil || st.closed
|
91
|
+
BayLog.warn("%s Channel is closed: %s", @agent, rd)
|
92
|
+
return
|
93
|
+
end
|
94
|
+
|
95
|
+
unt = WriteUnit.new(buf, adr, tag, lis)
|
96
|
+
st.writing_lock.synchronize do
|
97
|
+
st.write_queue << unt
|
98
|
+
end
|
99
|
+
|
100
|
+
need_write = false
|
101
|
+
st.writing_lock.synchronize do
|
102
|
+
if !st.writing
|
103
|
+
need_write = true
|
104
|
+
st.writing = true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if need_write
|
109
|
+
next_run(st, false)
|
110
|
+
end
|
111
|
+
|
112
|
+
st.access
|
113
|
+
end
|
114
|
+
|
115
|
+
def req_close(rd)
|
116
|
+
st = get_rudder_state(rd)
|
117
|
+
BayLog.debug("%s reqClose st=%s", @agent, st);
|
118
|
+
close_rudder(st)
|
119
|
+
st.access
|
120
|
+
end
|
121
|
+
|
122
|
+
def cancel_read(st)
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def cancel_write(st)
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
def next_accept(st)
|
131
|
+
raise Sink.new
|
132
|
+
end
|
133
|
+
|
134
|
+
def next_read(st)
|
135
|
+
next_run(st, true)
|
136
|
+
end
|
137
|
+
|
138
|
+
def next_write(st)
|
139
|
+
next_run(st, false)
|
140
|
+
end
|
141
|
+
|
142
|
+
def is_non_blocking()
|
143
|
+
return false
|
144
|
+
end
|
145
|
+
|
146
|
+
def use_async_api()
|
147
|
+
return false
|
148
|
+
end
|
149
|
+
|
150
|
+
def next_run(st, for_read)
|
151
|
+
BayLog.debug("%s Post next run: %s", self, st)
|
152
|
+
|
153
|
+
TaxiRunner.post(@agent.agent_id, TaxiForMpx.new(st, for_read))
|
154
|
+
end
|
155
|
+
|
156
|
+
def do_next_read(st)
|
157
|
+
st.access
|
158
|
+
begin
|
159
|
+
len = st.rudder.read(st.read_buf, st.buf_size)
|
160
|
+
if len <= 0
|
161
|
+
len = 0
|
162
|
+
end
|
163
|
+
@agent.send_read_letter(st, len, nil, nil, true)
|
164
|
+
|
165
|
+
rescue Exception => e
|
166
|
+
@agent.send_read_letter(st, -1, nil, e, true)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def do_next_write(st)
|
171
|
+
st.access
|
172
|
+
begin
|
173
|
+
if st.write_queue.empty?
|
174
|
+
raise Sink("%s write queue is empty", self)
|
175
|
+
end
|
176
|
+
|
177
|
+
u = st.write_queue[0]
|
178
|
+
if u.buf.length == 0
|
179
|
+
len = 0
|
180
|
+
else
|
181
|
+
len = st.rudder.write(u.buf)
|
182
|
+
u.buf.slice!(0, len)
|
183
|
+
end
|
184
|
+
@agent.send_wrote_letter(st, len, nil, true)
|
185
|
+
|
186
|
+
rescue Exception => e
|
187
|
+
@agent.send_wrote_letter(st, -1, e, true)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'baykit/bayserver/util/reusable'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Agent
|
6
|
+
module Multiplexer
|
7
|
+
module Transporter # interface
|
8
|
+
include Baykit::BayServer::Util::Reusable # implements
|
9
|
+
|
10
|
+
def init()
|
11
|
+
raise NotImplementedError.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_connect(rd)
|
15
|
+
raise NotImplementedError.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_read(rd, data, adr)
|
19
|
+
raise NotImplementedError.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_error(rd, e)
|
23
|
+
raise NotImplementedError.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_closed(rd)
|
27
|
+
raise NotImplementedError.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def req_connect(rd, adr)
|
31
|
+
raise NotImplementedError.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def req_read(rd)
|
35
|
+
raise NotImplementedError.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def req_write(rd, buf, adr, tag, &lis)
|
39
|
+
raise NotImplementedError.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def req_close(rd)
|
43
|
+
raise NotImplementedError.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_timeout(rd, duretion_sec)
|
47
|
+
raise NotImplementedError.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_read_buffer_size
|
51
|
+
raise NotImplementedError.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def print_usage(indent)
|
55
|
+
raise NotImplementedError.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'baykit/bayserver/util/reusable'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Agent
|
6
|
+
module Multiplexer
|
7
|
+
class WriteUnit
|
8
|
+
|
9
|
+
attr :buf
|
10
|
+
attr :adr
|
11
|
+
attr :tag
|
12
|
+
attr :listener
|
13
|
+
|
14
|
+
def initialize(buf, adr, tag, lis)
|
15
|
+
@buf = buf
|
16
|
+
@adr = adr
|
17
|
+
@tag = tag
|
18
|
+
@listener = lis
|
19
|
+
end
|
20
|
+
|
21
|
+
def done()
|
22
|
+
if @listener != nil
|
23
|
+
@listener.call()
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|