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
@@ -1,15 +1,11 @@
1
+ require 'baykit/bayserver/common/vehicle'
1
2
  require 'baykit/bayserver/util/counter'
3
+
2
4
  module Baykit
3
5
  module BayServer
4
6
  module Taxi
5
- class Taxi
7
+ class Taxi < Baykit::BayServer::Common::Vehicle
6
8
  include Baykit::BayServer::Util
7
- #
8
- # abstract method
9
- #
10
- # depart()
11
- # on_timer()
12
- #
13
9
 
14
10
  class << self
15
11
  attr :taxi_id_counter
@@ -27,11 +23,20 @@ module Baykit
27
23
  end
28
24
 
29
25
  def run()
30
- BayLog.trace("%s Start taxi on: %s", self, Thread.current.name);
31
- self.depart();
32
- BayLog.trace("%s End taxi on: %s", self, Thread.current.name);
26
+ BayLog.trace("%s Start taxi on: %s", self, Thread.current.name)
27
+ begin
28
+ self.depart
29
+ rescue => e
30
+ BayLog.error_e(e)
31
+ ensure
32
+ BayLog.trace("%s End taxi on: %s", self, Thread.current.name)
33
+ end
34
+
33
35
  end
34
36
 
37
+ def depart
38
+ NotImplementedError.new
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -1,119 +1,34 @@
1
1
  require 'baykit/bayserver/bayserver'
2
- require 'baykit/bayserver/agent/grand_agent'
3
- require 'baykit/bayserver/agent/lifecycle_listener'
4
- require 'baykit/bayserver/util/executor_service'
5
- require 'baykit/bayserver/sink'
2
+ require 'baykit/bayserver/common/vehicle_runner'
6
3
 
7
4
  module Baykit
8
5
  module BayServer
9
6
  module Taxi
10
7
  class TaxiRunner
11
8
  include Baykit::BayServer
12
- include Baykit::BayServer::Agent
13
- include Baykit::BayServer::Util
9
+ include Baykit::BayServer::Common
14
10
 
15
- class AgentListener
16
- include Baykit::BayServer::Agent::LifecycleListener # implements
17
11
 
18
- def add(agt)
19
- TaxiRunner.runners[agt.agent_id - 1] = TaxiRunner.new(agt)
20
- end
21
-
22
- def remove(agt)
23
- BayLog.debug("%s Remove tax runner", agt)
24
- TaxiRunner.runners[agt.agent_id - 1].terminate()
25
- TaxiRunner.runners[agt.agent_id - 1] = nil
26
- end
27
- end
28
-
29
-
30
- # define class instance accessor
31
12
  class << self
32
- attr :max_taxis
33
- attr :runners
34
- end
35
-
36
- attr :agent
37
- attr :exe
38
- attr :running_taxis
39
- attr :lock
40
-
41
- def initialize(agt)
42
- @agent = agt
43
- @exe = ExecutorService.new("TaxiRunner", TaxiRunner.max_taxis)
44
- @agent.add_timer_handler(self)
45
- @running_taxis = []
46
- @lock = Monitor.new()
47
- end
48
-
49
- ######################################################
50
- # Implements TimerHandler
51
- ######################################################
52
-
53
- def on_timer()
54
- @lock.synchronize do
55
- @running_taxis.each do |txi|
56
- txi.on_timer()
57
- end
58
- end
59
- end
60
-
61
- ######################################################
62
- # Custom methods
63
- ######################################################
64
-
65
- def terminate()
66
- @agent.remove_timer_handler(self)
67
- @exe.shutdown
13
+ attr :runner
68
14
  end
69
15
 
70
- def submit(txi)
71
- @exe.submit() do
72
- if @agent.aborted
73
- BayLog.error("Agent is aborted")
74
- return
75
- end
16
+ @runner = VehicleRunner.new
76
17
 
77
- @lock.synchronize do
78
- @running_taxis << txi
79
- end
80
-
81
- begin
82
- txi.run()
83
- rescue => e
84
- BayLog.fatal_e(e)
85
- @agent.req_shutdown
86
- ensure
87
- @lock.synchronize do
88
- @running_taxis.delete(txi)
89
- end
90
- end
91
- end
92
- end
93
18
 
94
19
  ######################################################
95
20
  # Class methods
96
21
  ######################################################
97
22
 
98
- def TaxiRunner.init(max_taxis)
99
- if(max_taxis <= 0)
100
- raise Sink.new()
101
- end
102
- @max_taxis = max_taxis
103
- @runners = []
104
- GrandAgent.add_lifecycle_listener(AgentListener.new())
23
+ def self.init(max_taxis)
24
+ @runner.init(max_taxis)
105
25
  end
106
26
 
107
- def TaxiRunner.post(agt_id, txi)
27
+ def self.post(agt_id, txi)
108
28
  BayLog.debug("agt#%d post taxi: thread=%s taxi=%s", agt_id, Thread.current.name, txi);
109
- begin
110
- @runners[agt_id - 1].submit(txi)
111
- return true
112
- rescue => e
113
- BayLog.error_e(e)
114
- return false
115
- end
29
+ @runner.post(agt_id, txi)
116
30
  end
31
+
117
32
  end
118
33
  end
119
34
  end
@@ -59,7 +59,7 @@ module Baykit
59
59
  ######################################################
60
60
 
61
61
  def depart()
62
- @start_time = Time.now.to_i
62
+ @start_time = Time.now.tv_sec
63
63
  begin
64
64
  @buf.clear()
65
65
  @infile.read(@buf_size, @buf)
@@ -86,7 +86,7 @@ module Baykit
86
86
  end
87
87
 
88
88
  def on_timer()
89
- duration_sec = Time.now.to_i - @start_time
89
+ duration_sec = Time.now.tv_sec - @start_time
90
90
  if (@data_listener.check_timeout(duration_sec))
91
91
  close()
92
92
  end
@@ -2,27 +2,30 @@ module Baykit
2
2
  module BayServer
3
3
  module Tours
4
4
 
5
- module ReqContentHandler
6
- #
7
- # interface
8
- #
9
- # void onReadContent(Tour tur, byte[] buf, int start, int len) throws IOException;
10
- # void onEndContent(Tour tur) throws IOException, HttpException;
11
- # void onAbort(Tour tur);
12
- #
13
-
14
- #DEV_NULL = nil
5
+ module ReqContentHandler # interface
6
+ def on_read_req_content(tur, buf, start, len)
7
+ raise NotImplementedError.new
8
+ end
9
+
10
+ def on_end_req_content(tur)
11
+ raise NotImplementedError.new
12
+ end
13
+
14
+ def on_abort_req(tur)
15
+ raise NotImplementedError.new
16
+ end
17
+
15
18
  end
16
19
 
17
20
  class DevNullReqContentHandler
18
21
  include ReqContentHandler # implements
19
- def on_read_content(tur, buf, start, len)
22
+ def on_read_req_content(tur, buf, start, len)
20
23
  end
21
24
 
22
- def on_end_content(tur)
25
+ def on_end_req_content(tur)
23
26
  end
24
27
 
25
- def on_abort(tur)
28
+ def on_abort_req(tur)
26
29
  return false
27
30
  end
28
31
  end
@@ -1,7 +1,7 @@
1
1
  require 'baykit/bayserver/bay_log'
2
2
  require 'baykit/bayserver/http_exception'
3
3
 
4
- require 'baykit/bayserver/watercraft/ship'
4
+ require 'baykit/bayserver/ships/ship'
5
5
  require 'baykit/bayserver/util/counter'
6
6
 
7
7
 
@@ -10,7 +10,7 @@ module Baykit
10
10
  module Tours
11
11
  class Tour
12
12
  include Baykit::BayServer
13
- include Baykit::BayServer::WaterCraft
13
+ include Baykit::BayServer::Ships
14
14
  include Baykit::BayServer::Util
15
15
  include Baykit::BayServer::Util::Reusable # implements
16
16
 
@@ -0,0 +1,36 @@
1
+ require 'baykit/bayserver/bay_log'
2
+ require 'baykit/bayserver/http_exception'
3
+
4
+ require 'baykit/bayserver/ships/ship'
5
+ require 'baykit/bayserver/util/counter'
6
+
7
+
8
+ module Baykit
9
+ module BayServer
10
+ module Tours
11
+ module TourHandler
12
+
13
+ # Send HTTP headers to client
14
+ def send_res_headers(tur)
15
+ raise NotImplementedError.new
16
+ end
17
+
18
+ # Send Contents to client
19
+ def send_res_content(tur, bytes, ofs, len, &lis)
20
+ raise NotImplementedError.new
21
+ end
22
+
23
+ # Send end of contents to client.
24
+ def send_end_tour(tur, keep_alive, &lis)
25
+ raise NotImplementedError.new
26
+ end
27
+
28
+ # Send protocol error to client
29
+ def on_protocol_error(e)
30
+ raise NotImplementedError.new
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -51,7 +51,6 @@ module Baykit
51
51
  attr :bytes_consumed
52
52
  attr :bytes_limit
53
53
 
54
- attr :consume_listener
55
54
  attr :available
56
55
  attr :ended
57
56
 
@@ -98,7 +97,6 @@ module Baykit
98
97
  @charset = nil
99
98
  @available = false
100
99
  @content_handler = nil
101
- @consume_listener = nil
102
100
  @ended = false
103
101
 
104
102
  end
@@ -107,22 +105,21 @@ module Baykit
107
105
  # other methods
108
106
  ######################################################
109
107
 
110
- def remote_host()
108
+ def remote_host
111
109
  return @remote_host_func.call()
112
110
  end
113
111
 
114
- def set_consume_listener(limit, &listener)
112
+ def set_limit(limit)
115
113
  if limit < 0
116
114
  raise Sink.new("invalid limit")
117
115
  end
118
116
  @bytes_limit = limit
119
- @consume_listener = listener
120
117
  @bytes_posted = 0
121
118
  @bytes_consumed = 0
122
119
  @available = true
123
120
  end
124
121
 
125
- def post_content(check_id, data, start, len)
122
+ def post_req_content(check_id, data, start, len, &callback)
126
123
  @tour.check_tour_id(check_id)
127
124
 
128
125
  data_passed = false
@@ -132,9 +129,6 @@ module Baykit
132
129
  elsif @content_handler == nil
133
130
  BayLog.warn("%s content read, but no content handler", tour)
134
131
 
135
- elsif @consume_listener == nil
136
- raise Sink.new("Request consume listener is null")
137
-
138
132
  elsif @bytes_posted + len > @bytes_limit
139
133
  raise ProtocolException.new("Read data exceed content-length: %d/%d", @bytes_posted + len, @bytes_limit)
140
134
 
@@ -143,7 +137,7 @@ module Baykit
143
137
  BayLog.debug("%s tour has error.", @tour)
144
138
 
145
139
  else
146
- @content_handler.on_read_content(@tour, data, start, len)
140
+ @content_handler.on_read_req_content(@tour, data, start, len, &callback)
147
141
  data_passed = true
148
142
  end
149
143
 
@@ -167,7 +161,7 @@ module Baykit
167
161
  return @available
168
162
  end
169
163
 
170
- def end_content(check_id)
164
+ def end_req_content(check_id)
171
165
  @tour.check_tour_id(check_id)
172
166
  if @ended
173
167
  raise Sink.new("#{@tour} Request content is already ended")
@@ -178,17 +172,13 @@ module Baykit
178
172
  end
179
173
 
180
174
  if @content_handler != nil
181
- @content_handler.on_end_content(@tour)
175
+ @content_handler.on_end_req_content(@tour)
182
176
  end
183
177
  @ended = true
184
178
  end
185
179
 
186
- def consumed(chk_id, length)
180
+ def consumed(chk_id, length, &callback)
187
181
  @tour.check_tour_id(chk_id)
188
- BayLog.debug("%s content_consumed: len=%d posted=%d", @tour, length, @bytes_posted)
189
- if @consume_listener == nil
190
- raise Sink.new("Request consume listener is null")
191
- end
192
182
 
193
183
  @bytes_consumed += length
194
184
  BayLog.debug("%s reqConsumed: len=%d posted=%d limit=%d consumed=%d",
@@ -204,24 +194,24 @@ module Baykit
204
194
  BayLog.debug("%s request available (^o^): posted=%d consumed=%d", self, @bytes_posted, @bytes_consumed);
205
195
  resume = true
206
196
  end
207
- @consume_listener.call(length, resume)
197
+ callback.call(length, resume)
208
198
  end
209
199
 
210
- def abort()
200
+ def abort
211
201
  BayLog.debug("%s abort", @tour)
212
202
  if @tour.preparing?
213
- @tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
203
+ #@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
214
204
  return true
215
205
 
216
206
  elsif @tour.running?
217
207
  aborted = true
218
208
  if @content_handler != nil
219
- aborted = @content_handler.on_abort(@tour)
209
+ aborted = @content_handler.on_abort_req(@tour)
220
210
  end
221
211
 
222
- if aborted
223
- @tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
224
- end
212
+ #if aborted
213
+ # @tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
214
+ #end
225
215
 
226
216
  return aborted
227
217
  else
@@ -1,6 +1,6 @@
1
1
  require 'baykit/bayserver/http_exception'
2
2
  require 'baykit/bayserver/protocol/protocol_exception'
3
- require 'baykit/bayserver/agent/transporter/plain_transporter'
3
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
4
4
  require 'baykit/bayserver/taxi/taxi_runner'
5
5
  require 'baykit/bayserver/docker/harbor'
6
6
  require 'baykit/bayserver/tours/send_file_yacht'
@@ -101,6 +101,7 @@ module Baykit
101
101
  end
102
102
 
103
103
  @bytes_limit = @headers.content_length()
104
+ BayLog.debug("%s send_headers content length: %s", self, @bytes_limit)
104
105
 
105
106
  # Compress check
106
107
  if BayServer.harbor.gzip_comp &&
@@ -161,7 +162,7 @@ module Baykit
161
162
  @available = true
162
163
  end
163
164
 
164
- def send_content(chk_tour_id, buf, ofs, len)
165
+ def send_res_content(chk_tour_id, buf, ofs, len)
165
166
  @tour.check_tour_id(chk_tour_id)
166
167
  BayLog.debug("%s sendContent len=%d", @tour, len)
167
168
 
@@ -223,7 +224,7 @@ module Baykit
223
224
  return @available
224
225
  end
225
226
 
226
- def end_content(chk_tour_id)
227
+ def end_res_content(chk_tour_id)
227
228
  @tour.check_tour_id(chk_tour_id)
228
229
 
229
230
  BayLog.debug("%s end ResContent", self)
@@ -345,92 +346,7 @@ module Baykit
345
346
  end
346
347
  end
347
348
 
348
- end_content(chk_tour_id)
349
- end
350
-
351
-
352
-
353
- def send_file(chk_tour_id, file, charset, async)
354
- @tour.check_tour_id(chk_tour_id)
355
-
356
- if @tour.zombie?
357
- return
358
- end
359
-
360
- if File.directory?(file)
361
- raise HttpException.new HttpStatus::FORBIDDEN, file
362
- elsif !File.exist?(file)
363
- raise HttpException.new HttpStatus::NOT_FOUND, file
364
- end
365
-
366
- mime_type = nil
367
-
368
- rname = File.basename(file)
369
- pos = rname.rindex('.')
370
- if pos
371
- ext = rname[pos + 1 .. -1].downcase
372
- mime_type = Mimes.type(ext)
373
- end
374
-
375
- if !mime_type
376
- mime_type = "application/octet-stream"
377
- end
378
-
379
- if mime_type.start_with?("text/") && charset != nil
380
- mime_type = mime_type + "; charset=" + charset
381
- end
382
-
383
- file_len = ::File.size(file)
384
- BayLog.debug("%s send_file %s async=%s len=%d", @tour, file, async, file_len)
385
-
386
- @headers.set_content_type(mime_type)
387
- @headers.set_content_length(file_len)
388
-
389
- begin
390
- send_headers(Tour::TOUR_ID_NOCHECK)
391
-
392
- if async
393
- bufsize = @tour.ship.protocol_handler.max_res_packet_data_size()
394
-
395
- case(BayServer.harbor.file_send_method())
396
-
397
- when Harbor::FILE_SEND_METHOD_SELECT
398
- tp = PlainTransporter.new(false, bufsize)
399
- @yacht.init(@tour, file, tp)
400
- tp.init(@tour.ship.agent.non_blocking_handler, File.open(file, "rb"), @yacht)
401
- @tour.ship.resume(@tour.ship_id)
402
- tp.open_valve()
403
-
404
- when Harbor::FILE_SEND_METHOD_SPIN
405
- timeout = 10
406
- tp = SpinReadTransporter.new(bufsize)
407
- @yacht.init(@tour, file, tp)
408
- tp.init(@tour.ship.agent.spin_handler, @yacht, File.open(file, "rb"), File.size(file), timeout, nil)
409
- @tour.ship.resume(@tour.ship_id)
410
- tp.open_valve()
411
-
412
- when Harbor::FILE_SEND_METHOD_TAXI
413
- txi = ReadFileTaxi.new(@tour.ship.agent.agent_id, bufsize)
414
- @yacht.init(@tour, file, txi)
415
- txi.init(File.open(file, "rb"), @yacht)
416
- if !TaxiRunner.post(@tour.ship.agent.agent_id, txi)
417
- raise HttpException.new(HttpStatus::SERVICE_UNAVAILABLE, "Taxi is busy!");
418
- end
419
-
420
- else
421
- raise Sink.new();
422
- end
423
-
424
- else
425
- SendFileTrain.new(@tour, file).run()
426
- end
427
- rescue HttpException => e
428
- raise e
429
- rescue => e
430
- BayLog.error_e(e)
431
- raise HttpException.new(HttpStatus::INTERNAL_SERVER_ERROR, file)
432
- end
433
-
349
+ end_res_content(chk_tour_id)
434
350
  end
435
351
 
436
352
  def get_compressor()
@@ -18,12 +18,12 @@ module Baykit
18
18
  class AgentListener
19
19
  include Baykit::BayServer::Agent::LifecycleListener # implements
20
20
 
21
- def add(agt)
22
- TourStore.stores[agt.agent_id] = TourStore.new();
21
+ def add(agt_id)
22
+ TourStore.stores[agt_id] = TourStore.new();
23
23
  end
24
24
 
25
- def remove(agt)
26
- TourStore.stores.delete(agt.agent_id);
25
+ def remove(agt_id)
26
+ TourStore.stores.delete(agt_id);
27
27
  end
28
28
  end
29
29
 
@@ -46,7 +46,7 @@ module Baykit
46
46
  def initialize()
47
47
  @free_tours = []
48
48
  @active_tour_map = {}
49
- @lock = Monitor.new
49
+ @lock = ::Monitor.new
50
50
  end
51
51
 
52
52
  def get(key)
@@ -5,26 +5,30 @@ module Baykit
5
5
  module BayServer
6
6
  module Train
7
7
  class TrainRunner
8
- include Baykit::BayServer::Util
8
+ include Baykit::BayServer
9
+ include Baykit::BayServer::Common
10
+
9
11
 
10
- # define class instance accessor
11
12
  class << self
12
- attr :exe
13
+ attr :runner
13
14
  end
14
15
 
15
- def self.init(num_agents)
16
- @exe = ExecutorService.new("TrainRunner", num_agents)
16
+ @runner = VehicleRunner.new
17
+
18
+
19
+ ######################################################
20
+ # Class methods
21
+ ######################################################
22
+
23
+ def self.init(max_trains)
24
+ @runner.init(max_trains)
17
25
  end
18
26
 
19
- def self.post(train)
20
- begin
21
- @exe.submit(train)
22
- return true
23
- rescue => e
24
- BayLog.error_e(e)
25
- return false
26
- end
27
+ def self.post(agt_id, train)
28
+ BayLog.debug("agt#%d post train: thread=%s train=%s", agt_id, Thread.current.name, train);
29
+ @runner.post(agt_id, train)
27
30
  end
31
+
28
32
  end
29
33
  end
30
34
  end
@@ -1,7 +1,7 @@
1
1
  module Baykit
2
2
  module BayServer
3
3
  module Util
4
- class DataConsumeListener
4
+ class DataConsumeListener # interface
5
5
  #
6
6
  # interface
7
7
  #
@@ -60,13 +60,17 @@ module Baykit
60
60
  count.times do |i|
61
61
  started = false
62
62
  Thread.new do
63
- started = true
64
- id = i + 1
65
- th_name = "Executor[#{name}]##{id}"
66
- Thread.current.name = th_name
67
- e = Executor.new @que, id, th_name
68
- e.run
69
- @executors << e
63
+ begin
64
+ started = true
65
+ id = i + 1
66
+ th_name = "Executor[#{name}]##{id}"
67
+ Thread.current.name = th_name
68
+ e = Executor.new @que, id, th_name
69
+ e.run
70
+ @executors << e
71
+ rescue => e
72
+ BayLog.error_e(e)
73
+ end
70
74
  end
71
75
  while !started
72
76
  sleep(0.01)