bayserver-core 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
  3. data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
  4. data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
  5. data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
  6. data/lib/baykit/bayserver/agent/letter.rb +30 -0
  7. data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
  8. data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
  9. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
  10. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
  11. data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
  12. data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
  13. data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
  14. data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
  15. data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
  16. data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
  17. data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
  18. data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
  19. data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
  20. data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
  21. data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
  22. data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
  23. data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
  24. data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
  25. data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
  26. data/lib/baykit/bayserver/bay_log.rb +1 -0
  27. data/lib/baykit/bayserver/bayserver.rb +32 -28
  28. data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
  29. data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
  30. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
  31. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
  32. data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
  33. data/lib/baykit/bayserver/common/postpone.rb +15 -0
  34. data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
  35. data/lib/baykit/bayserver/common/recipient.rb +24 -0
  36. data/lib/baykit/bayserver/common/vehicle.rb +24 -0
  37. data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
  38. data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
  39. data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
  40. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
  41. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
  42. data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
  43. data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
  44. data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
  45. data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
  46. data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
  47. data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
  48. data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
  49. data/lib/baykit/bayserver/docker/city.rb +27 -13
  50. data/lib/baykit/bayserver/docker/club.rb +8 -8
  51. data/lib/baykit/bayserver/docker/docker.rb +9 -1
  52. data/lib/baykit/bayserver/docker/harbor.rb +184 -22
  53. data/lib/baykit/bayserver/docker/permission.rb +7 -6
  54. data/lib/baykit/bayserver/docker/port.rb +39 -11
  55. data/lib/baykit/bayserver/docker/secure.rb +11 -9
  56. data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
  57. data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
  58. data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
  59. data/lib/baykit/bayserver/docker/town.rb +31 -15
  60. data/lib/baykit/bayserver/docker/trouble.rb +17 -5
  61. data/lib/baykit/bayserver/docker/warp.rb +34 -0
  62. data/lib/baykit/bayserver/mem_usage.rb +9 -9
  63. data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
  64. data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
  65. data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
  66. data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
  67. data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
  68. data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
  69. data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
  70. data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
  71. data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
  72. data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
  73. data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
  74. data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
  75. data/lib/baykit/bayserver/tours/tour.rb +2 -2
  76. data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
  77. data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
  78. data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
  79. data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
  80. data/lib/baykit/bayserver/train/train_runner.rb +17 -13
  81. data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
  82. data/lib/baykit/bayserver/util/executor_service.rb +11 -7
  83. data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
  84. data/lib/baykit/bayserver/util/locale.rb +1 -1
  85. data/lib/baykit/bayserver/util/selector.rb +24 -5
  86. data/lib/baykit/bayserver/util/sys_util.rb +6 -6
  87. data/lib/baykit/bayserver/version.rb +1 -1
  88. metadata +37 -18
  89. data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
  90. data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
  91. data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
  92. data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
  93. data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
  94. data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
  95. data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
  96. /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -15,63 +15,11 @@ module Baykit
15
15
  include Baykit::BayServer::Agent
16
16
  include Baykit::BayServer::Util
17
17
 
18
- class ChannelState
19
- attr_accessor :accepted
20
- attr :channel
21
- attr :listener
22
- attr_accessor :connecting
23
- attr_accessor :closing
24
-
25
- attr :last_access_time
26
-
27
- def initialize(ch, lis)
28
- @channel = ch
29
- @listener = lis
30
- @accepted = false
31
- @connecting = false
32
- @closing = false
33
- end
34
-
35
- def access
36
- @last_access_time = DateTime.now
37
- end
38
-
39
- def to_s
40
- if @listener != nil
41
- str = @listener.to_s
42
- else
43
- str = super.to_s
44
- end
45
- if @closing
46
- str += " closing";
47
- end
48
- return str
49
- end
50
- end
51
-
52
- class ChannelOperation
53
-
54
- attr :ch
55
- attr_accessor :op
56
- attr_accessor :to_connect
57
- attr_accessor :to_close
58
-
59
-
60
- def initialize(ch, op, to_connect, to_close)
61
- @ch = ch
62
- @op = op
63
- @to_connect = to_connect
64
- @to_close = to_close
65
- end
66
18
 
67
19
 
68
- end
69
-
70
20
  attr :agent
71
21
  attr :ch_map
72
22
  attr :ch_count
73
- attr :operations
74
- attr :operations_lock
75
23
 
76
24
  def initialize(ship_agent)
77
25
  @agent = ship_agent
@@ -100,197 +48,9 @@ module Baykit
100
48
  # Custom methods
101
49
  ######################################################
102
50
 
103
- def handle_channel(ch, op)
104
-
105
- ch_state = find_channel_state(ch)
106
- if ch_state == nil
107
- BayLog.error("Cannot find fd state (Maybe file is closed)")
108
- @agent.selector.unregister(ch)
109
- return
110
- end
111
-
112
- next_action = nil
113
- begin
114
-
115
- if ch_state.closing
116
- next_action = NextSocketAction::CLOSE
117
-
118
- elsif ch_state.connecting
119
- ch_state.connecting = false
120
- # connectable
121
- next_action = ch_state.listener.on_connectable(ch)
122
- if next_action == nil
123
- raise Sink.new("unknown next action")
124
- elsif next_action == NextSocketAction::READ
125
- # "Write-OP Off"
126
- op = @agent.selector.get_op(ch)
127
- op = op & ~Selector::OP_WRITE
128
- if op == 0
129
- @agent.selector.unregister(ch)
130
- else
131
- @agent.selector.modify(ch, op)
132
- end
133
- end
134
-
135
- else
136
- if op & Selector::OP_READ != 0
137
- # readable
138
- next_action = ch_state.listener.on_readable(ch)
139
- if next_action == nil
140
- raise Sink.new("unknown next action")
141
- elsif next_action == NextSocketAction::WRITE
142
- op = @agent.selector.get_op(ch)
143
- op = op | Selector::OP_WRITE
144
- @agent.selector.modify(ch, op)
145
- end
146
- end
147
-
148
- if (next_action != NextSocketAction::CLOSE) && (op & Selector::OP_WRITE != 0)
149
- # writable
150
- next_action = ch_state.listener.on_writable(ch)
151
- if next_action == nil
152
- raise Sink.new("unknown next action")
153
- elsif next_action == NextSocketAction::READ
154
- # Handle as "Write Off"
155
- op = @agent.selector.get_op(ch)
156
- op = op & ~Selector::OP_WRITE
157
- if op == 0
158
- @agent.selector.unregister(ch)
159
- else
160
- @agent.selector.modify(ch, op)
161
- end
162
- end
163
- end
164
- end
165
-
166
-
167
- if next_action == nil
168
- raise Sink.new("unknown next action")
169
- end
170
-
171
- rescue Sink => e
172
- raise e
173
-
174
- rescue => e
175
- if e.kind_of? EOFError
176
- BayLog.debug("%s Socket closed by peer: skt=%s", @agent, ch.inspect)
177
- elsif e.kind_of? SystemCallError
178
- BayLog.debug("%s O/S error: %s (skt=%s)", @agent, e.message, ch.inspect)
179
- elsif e.kind_of? IOError
180
- BayLog.debug("%s IO error: %s (skt=%s)", @agent, e.message, ch.inspect)
181
- elsif e.kind_of? OpenSSL::SSL::SSLError
182
- BayLog.debug("%s SSL error: %s (skt=%s)", @agent, e.message, ch.inspect)
183
- else
184
- BayLog.error("%s Unhandled error error: %s (skt=%s)", @agent, e, ch.inspect)
185
- throw e
186
- end
187
- # Cannot handle Exception any more
188
- ch_state.listener.on_error(ch, e)
189
- next_action = NextSocketAction::CLOSE
190
- end
191
-
192
- cancel = false
193
- ch_state.access()
194
- BayLog.trace("%s next=%d", ch_state, next_action)
195
- case next_action
196
- when NextSocketAction::CLOSE
197
- close_channel(ch, ch_state)
198
- cancel = false # already canceled in close_channel method
199
-
200
- when NextSocketAction::SUSPEND
201
- cancel = true
202
-
203
- when NextSocketAction::CONTINUE, NextSocketAction::READ, NextSocketAction::WRITE
204
- # do nothing
205
-
206
- else
207
- raise RuntimeError.new("IllegalState:: #{next_action}")
208
- end
209
-
210
- if cancel
211
- BayLog.trace("%s cancel key chState=%s", @agent, ch_state)
212
- @agent.selector.unregister(ch)
213
- end
214
- end
215
-
216
- def register_channel_ops()
217
- if @operations.empty?
218
- return 0
219
- end
220
-
221
- @operations_lock.synchronize do
222
- nch = @operations.length
223
- @operations.each do |ch_op|
224
- st = self.find_channel_state(ch_op.ch)
225
- if ch_op.ch.closed?
226
- # Channel is closed before register operation
227
- BayLog.debug("%s Try to register closed socket (Ignore)", @agent)
228
- next
229
- end
230
-
231
- begin
232
- BayLog.trace("%s register op=%s chState=%s", @agent, self.class.op_mode(ch_op.op), st)
233
- op = @agent.selector.get_op(ch_op.ch)
234
- if op == nil
235
- @agent.selector.register(ch_op.ch, ch_op.op)
236
- else
237
- new_op = op | ch_op.op
238
- BayLog.debug("%s Already registered ch=%s op=%s update to %s", @agent, ch_op.ch, self.class.op_mode(op), self.class.op_mode(new_op))
239
- @agent.selector.modify(ch_op.ch, new_op)
240
- end
241
-
242
- if ch_op.to_connect
243
- if st == nil
244
- BayLog.warn("%s register connect but ChannelState is null", @agent);
245
- else
246
- st.connecting = true
247
- end
248
-
249
- elsif ch_op.to_close
250
- if st == nil
251
- BayLog.warn("%s chState=%s register close but ChannelState", self.agent);
252
- else
253
- st.closing = true
254
- end
255
- end
256
-
257
- rescue => e
258
- cst = find_channel_state(ch_op.ch)
259
- BayLog.error_e(e, "%s Cannot register operation: %s", self.agent, cst != nil ? cst.listener : nil)
260
- end
261
- end
262
-
263
- @operations.clear()
264
- return nch
265
-
266
- end
267
- end
268
51
 
269
52
  def close_timeout_sockets()
270
- if @ch_map.empty?
271
- return
272
- end
273
53
 
274
- close_list = []
275
- now = DateTime.now
276
- @ch_map.values.each do |ch_state|
277
- if ch_state.listener != nil
278
- begin
279
- duration = ((now - ch_state.last_access_time) * 86400).to_i
280
- if ch_state.listener.check_timeout(ch_state.channel, duration)
281
- BayLog.debug("%s timeout: ch=%s", @agent, ch_state.channel)
282
- close_list << ch_state
283
- end
284
- rescue IOError => e
285
- BayLog.error_e(e)
286
- close_list << ch_state
287
- end
288
- end
289
- end
290
-
291
- close_list.each do |ch_state|
292
- close_channel ch_state.channel, ch_state
293
- end
294
54
  end
295
55
 
296
56
  def add_channel_listener(ch, lis)
@@ -309,66 +69,19 @@ module Baykit
309
69
  end
310
70
 
311
71
  def ask_to_connect(ch, addr)
312
- ch_state = find_channel_state(ch)
313
- BayLog.debug("%s askToConnect addr=%s skt=%s chState=%s", @agent, addr.ip_address, ch, ch_state)
314
72
 
315
- begin
316
- ch.connect_nonblock(addr)
317
- rescue IO::WaitWritable => e
318
- #BayLog.error_e(e)
319
- end
320
-
321
- ch_state.connecting = true
322
- add_operation(ch, Selector::OP_WRITE, true)
323
73
  end
324
74
 
325
75
  def ask_to_read(ch)
326
- ch_state = find_channel_state(ch)
327
- BayLog.debug("%s askToRead chState=%s", @agent, ch_state);
328
-
329
- if ch.closed?
330
- raise IOError.new("Channel is closed")
331
- end
332
-
333
- add_operation(ch, Selector::OP_READ)
334
76
 
335
- if ch_state != nil
336
- ch_state.access()
337
- end
338
77
  end
339
78
 
340
79
  def ask_to_write(ch)
341
- ch_state = find_channel_state(ch)
342
- BayLog.debug("%s askToWrite chState=%s", @agent, ch_state);
343
80
 
344
- if ch.closed?
345
- BayLog.warn("%s Channel is closed: %s", @agent, ch)
346
- return
347
- end
348
-
349
- add_operation(ch, Selector::OP_WRITE)
350
-
351
- if ch_state == nil
352
- BayLog.error("Unknown socket (or closed)")
353
- return
354
- end
355
-
356
- ch_state.access()
357
81
  end
358
82
 
359
83
  def ask_to_close(ch)
360
- ch_state = find_channel_state(ch)
361
- BayLog.debug("%s askToClose chState=%s", @agent, ch_state);
362
84
 
363
- if ch_state == nil
364
- BayLog.warn("%s channel state not found: %s", @agent, ch)
365
- return
366
- end
367
-
368
- ch_state.closing = true
369
- add_operation(ch, Selector::OP_WRITE, false, true)
370
-
371
- ch_state.access
372
85
  end
373
86
 
374
87
  def close_all()
@@ -381,27 +94,7 @@ module Baykit
381
94
 
382
95
  private
383
96
 
384
- def add_operation(ch, op, to_connect=false, to_close=false)
385
- @operations_lock.synchronize do
386
- found = false
387
- @operations.each do |ch_op|
388
- if ch_op.ch == ch
389
- ch_op.op |= op
390
- ch_op.to_close = (ch_op.to_close or to_close)
391
- ch_op.to_connect = (ch_op.to_connect or to_connect)
392
- found = true
393
- BayLog.trace("%s Update operation: %s con=%s close=%s ch=%s", @agent, self.class.op_mode(ch_op.op), ch_op.to_connect, ch_op.to_close, ch_op.ch.inspect())
394
- end
395
- end
396
-
397
- if not found
398
- BayLog.trace("%s New operation: %s con=%s close=%s ch=%s", @agent, self.class.op_mode(op), to_connect, to_close, ch.inspect());
399
- @operations << ChannelOperation.new(ch, op, to_connect, to_close)
400
- end
401
- end
402
97
 
403
- @agent.wakeup
404
- end
405
98
 
406
99
  def close_channel(ch, ch_state)
407
100
  BayLog.debug("%s Close chState=%s", @agent, ch_state)
@@ -449,19 +142,7 @@ module Baykit
449
142
  end
450
143
 
451
144
  def NonBlockingHandler.op_mode(mode)
452
- mode_str = ""
453
- if (mode & Selector::OP_READ) != 0
454
- mode_str = "OP_READ"
455
- end
456
-
457
- if (mode & Selector::OP_WRITE) != 0
458
- if mode_str != ""
459
- mode_str += "|"
460
- end
461
- mode_str += "OP_WRITE"
462
- end
463
145
 
464
- return mode_str
465
146
  end
466
147
  end
467
148
  end
@@ -1,7 +1,7 @@
1
1
  require 'baykit/bayserver/mem_usage'
2
2
  require 'baykit/bayserver/bcf/package'
3
3
 
4
- require 'baykit/bayserver/agent/grand_agent_monitor'
4
+ require 'baykit/bayserver/agent/monitor/grand_agent_monitor'
5
5
  require 'baykit/bayserver/agent/signal/signal_proxy'
6
6
  require 'baykit/bayserver/util/sys_util'
7
7
 
@@ -14,6 +14,7 @@ module Baykit
14
14
  include Baykit::BayServer::Bcf
15
15
  include Baykit::BayServer::Util
16
16
  include Baykit::BayServer::Agent
17
+ include Baykit::BayServer::Agent::Monitor
17
18
  include Baykit::BayServer::Agent::Signal
18
19
 
19
20
  COMMAND_RELOAD_CERT = "reloadcert"
@@ -5,7 +5,7 @@ module Baykit
5
5
  module TimerHandler # interface
6
6
 
7
7
  def on_timer()
8
- raise NotImplementedError()
8
+ raise NotImplementedError.new
9
9
  end
10
10
 
11
11
  end
@@ -5,31 +5,31 @@ module Baykit
5
5
  module DataListener # interface
6
6
 
7
7
  def notify_connect()
8
- raise NotImplementedError()
8
+ raise NotImplementedError.new
9
9
  end
10
10
 
11
11
  def notify_handshake_done(protocol)
12
- raise NotImplementedError()
12
+ raise NotImplementedError.new
13
13
  end
14
14
 
15
15
  def notify_read(buf)
16
- raise NotImplementedError()
16
+ raise NotImplementedError.new
17
17
  end
18
18
 
19
19
  def notify_eof()
20
- raise NotImplementedError()
20
+ raise NotImplementedError.new
21
21
  end
22
22
 
23
23
  def notify_protocol_error(err)
24
- raise NotImplementedError()
24
+ raise NotImplementedError.new
25
25
  end
26
26
 
27
27
  def notify_close()
28
- raise NotImplementedError()
28
+ raise NotImplementedError.new
29
29
  end
30
30
 
31
31
  def check_timeout(duration_sec)
32
- raise NotImplementedError()
32
+ raise NotImplementedError.new
33
33
  end
34
34
  end
35
35
  end
@@ -1,3 +0,0 @@
1
- require 'baykit/bayserver/agent/transporter/plain_transporter'
2
- require 'baykit/bayserver/agent/transporter/secure_transporter'
3
- require 'baykit/bayserver/agent/transporter/transporter'
@@ -16,53 +16,22 @@ module Baykit
16
16
  include Baykit::BayServer::Protocol
17
17
  include Baykit::BayServer::Util
18
18
 
19
- class WriteUnit
20
- attr :buf
21
- attr :adr
22
- attr :tag
23
- attr :listener
24
-
25
- def initialize(buf, adr, tag, lis)
26
- @buf = buf
27
- @adr = adr
28
- @tag = tag
29
- @listener = lis
30
- end
31
-
32
- def done()
33
- if @listener != nil
34
- @listener.call()
35
- end
36
- end
37
- end
38
-
39
19
  #
40
20
  # Abstract methods
41
21
  #
42
22
  def secure()
43
- raise NotImplementedError()
23
+ raise NotImplementedError.new
44
24
  end
45
25
 
46
26
  def handshake_nonblock()
47
- raise NotImplementedError()
27
+ raise NotImplementedError.new
48
28
  end
49
29
 
50
30
  def handshake_finished()
51
- raise NotImplementedError()
52
- end
53
-
54
- def read_nonblock()
55
- raise NotImplementedError()
31
+ raise NotImplementedError.new
56
32
  end
57
33
 
58
- def write_nonblock(buf, adr)
59
- raise NotImplementedError()
60
- end
61
-
62
-
63
34
  attr :data_listener
64
- attr :server_mode
65
- attr :trace_ssl
66
35
  attr :infile
67
36
  attr :write_queue
68
37
  attr :finale
@@ -79,7 +48,7 @@ module Baykit
79
48
  def initialize(server_mode, bufsiz, trace_ssl, write_only = false)
80
49
  @server_mode = server_mode
81
50
  @write_queue = []
82
- @lock = Monitor.new()
51
+ @lock = ::Monitor.new()
83
52
  @capacity = bufsiz
84
53
  @read_buf = StringUtil.alloc(bufsiz)
85
54
  @trace_ssl = trace_ssl
@@ -91,31 +60,6 @@ module Baykit
91
60
  return "tpt[#{@data_listener.to_s}]"
92
61
  end
93
62
 
94
- def init(nb_hnd, ch, lis)
95
- if ch == nil
96
- raise ArgumentError.new("Channel is nil")
97
- end
98
- if lis == nil
99
- raise ArgumentError.new("Data listener is nil")
100
- end
101
-
102
- if @initialized
103
- BayLog.error("%s This transporter is already in use by channel: %s", self, @ch)
104
- raise Sink.new("IllegalState")
105
- end
106
-
107
- if !@write_queue.empty?
108
- raise Sink.new()
109
- end
110
-
111
- @channel_handler = nb_hnd
112
- @data_listener = lis
113
- @ch = ch
114
- @initialized = true
115
- set_valid(true)
116
- @handshaked = false
117
- @channel_handler.add_channel_listener(ch, self)
118
- end
119
63
 
120
64
  ######################################################
121
65
  # Implements Reusable
@@ -146,19 +90,7 @@ module Baykit
146
90
 
147
91
  BayLog.debug("%s post: %s len=%d", self, tag, buf.length)
148
92
 
149
- @lock.synchronize do
150
-
151
- if !@ch_valid
152
- raise IOError.new("#{self} channel is invalid, Ignore")
153
- else
154
- unt = WriteUnit.new(buf, adr, tag, lisnr)
155
- @write_queue << unt
156
-
157
- BayLog.trace("%s sendBytes->askToWrite", self)
158
- @channel_handler.ask_to_write(@ch)
159
- end
160
93
 
161
- end
162
94
  end
163
95
 
164
96
  ######################################################
@@ -186,71 +118,6 @@ module Baykit
186
118
 
187
119
  def on_readable(chk_ch)
188
120
  check_channel(chk_ch)
189
- BayLog.trace("%s on_readable", self)
190
-
191
- if !@handshaked
192
- begin
193
- handshake_nonblock()
194
- @handshaked = true
195
- rescue IO::WaitReadable => e
196
- BayLog.debug("%s Handshake status: read more", @data_listener)
197
- return NextSocketAction::CONTINUE
198
- rescue IO::WaitWritable => e
199
- BayLog.debug("%s Handshake status: write more", @data_listener)
200
- @channel_handler.ask_to_write(@ch)
201
- return NextSocketAction::CONTINUE
202
- end
203
- end
204
-
205
- # read data
206
- # If closed, EOFError is raised
207
- if @read_buf.length == 0
208
- eof = false
209
- begin
210
- adr = read_nonblock()
211
- rescue IO::WaitReadable => e
212
- BayLog.debug("%s Read status: read more", self)
213
- return NextSocketAction::CONTINUE
214
- rescue IO::WaitWritable => e
215
- BayLog.debug("%s Read status: write more", self)
216
- @channel_handler.ask_to_write(@ch)
217
- return NextSocketAction::CONTINUE
218
- rescue EOFError => e
219
- BayLog.debug("%s EOF", self)
220
- eof = true
221
- rescue SystemCallError => e
222
- BayLog.debug_e(e, "SystemCall Error")
223
- eof = true
224
- end
225
-
226
- if eof
227
- return @data_listener.notify_eof()
228
- end
229
- end
230
-
231
- BayLog.debug("%s read %d bytes", self, @read_buf.length)
232
-
233
- begin
234
- begin
235
- next_action = @data_listener.notify_read(@read_buf, adr)
236
- BayLog.trace("%s returned from notify_read(). next action=%d", @ship, next_action)
237
- return next_action
238
- rescue UpgradeException => e
239
- BayLog.debug("%s Protocol upgrade", @ship)
240
- return @data_listener.notify_read(@read_buf, adr)
241
- ensure
242
- @read_buf.clear()
243
- end
244
-
245
-
246
- rescue ProtocolException => e
247
- close = @data_listener.notify_protocol_error(e)
248
- if !close && @server_mode
249
- return NextSocketAction::CONTINUE
250
- else
251
- return NextSocketAction::CLOSE
252
- end
253
- end
254
121
  end
255
122
 
256
123
  def on_writable(chk_ch)
@@ -397,9 +264,8 @@ module Baykit
397
264
  write_unit.done()
398
265
  end
399
266
  @write_queue.clear()
400
-
401
- @data_listener.notify_close()
402
267
  end
268
+ @data_listener.notify_close()
403
269
  end
404
270
 
405
271
  def flush()
@@ -16,6 +16,7 @@ module Baykit
16
16
  # class instance variables
17
17
  class << self
18
18
  attr :log_level
19
+ attr :full_path
19
20
  end
20
21
  @log_level = LOG_LEVEL_INFO
21
22
  @full_path = SysUtil.run_on_rubymine()