bayserver-core 3.0.2 → 3.3.1
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 +2 -0
- data/lib/baykit/bayserver/agent/grand_agent.rb +145 -133
- data/lib/baykit/bayserver/agent/letters/accepted_letter.rb +17 -0
- data/lib/baykit/bayserver/agent/letters/closed_letter.rb +14 -0
- data/lib/baykit/bayserver/agent/letters/connected_letter.rb +14 -0
- data/lib/baykit/bayserver/agent/letters/error_letter.rb +16 -0
- data/lib/baykit/bayserver/agent/letters/letter.rb +19 -0
- data/lib/baykit/bayserver/agent/letters/package.rb +9 -0
- data/lib/baykit/bayserver/agent/letters/read_letter.rb +20 -0
- data/lib/baykit/bayserver/agent/letters/wrote_letter.rb +17 -0
- data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +49 -49
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +47 -32
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +5 -0
- data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +12 -28
- data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +20 -5
- data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +125 -87
- data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +24 -19
- data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +21 -15
- data/lib/baykit/bayserver/bay_log.rb +20 -16
- data/lib/baykit/bayserver/bayserver.rb +8 -15
- data/lib/baykit/bayserver/common/cities.rb +1 -1
- data/lib/baykit/bayserver/common/inbound_ship.rb +5 -45
- data/lib/baykit/bayserver/common/inbound_ship_store.rb +0 -1
- data/lib/baykit/bayserver/common/multiplexer.rb +5 -1
- data/lib/baykit/bayserver/{agent/multiplexer → common}/rudder_state.rb +42 -11
- data/lib/baykit/bayserver/common/rudder_state_store.rb +63 -0
- data/lib/baykit/bayserver/{agent/multiplexer → common}/transporter.rb +2 -4
- data/lib/baykit/bayserver/common/warp_ship.rb +12 -7
- data/lib/baykit/bayserver/{agent/multiplexer → common}/write_unit.rb +2 -4
- data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +0 -1
- data/lib/baykit/bayserver/docker/base/port_base.rb +5 -5
- data/lib/baykit/bayserver/docker/base/warp_base.rb +7 -4
- data/lib/baykit/bayserver/docker/built_in/built_in_city_docker.rb +1 -1
- data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +25 -2
- data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +43 -35
- data/lib/baykit/bayserver/docker/harbor.rb +14 -0
- data/lib/baykit/bayserver/docker/send_file/file_content.rb +66 -0
- data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +113 -29
- data/lib/baykit/bayserver/docker/send_file/file_store.rb +117 -0
- data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +13 -5
- data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +11 -2
- data/lib/baykit/bayserver/docker/send_file/wait_file_ship.rb +92 -0
- data/lib/baykit/bayserver/mem_usage.rb +2 -0
- data/lib/baykit/bayserver/protocol/packet.rb +2 -1
- data/lib/baykit/bayserver/protocol/packet_part_accessor.rb +5 -5
- data/lib/baykit/bayserver/protocol/protocol_exception.rb +7 -1
- data/lib/baykit/bayserver/rudders/io_rudder.rb +2 -2
- data/lib/baykit/bayserver/rudders/rudder.rb +4 -0
- data/lib/baykit/bayserver/rudders/rudder_base.rb +21 -0
- data/lib/baykit/bayserver/tours/req_content_handler.rb +13 -13
- data/lib/baykit/bayserver/tours/tour.rb +18 -13
- data/lib/baykit/bayserver/tours/tour_req.rb +13 -15
- data/lib/baykit/bayserver/tours/tour_res.rb +42 -19
- data/lib/baykit/bayserver/util/cgi_util.rb +7 -2
- data/lib/baykit/bayserver/util/headers.rb +2 -2
- data/lib/baykit/bayserver/util/http_status.rb +7 -0
- data/lib/baykit/bayserver/util/http_util.rb +16 -0
- data/lib/baykit/bayserver/util/nio_selector.rb +103 -0
- data/lib/baykit/bayserver/util/rb_selector.rb +55 -0
- data/lib/baykit/bayserver/util/selector.rb +43 -80
- data/lib/baykit/bayserver/util/simple_buffer.rb +1 -1
- data/lib/baykit/bayserver/version.rb +1 -1
- metadata +24 -21
- data/lib/baykit/bayserver/agent/accept_handler.rb +0 -71
- data/lib/baykit/bayserver/agent/channel_listener.rb +0 -35
- data/lib/baykit/bayserver/agent/letter.rb +0 -30
- data/lib/baykit/bayserver/agent/transporter/data_listener.rb +0 -38
- data/lib/baykit/bayserver/agent/transporter/package.rb +0 -0
- data/lib/baykit/bayserver/agent/transporter/spin_read_transporter.rb +0 -111
- data/lib/baykit/bayserver/agent/transporter/spin_write_transporter.rb +0 -125
- data/lib/baykit/bayserver/agent/transporter/transporter.rb +0 -332
- data/lib/baykit/bayserver/docker/built_in/log_boat.rb +0 -71
- data/lib/baykit/bayserver/tours/send_file_yacht.rb +0 -97
- data/lib/baykit/bayserver/watercraft/boat.rb +0 -43
- data/lib/baykit/bayserver/watercraft/yacht.rb +0 -42
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module Baykit
|
|
2
|
-
module BayServer
|
|
3
|
-
module Agent
|
|
4
|
-
module Transporter
|
|
5
|
-
module DataListener # interface
|
|
6
|
-
|
|
7
|
-
def notify_connect()
|
|
8
|
-
raise NotImplementedError.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def notify_handshake_done(protocol)
|
|
12
|
-
raise NotImplementedError.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def notify_read(buf)
|
|
16
|
-
raise NotImplementedError.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def notify_eof()
|
|
20
|
-
raise NotImplementedError.new
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def notify_protocol_error(err)
|
|
24
|
-
raise NotImplementedError.new
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def notify_close()
|
|
28
|
-
raise NotImplementedError.new
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def check_timeout(duration_sec)
|
|
32
|
-
raise NotImplementedError.new
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
File without changes
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'baykit/bayserver/agent/spin_handler'
|
|
2
|
-
require 'baykit/bayserver/util/string_util'
|
|
3
|
-
require 'baykit/bayserver/util/valve'
|
|
4
|
-
|
|
5
|
-
module Baykit
|
|
6
|
-
module BayServer
|
|
7
|
-
module Agent
|
|
8
|
-
module Transporter
|
|
9
|
-
class SpinReadTransporter
|
|
10
|
-
include Baykit::BayServer::Agent::SpinHandler::SpinListener # implements
|
|
11
|
-
include Baykit::BayServer::Util::Valve # implements
|
|
12
|
-
include Baykit::BayServer::Util
|
|
13
|
-
|
|
14
|
-
attr :spin_handler
|
|
15
|
-
attr :data_listener
|
|
16
|
-
attr :infile
|
|
17
|
-
attr :read_buf
|
|
18
|
-
attr :total_read
|
|
19
|
-
attr :file_len
|
|
20
|
-
attr :timeout_sec
|
|
21
|
-
attr :eof_checker
|
|
22
|
-
attr :is_closed
|
|
23
|
-
|
|
24
|
-
def initialize(buf_size)
|
|
25
|
-
@read_buf = StringUtil.alloc(buf_size)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def init(spin_hnd, lis, infile, limit, timeout_sec, eof_checker)
|
|
29
|
-
@spin_handler = spin_hnd
|
|
30
|
-
@data_listener = lis
|
|
31
|
-
@infile = infile
|
|
32
|
-
@file_len = limit
|
|
33
|
-
@total_read = 0
|
|
34
|
-
@timeout_sec = timeout_sec
|
|
35
|
-
@eof_checker = eof_checker
|
|
36
|
-
@is_closed = false
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_s
|
|
40
|
-
data_listener.to_s()
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
######################################################
|
|
44
|
-
# Implements Reusable
|
|
45
|
-
######################################################
|
|
46
|
-
|
|
47
|
-
def reset()
|
|
48
|
-
@data_listener = nil
|
|
49
|
-
@infile = nil
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
######################################################
|
|
53
|
-
# Implements SpinListener
|
|
54
|
-
######################################################
|
|
55
|
-
|
|
56
|
-
def lap()
|
|
57
|
-
begin
|
|
58
|
-
@infile.sysread(@buf_size, @read_buf)
|
|
59
|
-
|
|
60
|
-
if @read_buf.length == 0
|
|
61
|
-
return NextSocketAction::CONTINUE, true
|
|
62
|
-
end
|
|
63
|
-
@total_read += @read_buf.length
|
|
64
|
-
|
|
65
|
-
next_act = @yacht.notify_read(@read_buf)
|
|
66
|
-
|
|
67
|
-
if @total_read == @file_len
|
|
68
|
-
@data_listener.notify_eof()
|
|
69
|
-
close()
|
|
70
|
-
return NextSocketAction::CLOSE, false
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
return next_act, false
|
|
74
|
-
rescue Exception => e
|
|
75
|
-
BayLog.error_e(e)
|
|
76
|
-
close()
|
|
77
|
-
return NextSocketAction::CLOSE, false
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def check_timeout(duration_sec)
|
|
82
|
-
return duration_sec > @timeout_sec
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def close()
|
|
86
|
-
if @infile != nil
|
|
87
|
-
@infile.close()
|
|
88
|
-
end
|
|
89
|
-
@data_listener.notify_close()
|
|
90
|
-
@is_closed = true
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
######################################################
|
|
94
|
-
# Implements Valve
|
|
95
|
-
######################################################
|
|
96
|
-
|
|
97
|
-
def open_valve()
|
|
98
|
-
@spin_handler.ask_to_callback(self)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
######################################################
|
|
102
|
-
# Other methods
|
|
103
|
-
######################################################
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
require 'baykit/bayserver/agent/spin_handler'
|
|
2
|
-
require 'baykit/bayserver/util/string_util'
|
|
3
|
-
require 'baykit/bayserver/util/reusable'
|
|
4
|
-
require 'baykit/bayserver/util/valve'
|
|
5
|
-
require 'baykit/bayserver/util/postman'
|
|
6
|
-
|
|
7
|
-
module Baykit
|
|
8
|
-
module BayServer
|
|
9
|
-
module Agent
|
|
10
|
-
module Transporter
|
|
11
|
-
class SpinWriteTransporter < Baykit::BayServer::Agent::SpinHandler
|
|
12
|
-
include Baykit::BayServer::Util::Valve # implements
|
|
13
|
-
include Baykit::BayServer::Util::Reusable # implements
|
|
14
|
-
include Baykit::BayServer::Util::Postman # implements
|
|
15
|
-
|
|
16
|
-
include Baykit::BayServer::Util
|
|
17
|
-
|
|
18
|
-
attr :spin_handler
|
|
19
|
-
attr :data_listener
|
|
20
|
-
attr :outfile
|
|
21
|
-
attr :write_queue
|
|
22
|
-
attr :lock
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def initialize()
|
|
26
|
-
@write_queue = []
|
|
27
|
-
@lock = Mutex.new()
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def init(spin_hnd, outfile, lis)
|
|
31
|
-
@spin_handler = spin_hnd
|
|
32
|
-
@data_listener = lis
|
|
33
|
-
@outfile = outfile
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def to_s
|
|
37
|
-
data_listener.to_s()
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
######################################################
|
|
41
|
-
# Implements Reusable
|
|
42
|
-
######################################################
|
|
43
|
-
|
|
44
|
-
def reset()
|
|
45
|
-
@data_listener = nil
|
|
46
|
-
@outfile = nil
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
######################################################
|
|
50
|
-
# Implements SpinListener
|
|
51
|
-
######################################################
|
|
52
|
-
|
|
53
|
-
def lap()
|
|
54
|
-
begin
|
|
55
|
-
|
|
56
|
-
buf = nil
|
|
57
|
-
@lock.synchronize do
|
|
58
|
-
if @write_queue.empty?
|
|
59
|
-
BayLog.warn("%s Write queue empty", self)
|
|
60
|
-
return NextSocketAction::SUSPEND
|
|
61
|
-
end
|
|
62
|
-
buf = @write_queue[0]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
len = @outfile.syswrite(buf)
|
|
66
|
-
|
|
67
|
-
if len == 0
|
|
68
|
-
return NextSocketAction::CONTINUE
|
|
69
|
-
elsif len < buf.length
|
|
70
|
-
buf[0 .. len-1] = ""
|
|
71
|
-
return NextSocketAction::CONTINUE
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
@lock.synchronize do
|
|
75
|
-
@write_queue.delete_at(0)
|
|
76
|
-
if @write_queue.empty?
|
|
77
|
-
return NextSocketAction::SUSPEND
|
|
78
|
-
else
|
|
79
|
-
return NextSocketAction::CONTINUE
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
rescue Exception => e
|
|
84
|
-
BayLog.error_e(e)
|
|
85
|
-
close()
|
|
86
|
-
return NextSocketAction::CLOSE
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def check_timeout(duration_sec)
|
|
91
|
-
return false
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def close()
|
|
95
|
-
if @outfile != nil
|
|
96
|
-
@outfile.close()
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
######################################################
|
|
101
|
-
# Implements Valve
|
|
102
|
-
######################################################
|
|
103
|
-
|
|
104
|
-
def open_valve()
|
|
105
|
-
@spin_handler.ask_to_callback(self)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
######################################################
|
|
109
|
-
# Other methods
|
|
110
|
-
######################################################
|
|
111
|
-
def post(bytes, tag)
|
|
112
|
-
@lock.synchronize do
|
|
113
|
-
empty = @write_queue.empty?
|
|
114
|
-
@write_queue << bytes
|
|
115
|
-
if empty
|
|
116
|
-
open_valve()
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
require 'baykit/bayserver/agent/non_blocking_handler'
|
|
2
|
-
require 'baykit/bayserver/agent/channel_listener'
|
|
3
|
-
require 'baykit/bayserver/protocol/protocol_exception'
|
|
4
|
-
require 'baykit/bayserver/util/reusable'
|
|
5
|
-
require 'baykit/bayserver/util/postman'
|
|
6
|
-
|
|
7
|
-
module Baykit
|
|
8
|
-
module BayServer
|
|
9
|
-
module Agent
|
|
10
|
-
module Transporter
|
|
11
|
-
class Transporter
|
|
12
|
-
include Baykit::BayServer::Agent::ChannelListener # implements
|
|
13
|
-
include Baykit::BayServer::Util::Reusable # implements
|
|
14
|
-
include Baykit::BayServer::Util::Postman # implements
|
|
15
|
-
|
|
16
|
-
include Baykit::BayServer::Protocol
|
|
17
|
-
include Baykit::BayServer::Util
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
# Abstract methods
|
|
21
|
-
#
|
|
22
|
-
def secure()
|
|
23
|
-
raise NotImplementedError.new
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def handshake_nonblock()
|
|
27
|
-
raise NotImplementedError.new
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def handshake_finished()
|
|
31
|
-
raise NotImplementedError.new
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
attr :data_listener
|
|
35
|
-
attr :infile
|
|
36
|
-
attr :write_queue
|
|
37
|
-
attr :finale
|
|
38
|
-
attr :initialized
|
|
39
|
-
attr :ch_valid
|
|
40
|
-
attr :read_buf
|
|
41
|
-
attr :socket_io
|
|
42
|
-
attr :handshaked
|
|
43
|
-
attr :lock
|
|
44
|
-
attr :capacity
|
|
45
|
-
attr :non_blocking_handler
|
|
46
|
-
attr :write_only
|
|
47
|
-
|
|
48
|
-
def initialize(server_mode, bufsiz, trace_ssl, write_only = false)
|
|
49
|
-
@server_mode = server_mode
|
|
50
|
-
@write_queue = []
|
|
51
|
-
@lock = ::Monitor.new()
|
|
52
|
-
@capacity = bufsiz
|
|
53
|
-
@read_buf = StringUtil.alloc(bufsiz)
|
|
54
|
-
@trace_ssl = trace_ssl
|
|
55
|
-
reset()
|
|
56
|
-
@write_only = write_only
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def to_s()
|
|
60
|
-
return "tpt[#{@data_listener.to_s}]"
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
######################################################
|
|
65
|
-
# Implements Reusable
|
|
66
|
-
######################################################
|
|
67
|
-
def reset()
|
|
68
|
-
|
|
69
|
-
# Check write queue
|
|
70
|
-
if !@write_queue.empty?
|
|
71
|
-
raise Sink.new("Write queue is not empty")
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
@finale = false
|
|
75
|
-
@initialized = false
|
|
76
|
-
@ch = nil
|
|
77
|
-
set_valid(false)
|
|
78
|
-
@handshaked = false
|
|
79
|
-
@socket_io = nil
|
|
80
|
-
@read_buf.clear()
|
|
81
|
-
@write_only = false
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
######################################################
|
|
85
|
-
# Implements Postman
|
|
86
|
-
######################################################
|
|
87
|
-
|
|
88
|
-
def post(buf, adr, tag, &lisnr)
|
|
89
|
-
check_initialized()
|
|
90
|
-
|
|
91
|
-
BayLog.debug("%s post: %s len=%d", self, tag, buf.length)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
######################################################
|
|
97
|
-
# Implements Valve
|
|
98
|
-
######################################################
|
|
99
|
-
|
|
100
|
-
def open_valve()
|
|
101
|
-
BayLog.debug("%s resume", self)
|
|
102
|
-
@channel_handler.ask_to_read(@ch)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def abort()
|
|
106
|
-
BayLog.debug("%s abort", self)
|
|
107
|
-
@channel_handler.ask_to_close(@ch)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def zombie?()
|
|
111
|
-
return @ch != nil && !@ch_valid
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
######################################################
|
|
116
|
-
# Implements ChannelListener
|
|
117
|
-
######################################################
|
|
118
|
-
|
|
119
|
-
def on_readable(chk_ch)
|
|
120
|
-
check_channel(chk_ch)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def on_writable(chk_ch)
|
|
124
|
-
check_channel(chk_ch)
|
|
125
|
-
|
|
126
|
-
BayLog.trace("%s Writable", self)
|
|
127
|
-
|
|
128
|
-
if !@handshaked
|
|
129
|
-
begin
|
|
130
|
-
handshake_nonblock
|
|
131
|
-
BayLog.debug("#{@ship} Handshake done")
|
|
132
|
-
@handshaked = true
|
|
133
|
-
rescue IO::WaitReadable => e
|
|
134
|
-
BayLog.debug("#{@ship} Handshake status: read more")
|
|
135
|
-
return NextSocketAction::READ
|
|
136
|
-
rescue IO::WaitWritable => e
|
|
137
|
-
BayLog.debug("#{@ship} Handshake status: write more")
|
|
138
|
-
return NextSocketAction::CONTINUE
|
|
139
|
-
rescue StandardError => e
|
|
140
|
-
BayLog.error_e(e, " Error on handshaking: %s", self, e);
|
|
141
|
-
set_valid(false)
|
|
142
|
-
return NextSocketAction::CLOSE
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
if !@ch_valid
|
|
147
|
-
return NextSocketAction::CLOSE
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
empty = false
|
|
151
|
-
while true
|
|
152
|
-
#BayLog.debug "#{self} Send queue len=#{@write_queue.length}"
|
|
153
|
-
wunit = nil
|
|
154
|
-
@lock.synchronize do
|
|
155
|
-
if @write_queue.empty?
|
|
156
|
-
empty = true
|
|
157
|
-
break
|
|
158
|
-
end
|
|
159
|
-
wunit = @write_queue[0]
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
if empty
|
|
163
|
-
break
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
BayLog.debug("%s Try to write: pkt=%s buflen=%d chValid=%s", self, wunit.tag, wunit.buf.length, @ch_valid)
|
|
167
|
-
|
|
168
|
-
if @ch_valid && wunit.buf.length > 0
|
|
169
|
-
begin
|
|
170
|
-
len = write_nonblock(wunit.buf, wunit.adr)
|
|
171
|
-
wunit.buf[0, len] = ""
|
|
172
|
-
if wunit.buf.length > 0
|
|
173
|
-
# Data remains
|
|
174
|
-
break
|
|
175
|
-
end
|
|
176
|
-
rescue IO::WaitWritable => e
|
|
177
|
-
BayLog.debug_e(e, "%s Write will be pended", self)
|
|
178
|
-
break
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# packet send complete
|
|
183
|
-
wunit.done()
|
|
184
|
-
|
|
185
|
-
@lock.synchronize do
|
|
186
|
-
@write_queue.delete_at(0)
|
|
187
|
-
empty = @write_queue.empty?
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
if empty
|
|
191
|
-
break
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
if empty
|
|
196
|
-
if @finale
|
|
197
|
-
BayLog.trace("%s finale return Close", self)
|
|
198
|
-
state = NextSocketAction::CLOSE
|
|
199
|
-
elsif @write_only
|
|
200
|
-
state = NextSocketAction::SUSPEND
|
|
201
|
-
else
|
|
202
|
-
state = NextSocketAction::READ # will be handled as "Write Off"
|
|
203
|
-
end
|
|
204
|
-
else
|
|
205
|
-
state = NextSocketAction::CONTINUE
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
return state
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
def on_connectable(chk_ch)
|
|
213
|
-
check_channel(chk_ch)
|
|
214
|
-
BayLog.trace("%s onConnectable", self)
|
|
215
|
-
|
|
216
|
-
# check connected
|
|
217
|
-
begin
|
|
218
|
-
buf = ""
|
|
219
|
-
@ch.syswrite(buf)
|
|
220
|
-
rescue => e
|
|
221
|
-
BayLog.error("Connect failed: %s", e)
|
|
222
|
-
return NextSocketAction::CLOSE
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
return @data_listener.notify_connect()
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def check_timeout(chk_ch, duration)
|
|
229
|
-
check_channel(chk_ch)
|
|
230
|
-
|
|
231
|
-
return @data_listener.check_timeout(duration)
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def on_error(chk_ch, e)
|
|
235
|
-
check_channel(chk_ch)
|
|
236
|
-
BayLog.trace("%s onError: %s", self, e)
|
|
237
|
-
|
|
238
|
-
begin
|
|
239
|
-
raise e
|
|
240
|
-
rescue OpenSSL::SSL::SSLError => e
|
|
241
|
-
if @trace_ssl
|
|
242
|
-
BayLog.error_e(e, "%s SSL Error: %s", self, e)
|
|
243
|
-
else
|
|
244
|
-
BayLog.debug_e(e, "%s SSL Error: %s", self, e)
|
|
245
|
-
end
|
|
246
|
-
rescue => e
|
|
247
|
-
BayLog.error_e(e)
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def on_closed(chk_ch)
|
|
252
|
-
begin
|
|
253
|
-
check_channel(chk_ch)
|
|
254
|
-
rescue => e
|
|
255
|
-
BayLog.error_e(e)
|
|
256
|
-
return
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
set_valid(false)
|
|
260
|
-
|
|
261
|
-
@lock.synchronize do
|
|
262
|
-
# Clear queue
|
|
263
|
-
@write_queue.each do |write_unit|
|
|
264
|
-
write_unit.done()
|
|
265
|
-
end
|
|
266
|
-
@write_queue.clear()
|
|
267
|
-
end
|
|
268
|
-
@data_listener.notify_close()
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
def flush()
|
|
272
|
-
check_initialized()
|
|
273
|
-
|
|
274
|
-
BayLog.debug("%s flush", self)
|
|
275
|
-
|
|
276
|
-
if @ch_valid
|
|
277
|
-
empty = false
|
|
278
|
-
@lock.synchronize do
|
|
279
|
-
empty = @write_queue.empty?
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
if !empty
|
|
283
|
-
BayLog.debug("%s flush->askToWrite", self)
|
|
284
|
-
@channel_handler.ask_to_write(@ch)
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
def post_end()
|
|
290
|
-
check_initialized()
|
|
291
|
-
|
|
292
|
-
BayLog.debug("%s postEnd vld=%s", self, self.ch_valid)
|
|
293
|
-
|
|
294
|
-
# setting order is QUITE important finalState->finale
|
|
295
|
-
@finale = true
|
|
296
|
-
|
|
297
|
-
if @ch_valid
|
|
298
|
-
empty = nil
|
|
299
|
-
@lock.synchronize do
|
|
300
|
-
empty = @write_queue.empty?
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
if !empty
|
|
304
|
-
BayLog.debug("%s Tpt: sendEnd->askToWrite", self)
|
|
305
|
-
@channel_handler.ask_to_write(@ch)
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
protected
|
|
311
|
-
def check_channel(chk_ch)
|
|
312
|
-
if chk_ch != @ch
|
|
313
|
-
raise Sink.new("Invalid transporter instance (ship was returned?): #{chk_ch}")
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
def check_initialized
|
|
318
|
-
if !@initialized
|
|
319
|
-
raise Sink.new("Illegal State")
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def set_valid(valid)
|
|
324
|
-
@ch_valid = valid
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
end
|
|
328
|
-
end
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require 'baykit/bayserver/agent/transporter/data_listener'
|
|
2
|
-
require 'baykit/bayserver/protocol/packet'
|
|
3
|
-
require 'baykit/bayserver/watercraft/boat'
|
|
4
|
-
|
|
5
|
-
module Baykit
|
|
6
|
-
module BayServer
|
|
7
|
-
module Docker
|
|
8
|
-
module BuiltIn
|
|
9
|
-
class LogBoat < Baykit::BayServer::WaterCraft::Boat
|
|
10
|
-
include Baykit::BayServer::Agent::Transporter::DataListener
|
|
11
|
-
include Baykit::BayServer::Protocol
|
|
12
|
-
|
|
13
|
-
class LogPacket < Packet
|
|
14
|
-
def initialize(data)
|
|
15
|
-
super(0, 0, data.length)
|
|
16
|
-
new_data_accessor().put_string(data)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
attr :file_name
|
|
21
|
-
attr :postman
|
|
22
|
-
|
|
23
|
-
def initialize()
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def to_s()
|
|
28
|
-
return "lboat##{@boart_id}/#{@object_id} file=#{@file_name}";
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
######################################################
|
|
32
|
-
# Implements Reusable
|
|
33
|
-
######################################################
|
|
34
|
-
|
|
35
|
-
def reset()
|
|
36
|
-
@file_name = nil
|
|
37
|
-
@postman = nil
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
######################################################
|
|
41
|
-
# Implements DataListener
|
|
42
|
-
######################################################
|
|
43
|
-
|
|
44
|
-
def notify_close()
|
|
45
|
-
BayLog.info("Log closed: %s", self.file_name)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
######################################################
|
|
49
|
-
# Custom methods
|
|
50
|
-
######################################################
|
|
51
|
-
|
|
52
|
-
def init(file_name, postman)
|
|
53
|
-
init_boat()
|
|
54
|
-
@file_name = file_name
|
|
55
|
-
@postman = postman
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def log(data)
|
|
59
|
-
if data == nil
|
|
60
|
-
data = ""
|
|
61
|
-
end
|
|
62
|
-
data += CharUtil::LF
|
|
63
|
-
|
|
64
|
-
@postman.post(data, nil, file_name)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|