bayserver-core 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/baykit/bayserver/agent/command_receiver.rb +1 -1
- data/lib/baykit/bayserver/agent/grand_agent.rb +75 -75
- data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +35 -22
- data/lib/baykit/bayserver/docker/base/inbound_ship.rb +2 -0
- data/lib/baykit/bayserver/docker/base/port_base.rb +1 -1
- data/lib/baykit/bayserver/docker/built_in/write_file_taxi.rb +4 -0
- data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +9 -9
- data/lib/baykit/bayserver/taxi/taxi.rb +1 -0
- data/lib/baykit/bayserver/taxi/taxi_runner.rb +22 -6
- data/lib/baykit/bayserver/tours/read_file_taxi.rb +42 -21
- data/lib/baykit/bayserver/tours/send_file_yacht.rb +5 -1
- data/lib/baykit/bayserver/tours/tour.rb +0 -8
- data/lib/baykit/bayserver/tours/tour_req.rb +16 -15
- data/lib/baykit/bayserver/tours/tour_res.rb +10 -13
- data/lib/baykit/bayserver/util/executor_service.rb +27 -10
- data/lib/baykit/bayserver/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef1870c148ef4f045575bdd31e28b5e13808013fa159e0642a627471e0b80962
|
4
|
+
data.tar.gz: 0247c5d8b92f4c9f1cf95b20ae02687202d524c6edd82158711bce98fa5e8e6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3460ae4f7b5d50945fb20e5f6072838fe7277ccf6d6b9f0cd9d8e51e4ecd3c87a729121cc1d502edb8ddb120841e99377a63ba62324515a74de06d27fe769b6
|
7
|
+
data.tar.gz: 22d1f706b151704256cf55526e8b4bc6d29a04c2ab543c9803cb32316719239140997390d7b88b500e1d248cc8281821e68666ba68f2abdddd247880a2dbc698
|
@@ -37,7 +37,7 @@ module Baykit
|
|
37
37
|
when GrandAgent::CMD_MEM_USAGE
|
38
38
|
@agent.print_usage()
|
39
39
|
when GrandAgent::CMD_SHUTDOWN
|
40
|
-
@agent.
|
40
|
+
@agent.req_shutdown()
|
41
41
|
@aborted = true
|
42
42
|
when GrandAgent::CMD_ABORT
|
43
43
|
IOUtil.write_int32(@communication_channel, GrandAgent::CMD_OK)
|
@@ -125,112 +125,117 @@ module Baykit
|
|
125
125
|
busy = true
|
126
126
|
begin
|
127
127
|
while not @aborted
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
128
|
+
|
129
|
+
count = -1
|
130
|
+
|
131
|
+
if @accept_handler
|
132
|
+
test_busy = @accept_handler.ch_count >= @max_inbound_ships
|
133
|
+
if test_busy != busy
|
134
|
+
busy = test_busy
|
135
|
+
if busy
|
136
|
+
@accept_handler.on_busy()
|
137
|
+
else
|
138
|
+
@accept_handler.on_free()
|
140
139
|
end
|
141
140
|
end
|
141
|
+
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
if !busy && @selector.count() == 2
|
144
|
+
# agent finished
|
145
|
+
BayLog.debug("%s Selector has no key", self)
|
146
|
+
break
|
147
|
+
end
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
149
|
+
if !@spin_handler.empty?
|
150
|
+
timeout = 0
|
151
|
+
else
|
152
|
+
timeout = @select_timeout_sec
|
153
|
+
end
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
if @aborted
|
156
|
+
BayLog.info("%s aborted by another thread", self)
|
157
|
+
break
|
158
|
+
end
|
159
|
+
#@BayServer.debug("Selecting... read=" + read_list.to_s)
|
160
|
+
selected_map = @selector.select(timeout)
|
161
|
+
#BayLog.debug("%s selected: %s", self, selected_map)
|
158
162
|
|
159
|
-
|
163
|
+
processed = @non_blocking_handler.register_channel_ops() > 0
|
160
164
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
+
if @aborted
|
166
|
+
BayLog.info("%s aborted by another thread", self)
|
167
|
+
break
|
168
|
+
end
|
165
169
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
elsif ch == @command_receiver.communication_channel
|
171
|
-
@command_receiver.on_pipe_readable()
|
172
|
-
elsif @accept_handler && @accept_handler.server_socket?(ch)
|
173
|
-
@accept_handler.on_acceptable(ch)
|
174
|
-
else
|
175
|
-
@non_blocking_handler.handle_channel(ch, selected_map[ch])
|
176
|
-
end
|
177
|
-
processed = true
|
178
|
-
end
|
170
|
+
if selected_map.length == 0
|
171
|
+
# No channel is selected
|
172
|
+
processed |= @spin_handler.process_data()
|
173
|
+
end
|
179
174
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
175
|
+
selected_map.keys().each do |ch|
|
176
|
+
if ch == @select_wakeup_pipe[0]
|
177
|
+
# Waked up by ask_to_*
|
178
|
+
on_waked_up(ch)
|
179
|
+
elsif ch == @command_receiver.communication_channel
|
180
|
+
@command_receiver.on_pipe_readable()
|
181
|
+
elsif @accept_handler && @accept_handler.server_socket?(ch)
|
182
|
+
@accept_handler.on_acceptable(ch)
|
183
|
+
else
|
184
|
+
@non_blocking_handler.handle_channel(ch, selected_map[ch])
|
185
185
|
end
|
186
|
+
processed = true
|
187
|
+
end
|
186
188
|
|
187
|
-
|
188
|
-
|
189
|
+
if not processed
|
190
|
+
# timeout check
|
191
|
+
@timer_handlers.each do |h|
|
192
|
+
h.on_timer()
|
193
|
+
end
|
189
194
|
end
|
195
|
+
|
190
196
|
end # while
|
191
197
|
|
192
198
|
rescue => e
|
193
|
-
BayLog.
|
194
|
-
raise e
|
199
|
+
BayLog.fatal_e(e)
|
195
200
|
ensure
|
196
201
|
BayLog.info("%s end", self)
|
197
|
-
|
202
|
+
shutdown()
|
198
203
|
end
|
199
204
|
end
|
200
205
|
|
201
206
|
def shutdown()
|
207
|
+
BayLog.info("%s shutdown", self)
|
208
|
+
|
202
209
|
if @accept_handler != nil
|
203
210
|
@accept_handler.shutdown()
|
204
211
|
end
|
205
|
-
@aborted = true
|
206
|
-
wakeup()
|
207
|
-
end
|
208
|
-
|
209
|
-
def abort_agent(err = nil, status = 1)
|
210
|
-
BayLog.info("%s abort aborted=%s", self, @aborted)
|
211
|
-
if @aborted
|
212
|
-
return
|
213
|
-
end
|
214
|
-
|
215
|
-
if err
|
216
|
-
BayLog.fatal("%s abort", self)
|
217
|
-
BayLog.fatal_e(err)
|
218
|
-
end
|
219
212
|
|
220
213
|
@command_receiver.end()
|
214
|
+
@non_blocking_handler.close_all()
|
215
|
+
|
221
216
|
GrandAgent.listeners.each do |lis|
|
222
217
|
lis.remove(self)
|
223
218
|
end
|
224
219
|
|
225
220
|
GrandAgent.agents.delete(@agent_id)
|
226
221
|
|
227
|
-
@
|
222
|
+
@agent_id = -1
|
223
|
+
if BayServer.harbor.multi_core
|
224
|
+
exit(1)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def abort_agent()
|
229
|
+
BayLog.info("%s abort", self)
|
230
|
+
|
228
231
|
if BayServer.harbor.multi_core
|
229
232
|
exit(1)
|
230
|
-
else
|
231
|
-
clean()
|
232
233
|
end
|
234
|
+
end
|
233
235
|
|
236
|
+
def req_shutdown()
|
237
|
+
@aborted = true
|
238
|
+
wakeup()
|
234
239
|
end
|
235
240
|
|
236
241
|
def reload_cert()
|
@@ -281,11 +286,6 @@ module Baykit
|
|
281
286
|
val = IOUtil.read_int32(pipe_fd)
|
282
287
|
end
|
283
288
|
|
284
|
-
def clean()
|
285
|
-
@non_blocking_handler.close_all()
|
286
|
-
@agent_id = -1
|
287
|
-
end
|
288
|
-
|
289
289
|
######################################################
|
290
290
|
# class methods
|
291
291
|
######################################################
|
@@ -25,11 +25,13 @@ module Baykit
|
|
25
25
|
attr :agent_id
|
26
26
|
attr :anchorable
|
27
27
|
attr :communication_channel
|
28
|
+
attr :child_pid
|
28
29
|
|
29
|
-
def initialize(agt_id, anchorable, com_channel)
|
30
|
+
def initialize(agt_id, anchorable, com_channel, child_pid)
|
30
31
|
@agent_id = agt_id
|
31
32
|
@anchorable = anchorable
|
32
33
|
@communication_channel = com_channel
|
34
|
+
@child_pid = child_pid
|
33
35
|
end
|
34
36
|
|
35
37
|
def to_s()
|
@@ -42,7 +44,7 @@ module Baykit
|
|
42
44
|
if res == nil || res == GrandAgent::CMD_CLOSE
|
43
45
|
BayLog.debug("%s read Close", self)
|
44
46
|
close()
|
45
|
-
|
47
|
+
agent_aborted()
|
46
48
|
else
|
47
49
|
BayLog.debug("%s read OK: %d", self, res)
|
48
50
|
end
|
@@ -81,6 +83,33 @@ module Baykit
|
|
81
83
|
@communication_channel.close()
|
82
84
|
end
|
83
85
|
|
86
|
+
def agent_aborted()
|
87
|
+
BayLog.info(BayMessage.get(:MSG_GRAND_AGENT_SHUTDOWN, @agent_id))
|
88
|
+
|
89
|
+
if @child_pid != nil
|
90
|
+
begin
|
91
|
+
Process.kill("TERM", @child_pid)
|
92
|
+
rescue => e
|
93
|
+
BayLog.debug_e(e, "Error on killing process")
|
94
|
+
end
|
95
|
+
Process.wait(@child_pid)
|
96
|
+
end
|
97
|
+
GrandAgentMonitor.monitors.delete(@agent_id)
|
98
|
+
|
99
|
+
if not GrandAgentMonitor.finale
|
100
|
+
if GrandAgentMonitor.monitors.length < GrandAgentMonitor.num_agents
|
101
|
+
begin
|
102
|
+
if !BayServer.harbor.multi_core
|
103
|
+
GrandAgent.add(-1, @anchorable)
|
104
|
+
end
|
105
|
+
GrandAgentMonitor.add(@anchorable)
|
106
|
+
rescue => e
|
107
|
+
BayLog.error_e(e)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
84
113
|
########################################
|
85
114
|
# Class methods
|
86
115
|
########################################
|
@@ -151,32 +180,16 @@ module Baykit
|
|
151
180
|
agt.run()
|
152
181
|
end
|
153
182
|
|
183
|
+
child = nil
|
184
|
+
|
154
185
|
end
|
155
186
|
|
156
187
|
@monitors[agt_id] =
|
157
188
|
GrandAgentMonitor.new(
|
158
189
|
agt_id,
|
159
190
|
anchoroable,
|
160
|
-
client_socket
|
161
|
-
|
162
|
-
|
163
|
-
def self.agent_aborted(agt_id, anchorable)
|
164
|
-
BayLog.info(BayMessage.get(:MSG_GRAND_AGENT_SHUTDOWN, agt_id))
|
165
|
-
|
166
|
-
@monitors.delete(agt_id)
|
167
|
-
|
168
|
-
if not @finale
|
169
|
-
if @monitors.length < @num_agents
|
170
|
-
begin
|
171
|
-
if !BayServer.harbor.multi_core
|
172
|
-
GrandAgent.add(-1, anchorable)
|
173
|
-
end
|
174
|
-
add(anchorable)
|
175
|
-
rescue => e
|
176
|
-
BayLog.error_e(e)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
191
|
+
client_socket,
|
192
|
+
child)
|
180
193
|
end
|
181
194
|
|
182
195
|
def self.reload_cert_all()
|
@@ -203,7 +203,7 @@ module Baykit
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def return_protocol_handler(agt, proto_hnd)
|
206
|
-
BayLog.debug("%s Return protocol handler
|
206
|
+
BayLog.debug("%s Return protocol handler", proto_hnd)
|
207
207
|
PortBase.get_protocol_handler_store(proto_hnd.protocol, agt).Return(proto_hnd)
|
208
208
|
end
|
209
209
|
|
@@ -66,17 +66,17 @@ module Baykit
|
|
66
66
|
tur = pair[1]
|
67
67
|
tur.check_tour_id pair[0]
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
begin
|
70
|
+
if !tur.res.header_sent
|
71
|
+
BayLog.debug("%s Send ServiceUnavailable: tur=%s", self, tur)
|
72
|
+
tur.res.send_error(Tour::TOUR_ID_NOCHECK, HttpStatus::SERVICE_UNAVAILABLE, "Server closed on reading headers")
|
73
|
+
else
|
74
|
+
# NOT treat EOF as Error
|
75
|
+
BayLog.debug("%s EOF is not an error: tur=%s", self, tur)
|
76
76
|
tur.res.end_content(Tour::TOUR_ID_NOCHECK)
|
77
|
-
rescue IOError => e
|
78
|
-
BayLog::debug_e(e, "%s end content error: tur=%s", self, tur);
|
79
77
|
end
|
78
|
+
rescue IOError => e
|
79
|
+
BayLog::debug_e(e)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -20,6 +20,7 @@ module Baykit
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def remove(agt)
|
23
|
+
BayLog.debug("%s Remove tax runner", agt)
|
23
24
|
TaxiRunner.runners[agt.agent_id - 1].terminate()
|
24
25
|
TaxiRunner.runners[agt.agent_id - 1] = nil
|
25
26
|
end
|
@@ -63,15 +64,30 @@ module Baykit
|
|
63
64
|
|
64
65
|
def terminate()
|
65
66
|
@agent.remove_timer_handler(self)
|
67
|
+
@exe.shutdown
|
66
68
|
end
|
67
69
|
|
68
70
|
def submit(txi)
|
69
|
-
@
|
70
|
-
@
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
@exe.submit() do
|
72
|
+
if @agent.aborted
|
73
|
+
BayLog.error("Agent is aborted")
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
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
|
75
91
|
end
|
76
92
|
end
|
77
93
|
|
@@ -24,6 +24,7 @@ module Baykit
|
|
24
24
|
attr :running
|
25
25
|
attr :lock
|
26
26
|
attr :agent_id
|
27
|
+
attr :start_time
|
27
28
|
|
28
29
|
def initialize(agt_id, buf_size)
|
29
30
|
super()
|
@@ -58,28 +59,36 @@ module Baykit
|
|
58
59
|
######################################################
|
59
60
|
|
60
61
|
def depart()
|
61
|
-
@
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if @buf.length == 0
|
67
|
-
@data_listener.notify_eof()
|
68
|
-
close()
|
69
|
-
return
|
70
|
-
end
|
62
|
+
@start_time = Time.now.to_i
|
63
|
+
begin
|
64
|
+
@buf.clear()
|
65
|
+
@infile.read(@buf_size, @buf)
|
71
66
|
|
72
|
-
|
67
|
+
if @buf.length == 0
|
68
|
+
close()
|
69
|
+
return
|
70
|
+
end
|
73
71
|
|
74
|
-
|
75
|
-
if act == NextSocketAction::CONTINUE
|
76
|
-
next_run()
|
77
|
-
end
|
72
|
+
act = @data_listener.notify_read(@buf, nil)
|
78
73
|
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
@running = false
|
75
|
+
if act == NextSocketAction::CONTINUE
|
76
|
+
next_run()
|
82
77
|
end
|
78
|
+
|
79
|
+
rescue IOError => e
|
80
|
+
BayLog.debug_e(e)
|
81
|
+
close()
|
82
|
+
rescue Exception => e
|
83
|
+
close()
|
84
|
+
raise e
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def on_timer()
|
89
|
+
duration_sec = Time.now.to_i - @start_time
|
90
|
+
if (@data_listener.check_timeout(duration_sec))
|
91
|
+
close()
|
83
92
|
end
|
84
93
|
end
|
85
94
|
|
@@ -94,9 +103,21 @@ module Baykit
|
|
94
103
|
end
|
95
104
|
|
96
105
|
def close()
|
97
|
-
@
|
98
|
-
|
99
|
-
|
106
|
+
@lock.synchronize do
|
107
|
+
if !@ch_valid
|
108
|
+
return
|
109
|
+
end
|
110
|
+
|
111
|
+
@ch_valid = false
|
112
|
+
@data_listener.notify_eof()
|
113
|
+
|
114
|
+
begin
|
115
|
+
@infile.close()
|
116
|
+
rescue IOError => e
|
117
|
+
end
|
118
|
+
|
119
|
+
@data_listener.notify_close()
|
120
|
+
end
|
100
121
|
end
|
101
122
|
end
|
102
123
|
end
|
@@ -57,7 +57,11 @@ module Baykit
|
|
57
57
|
|
58
58
|
def notify_eof()
|
59
59
|
BayLog.trace("%s EOF(^o^) %s", self, @file_name)
|
60
|
-
|
60
|
+
begin
|
61
|
+
@tour.res.end_content(@tour_id)
|
62
|
+
rescue IOError => e
|
63
|
+
BayLog.debug_e(e)
|
64
|
+
end
|
61
65
|
return NextSocketAction::CLOSE
|
62
66
|
end
|
63
67
|
|
@@ -123,17 +123,9 @@ module Baykit
|
|
123
123
|
else
|
124
124
|
begin
|
125
125
|
city.enter(self)
|
126
|
-
rescue Sink => e
|
127
|
-
change_state(TOUR_ID_NOCHECK, TourState::ABORTED)
|
128
|
-
raise e
|
129
126
|
rescue HttpException => e
|
130
|
-
BayLog.error_e(e)
|
131
127
|
change_state(TOUR_ID_NOCHECK, TourState::ABORTED)
|
132
128
|
raise e
|
133
|
-
rescue => e
|
134
|
-
BayLog.error_e(e)
|
135
|
-
change_state(TOUR_ID_NOCHECK, TourState::ABORTED)
|
136
|
-
raise HttpException.new(HttpStatus::INTERNAL_SERVER_ERROR, e.message)
|
137
129
|
end
|
138
130
|
end
|
139
131
|
end
|
@@ -208,26 +208,27 @@ module Baykit
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def abort()
|
211
|
-
if !@tour.preparing?
|
212
|
-
BayLog.debug("%s cannot abort non-preparing tour", @tour)
|
213
|
-
return false
|
214
|
-
end
|
215
|
-
|
216
211
|
BayLog.debug("%s abort", @tour)
|
217
|
-
if @tour.
|
218
|
-
|
219
|
-
|
212
|
+
if @tour.preparing?
|
213
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
214
|
+
return true
|
220
215
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
216
|
+
elsif @tour.running?
|
217
|
+
aborted = true
|
218
|
+
if @content_handler != nil
|
219
|
+
aborted = @content_handler.on_abort(@tour)
|
220
|
+
end
|
225
221
|
|
226
|
-
|
227
|
-
|
222
|
+
if aborted
|
223
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
224
|
+
end
|
225
|
+
|
226
|
+
return aborted
|
227
|
+
else
|
228
|
+
BayLog.debug("%s tour is not preparing or not running", @tour)
|
229
|
+
return false
|
228
230
|
end
|
229
231
|
|
230
|
-
return aborted
|
231
232
|
end
|
232
233
|
|
233
234
|
def set_content_handler(hnd)
|
@@ -47,13 +47,11 @@ module Baykit
|
|
47
47
|
attr :bytes_consumed
|
48
48
|
attr :bytes_limit
|
49
49
|
attr :buffer_size
|
50
|
-
attr :tour_returned
|
51
50
|
|
52
51
|
def initialize(tur)
|
53
52
|
@headers = Headers.new()
|
54
53
|
@tour = tur
|
55
54
|
@buffer_size = BayServer.harbor.tour_buffer_size
|
56
|
-
@tour_returned = false
|
57
55
|
end
|
58
56
|
|
59
57
|
def init()
|
@@ -187,6 +185,7 @@ module Baykit
|
|
187
185
|
raise Sink.new("Response consume listener is null")
|
188
186
|
end
|
189
187
|
|
188
|
+
@bytes_posted += len
|
190
189
|
BayLog.debug("%s posted res content len=%d posted=%d limit=%d consumed=%d",
|
191
190
|
@tour, len, @bytes_posted, @bytes_limit, @bytes_consumed)
|
192
191
|
if @bytes_limit > 0 && @bytes_limit < self.bytes_posted
|
@@ -211,10 +210,6 @@ module Baykit
|
|
211
210
|
end
|
212
211
|
end
|
213
212
|
|
214
|
-
@bytes_posted += len
|
215
|
-
|
216
|
-
BayLog.debug("%s post res content: len=%d posted=%d limit=%d consumed=%d",
|
217
|
-
@tour, len, @bytes_posted, @bytes_limit, @bytes_consumed)
|
218
213
|
|
219
214
|
old_available = @available
|
220
215
|
if !buffer_available()
|
@@ -248,17 +243,17 @@ module Baykit
|
|
248
243
|
|
249
244
|
|
250
245
|
# Done listener
|
246
|
+
tour_returned = false
|
251
247
|
done_lis = Proc.new() do
|
252
248
|
@tour.check_tour_id(chk_tour_id)
|
253
249
|
@tour.ship.return_tour(@tour)
|
254
|
-
|
250
|
+
tour_returned = true
|
255
251
|
end
|
256
252
|
|
257
253
|
begin
|
258
254
|
if @tour.zombie? || @tour.aborted?
|
259
255
|
# Don't send peer any data. Do nothing
|
260
256
|
BayLog.debug("%s Aborted or zombie tour. do nothing: %s state=%s", self, @tour, @tour.state)
|
261
|
-
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ENDED)
|
262
257
|
done_lis.call()
|
263
258
|
else
|
264
259
|
begin
|
@@ -270,8 +265,10 @@ module Baykit
|
|
270
265
|
end
|
271
266
|
end
|
272
267
|
ensure
|
273
|
-
|
274
|
-
|
268
|
+
# If tour is returned, we cannot change its state because
|
269
|
+
# it will become uninitialized.
|
270
|
+
BayLog.debug("%s tur#%d is returned: %s", self, chk_tour_id, tour_returned)
|
271
|
+
if !tour_returned
|
275
272
|
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ENDED)
|
276
273
|
end
|
277
274
|
end
|
@@ -326,8 +323,8 @@ module Baykit
|
|
326
323
|
end
|
327
324
|
|
328
325
|
if @header_sent
|
329
|
-
BayLog.
|
330
|
-
BayLog.
|
326
|
+
BayLog.debug("Try to send error after response header is sent (Ignore)")
|
327
|
+
BayLog.debug("%s: status=%d, message=%s", self, status, msg)
|
331
328
|
if err != nil
|
332
329
|
BayLog.error_e(err);
|
333
330
|
end
|
@@ -341,7 +338,7 @@ module Baykit
|
|
341
338
|
begin
|
342
339
|
@tour.ship.send_error(@tour.ship_id, @tour, status, msg, err)
|
343
340
|
rescue IOError => e
|
344
|
-
BayLog.
|
341
|
+
BayLog.debug_e(e, "%s Error on sending error", self)
|
345
342
|
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
346
343
|
end
|
347
344
|
@header_sent = true
|
@@ -20,17 +20,25 @@ module Baykit
|
|
20
20
|
@name = name
|
21
21
|
end
|
22
22
|
|
23
|
+
def to_s
|
24
|
+
@name
|
25
|
+
end
|
26
|
+
|
23
27
|
def run
|
24
28
|
while true
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
block = @que.deq
|
30
|
+
if block == nil
|
31
|
+
break
|
32
|
+
end
|
33
|
+
BayLog.debug("Start task on: %s", @name)
|
34
|
+
block.call
|
35
|
+
BayLog.debug("End task on: %s", @name)
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
def
|
33
|
-
@
|
39
|
+
def shutdown
|
40
|
+
@que.pop until @que.empty?
|
41
|
+
@que.enq(nil)
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
@@ -40,12 +48,14 @@ module Baykit
|
|
40
48
|
attr :count
|
41
49
|
attr :max_queue_len
|
42
50
|
attr :name
|
51
|
+
attr :executors
|
43
52
|
|
44
53
|
def initialize(name, count)
|
45
54
|
@que = Thread::Queue.new
|
46
55
|
@count = count
|
47
56
|
@max_queue_len = MAX_LEN_PER_EXECUTOR * count
|
48
57
|
@name = name
|
58
|
+
@executors = []
|
49
59
|
|
50
60
|
count.times do |i|
|
51
61
|
started = false
|
@@ -56,6 +66,7 @@ module Baykit
|
|
56
66
|
Thread.current.name = th_name
|
57
67
|
e = Executor.new @que, id, th_name
|
58
68
|
e.run
|
69
|
+
@executors << e
|
59
70
|
end
|
60
71
|
while !started
|
61
72
|
sleep(0.01)
|
@@ -63,17 +74,23 @@ module Baykit
|
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
|
-
def to_s
|
77
|
+
def to_s
|
67
78
|
return "ExecutorService[#{@name}]"
|
68
79
|
end
|
69
80
|
|
70
81
|
# post task
|
71
|
-
def submit(
|
72
|
-
BayLog.debug("%s Submit:
|
82
|
+
def submit(&block)
|
83
|
+
BayLog.debug("%s Submit: (qlen=%d/%d)", self, @que.length, @max_queue_len)
|
73
84
|
if @que.length > @max_queue_len
|
74
85
|
raise IOError("Task queue is full (>_<)")
|
75
86
|
end
|
76
|
-
@que.enq(
|
87
|
+
@que.enq(block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def shutdown
|
91
|
+
@executors.each do |exe|
|
92
|
+
exe.shutdown
|
93
|
+
end
|
77
94
|
end
|
78
95
|
end
|
79
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bayserver-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michisuke-P
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: BayServer is one of the high-speed web servers. It operates as a single-threaded,
|
14
14
|
asynchronous server, which makes it exceptionally fast. It also supports multi-core
|