bayserver-core 2.3.2 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
- data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
- data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
- data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
- data/lib/baykit/bayserver/agent/letter.rb +30 -0
- data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
- data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
- data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
- data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
- data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
- data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
- data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
- data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
- data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
- data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
- data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
- data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
- data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
- data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
- data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
- data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
- data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
- data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
- data/lib/baykit/bayserver/bay_log.rb +1 -0
- data/lib/baykit/bayserver/bayserver.rb +32 -28
- data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
- data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
- data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
- data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
- data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
- data/lib/baykit/bayserver/common/postpone.rb +15 -0
- data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
- data/lib/baykit/bayserver/common/recipient.rb +24 -0
- data/lib/baykit/bayserver/common/vehicle.rb +24 -0
- data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
- data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
- data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
- data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
- data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
- data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
- data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
- data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
- data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
- data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
- data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
- data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
- data/lib/baykit/bayserver/docker/city.rb +27 -13
- data/lib/baykit/bayserver/docker/club.rb +8 -8
- data/lib/baykit/bayserver/docker/docker.rb +9 -1
- data/lib/baykit/bayserver/docker/harbor.rb +184 -22
- data/lib/baykit/bayserver/docker/permission.rb +7 -6
- data/lib/baykit/bayserver/docker/port.rb +39 -11
- data/lib/baykit/bayserver/docker/secure.rb +11 -9
- data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
- data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
- data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
- data/lib/baykit/bayserver/docker/town.rb +31 -15
- data/lib/baykit/bayserver/docker/trouble.rb +17 -5
- data/lib/baykit/bayserver/docker/warp.rb +34 -0
- data/lib/baykit/bayserver/mem_usage.rb +9 -9
- data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
- data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
- data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
- data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
- data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
- data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
- data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
- data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
- data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
- data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
- data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
- data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
- data/lib/baykit/bayserver/tours/tour.rb +2 -2
- data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
- data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
- data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
- data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
- data/lib/baykit/bayserver/train/train_runner.rb +17 -13
- data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
- data/lib/baykit/bayserver/util/executor_service.rb +11 -7
- data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
- data/lib/baykit/bayserver/util/locale.rb +1 -1
- data/lib/baykit/bayserver/util/selector.rb +24 -5
- data/lib/baykit/bayserver/util/sys_util.rb +6 -6
- data/lib/baykit/bayserver/version.rb +1 -1
- metadata +37 -18
- data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
- data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
- data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
- data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
- data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
- data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
- data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
- /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'baykit/bayserver/common/read_only_ship'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Docker
|
6
|
+
module SendFile
|
7
|
+
class SendFileShip < Baykit::BayServer::Common::ReadOnlyShip
|
8
|
+
include Baykit::BayServer::Tours::ReqContentHandler # implements
|
9
|
+
|
10
|
+
attr :file_wrote_len
|
11
|
+
attr :tour
|
12
|
+
attr :tour_id
|
13
|
+
|
14
|
+
include Baykit::BayServer::Agent
|
15
|
+
include Baykit::BayServer::Agent::Multiplexer
|
16
|
+
include Baykit::BayServer::Tours
|
17
|
+
include Baykit::BayServer::Rudders
|
18
|
+
|
19
|
+
attr :path
|
20
|
+
attr :abortable
|
21
|
+
|
22
|
+
def init(rd, tp, tur)
|
23
|
+
super(tur.ship.agent_id, rd, tp)
|
24
|
+
@file_wrote_len = 0
|
25
|
+
@tour = tur
|
26
|
+
@tour_id = tur.tour_id
|
27
|
+
end
|
28
|
+
|
29
|
+
######################################################
|
30
|
+
# Implements Reusable
|
31
|
+
######################################################
|
32
|
+
|
33
|
+
def reset
|
34
|
+
super
|
35
|
+
@file_wrote_len = 0
|
36
|
+
@tour_id = 0
|
37
|
+
@tour = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
######################################################
|
41
|
+
# Implements ReqContentHandler
|
42
|
+
######################################################
|
43
|
+
|
44
|
+
def notify_read(buf)
|
45
|
+
@file_wrote_len += buf.length
|
46
|
+
BayLog.debug("%s read file %d bytes: total=%d", self, buf.length, @file_wrote_len)
|
47
|
+
|
48
|
+
begin
|
49
|
+
available = @tour.res.send_res_content(@tour_id, buf, 0, buf.length)
|
50
|
+
|
51
|
+
if available
|
52
|
+
return NextSocketAction::CONTINUE
|
53
|
+
else
|
54
|
+
return NextSocketAction::SUSPEND
|
55
|
+
end
|
56
|
+
rescue IOError => e
|
57
|
+
notify_error(e)
|
58
|
+
return NextSocketAction::CLOSE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def notify_error(e)
|
63
|
+
BayLog.debug_e(e, "%s Error notified", self)
|
64
|
+
begin
|
65
|
+
@tour.res.send_error(@tour_id, HttpStatus::INTERNAL_SERVER_ERROR, nil, e)
|
66
|
+
rescue IOError => ex
|
67
|
+
BayLog.debug_e(ex)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def notify_eof
|
72
|
+
BayLog.debug("%s EOF", self)
|
73
|
+
begin
|
74
|
+
@tour.res.end_res_content(@tour_id)
|
75
|
+
rescue IOError => e
|
76
|
+
BayLog.debug_e(ex)
|
77
|
+
end
|
78
|
+
return NextSocketAction::CLOSE
|
79
|
+
end
|
80
|
+
|
81
|
+
def notify_close
|
82
|
+
BayLog.debug("%s Close", self)
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_timeout(duration_sec)
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -9,21 +9,37 @@ module Baykit
|
|
9
9
|
MATCH_TYPE_NOT_MATCHED = 2
|
10
10
|
MATCH_TYPE_CLOSE = 3
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
def name
|
13
|
+
raise NotImplementedError.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def city
|
17
|
+
raise NotImplementedError.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def location
|
21
|
+
raise NotImplementedError.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def welcome_file
|
25
|
+
raise NotImplementedError.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def clubs
|
29
|
+
raise NotImplementedError.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def reroute(uri)
|
33
|
+
raise NotImplementedError.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def matches(uri)
|
37
|
+
raise NotImplementedError.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_admitted(tur)
|
41
|
+
raise NotImplementedError.new
|
42
|
+
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
end
|
@@ -6,11 +6,23 @@ module Baykit
|
|
6
6
|
module Trouble
|
7
7
|
include Docker # implements
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
TROUBLE_METHOD_GUIDE = 1
|
10
|
+
TROUBLE_METHOD_TEXT = 2
|
11
|
+
TROUBLE_METHOD_REROUTE = 3
|
12
|
+
|
13
|
+
class Command
|
14
|
+
attr :method
|
15
|
+
attr :target
|
16
|
+
|
17
|
+
def initialize(method, target)
|
18
|
+
@method = method
|
19
|
+
@target = target
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(status) Command
|
24
|
+
raise NotImplementedError.new
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'baykit/bayserver/docker/docker'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Docker
|
6
|
+
module Warp # interface
|
7
|
+
include Docker # implements
|
8
|
+
|
9
|
+
def host
|
10
|
+
raise NotImplementedError.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def port
|
14
|
+
raise NotImplementedError.new
|
15
|
+
end
|
16
|
+
def warp_base
|
17
|
+
raise NotImplementedError.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def timeout_sec
|
21
|
+
raise NotImplementedError.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def keep(warp_ship)
|
25
|
+
raise NotImplementedError.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_end_ship(warp_ship)
|
29
|
+
raise NotImplementedError.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -4,8 +4,8 @@ require 'baykit/bayserver/agent/lifecycle_listener'
|
|
4
4
|
require 'baykit/bayserver/protocol/protocol_handler_store'
|
5
5
|
require 'baykit/bayserver/protocol/packet_store'
|
6
6
|
require 'baykit/bayserver/tours/tour_store'
|
7
|
-
require 'baykit/bayserver/
|
8
|
-
require 'baykit/bayserver/docker/
|
7
|
+
require 'baykit/bayserver/common/inbound_ship_store'
|
8
|
+
require 'baykit/bayserver/docker/base/warp_base'
|
9
9
|
|
10
10
|
require 'baykit/bayserver/util/string_util'
|
11
11
|
|
@@ -16,19 +16,19 @@ module Baykit
|
|
16
16
|
include Baykit::BayServer::Agent
|
17
17
|
include Baykit::BayServer::Protocol
|
18
18
|
include Baykit::BayServer::Tours
|
19
|
-
include Baykit::BayServer::
|
19
|
+
include Baykit::BayServer::Common
|
20
20
|
include Baykit::BayServer::Docker::Base
|
21
21
|
include Baykit::BayServer::Util
|
22
22
|
|
23
23
|
class AgentListener
|
24
24
|
include Baykit::BayServer::Agent::LifecycleListener
|
25
25
|
|
26
|
-
def add(
|
27
|
-
MemUsage.mem_usages[
|
26
|
+
def add(agt_id)
|
27
|
+
MemUsage.mem_usages[agt_id] = MemUsage.new(agt_id);
|
28
28
|
end
|
29
29
|
|
30
|
-
def remove(
|
31
|
-
MemUsage.mem_usages.delete(
|
30
|
+
def remove(agt_id)
|
31
|
+
MemUsage.mem_usages.delete(agt_id)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -73,14 +73,14 @@ module Baykit
|
|
73
73
|
end
|
74
74
|
|
75
75
|
city.clubs().each do |club|
|
76
|
-
if club.kind_of?(
|
76
|
+
if club.kind_of?(WarpBase)
|
77
77
|
BayLog.info("%sClub(%s%s) Usage:", StringUtil.indent(indent), club, pname);
|
78
78
|
club.get_ship_store(@agent_id).print_usage(indent+1)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
city.towns().each do |town|
|
82
82
|
town.clubs().each do |club|
|
83
|
-
if club.kind_of?(
|
83
|
+
if club.kind_of?(WarpBase)
|
84
84
|
BayLog.info("%sClub(%s%s) Usage:", StringUtil.indent(indent), club, pname);
|
85
85
|
club.get_ship_store(@agent_id).print_usage(indent+1)
|
86
86
|
end
|
@@ -24,7 +24,7 @@ module Baykit
|
|
24
24
|
pkt = @pkt_store.rent(cmd.type)
|
25
25
|
begin
|
26
26
|
cmd.pack(pkt)
|
27
|
-
@pkt_packer.post(sip
|
27
|
+
@pkt_packer.post(sip, pkt) do
|
28
28
|
@pkt_store.Return(pkt)
|
29
29
|
if lisnr != nil
|
30
30
|
lisnr.call()
|
@@ -36,13 +36,6 @@ module Baykit
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def flush(sip)
|
40
|
-
@pkt_packer.flush(sip.postman)
|
41
|
-
end
|
42
|
-
|
43
|
-
def end(sip)
|
44
|
-
@pkt_packer.end(sip.postman)
|
45
|
-
end
|
46
39
|
end
|
47
40
|
end
|
48
41
|
end
|
@@ -7,23 +7,19 @@ module Baykit
|
|
7
7
|
def reset()
|
8
8
|
end
|
9
9
|
|
10
|
-
def post(
|
11
|
-
if
|
10
|
+
def post(sip, pkt, &lisnr)
|
11
|
+
if sip == nil || pkt == nil || lisnr == nil
|
12
12
|
raise Sink.new()
|
13
13
|
end
|
14
|
-
|
14
|
+
sip.transporter.req_write(
|
15
|
+
sip.rudder,
|
16
|
+
pkt.buf[0, pkt.buf_len],
|
17
|
+
nil,
|
18
|
+
pkt) do
|
15
19
|
lisnr.call()
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
|
-
def flush(postman)
|
20
|
-
postman.flush()
|
21
|
-
end
|
22
|
-
|
23
|
-
def end(postman)
|
24
|
-
postman.post_end()
|
25
|
-
end
|
26
|
-
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -15,15 +15,15 @@ module Baykit
|
|
15
15
|
class AgentListener
|
16
16
|
include Baykit::BayServer::Agent::LifecycleListener # implements
|
17
17
|
|
18
|
-
def add(
|
18
|
+
def add(agt_id)
|
19
19
|
PacketStore.proto_map.values().each do |ifo|
|
20
|
-
ifo.add_agent(
|
20
|
+
ifo.add_agent(agt_id);
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def remove(
|
24
|
+
def remove(agt_id)
|
25
25
|
PacketStore.proto_map.values().each do |ifo|
|
26
|
-
ifo.remove_agent(
|
26
|
+
ifo.remove_agent(agt_id);
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -12,22 +12,36 @@ module Baykit
|
|
12
12
|
attr :packet_packer
|
13
13
|
attr :command_unpacker
|
14
14
|
attr :command_packer
|
15
|
-
attr :
|
15
|
+
attr :command_handler
|
16
16
|
attr :server_mode
|
17
17
|
attr_accessor :ship
|
18
18
|
|
19
|
+
def initialize(pkt_unpacker, pkt_packer, cmd_unpacker, cmd_packer, cmd_handler, svr_mode)
|
20
|
+
@packet_unpacker = pkt_unpacker
|
21
|
+
@packet_packer = pkt_packer
|
22
|
+
@command_unpacker = cmd_unpacker
|
23
|
+
@command_packer = cmd_packer
|
24
|
+
@command_handler = cmd_handler
|
25
|
+
@server_mode = svr_mode
|
26
|
+
end
|
19
27
|
def to_s()
|
20
28
|
return ClassUtil.get_local_name(self.class) + " ship=" + ship.to_s
|
21
29
|
end
|
22
30
|
|
31
|
+
def init(sip)
|
32
|
+
@ship = sip
|
33
|
+
end
|
34
|
+
|
23
35
|
##################################################
|
24
36
|
# Implements Reusable
|
25
37
|
##################################################
|
26
38
|
def reset()
|
27
|
-
@command_unpacker.reset
|
28
|
-
@command_packer.reset
|
29
|
-
@packet_unpacker.reset
|
30
|
-
@packet_packer.reset
|
39
|
+
@command_unpacker.reset
|
40
|
+
@command_packer.reset
|
41
|
+
@packet_unpacker.reset
|
42
|
+
@packet_packer.reset
|
43
|
+
@command_handler.reset
|
44
|
+
@ship = nil
|
31
45
|
end
|
32
46
|
|
33
47
|
##################################################
|
@@ -35,21 +49,21 @@ module Baykit
|
|
35
49
|
##################################################
|
36
50
|
|
37
51
|
def protocol()
|
38
|
-
raise NotImplementedError
|
52
|
+
raise NotImplementedError.new
|
39
53
|
end
|
40
54
|
|
41
55
|
#
|
42
56
|
# Get max of request data size (maybe not packet size)
|
43
57
|
#
|
44
58
|
def max_req_packet_data_size()
|
45
|
-
raise NotImplementedError
|
59
|
+
raise NotImplementedError.new
|
46
60
|
end
|
47
61
|
|
48
62
|
#
|
49
63
|
# Get max of response data size (maybe not packet size)
|
50
64
|
#
|
51
65
|
def max_res_packet_data_size()
|
52
|
-
raise NotImplementedError
|
66
|
+
raise NotImplementedError.new
|
53
67
|
end
|
54
68
|
|
55
69
|
##################################################
|
@@ -58,6 +72,10 @@ module Baykit
|
|
58
72
|
def bytes_received(buf)
|
59
73
|
return @packet_unpacker.bytes_received(buf)
|
60
74
|
end
|
75
|
+
|
76
|
+
def post(cmd, &lis)
|
77
|
+
@command_packer.post(@ship, cmd, &lis)
|
78
|
+
end
|
61
79
|
end
|
62
80
|
end
|
63
81
|
end
|
@@ -38,13 +38,13 @@ module Baykit
|
|
38
38
|
@stores = {}
|
39
39
|
end
|
40
40
|
|
41
|
-
def add_agent(
|
42
|
-
store = PacketStore.get_store(@protocol,
|
43
|
-
@stores[
|
41
|
+
def add_agent(agt_id)
|
42
|
+
store = PacketStore.get_store(@protocol, agt_id);
|
43
|
+
@stores[agt_id] = ProtocolHandlerStore.new(@protocol, @server_mode, @protocol_handler_factory, store);
|
44
44
|
end
|
45
45
|
|
46
|
-
def remove_agent(
|
47
|
-
@stores.delete(
|
46
|
+
def remove_agent(agt_id)
|
47
|
+
@stores.delete(agt_id);
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'baykit/bayserver/rudders/rudder'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Rudders
|
6
|
+
class IORudder
|
7
|
+
include Rudder
|
8
|
+
|
9
|
+
attr :io
|
10
|
+
attr :non_blocking
|
11
|
+
|
12
|
+
def initialize(io)
|
13
|
+
@io = io
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
return "IORudder:" + @io.to_s
|
18
|
+
end
|
19
|
+
def key
|
20
|
+
return @io
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_non_blocking()
|
24
|
+
@non_blocking = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def read(buf, len)
|
28
|
+
begin
|
29
|
+
if @non_blocking
|
30
|
+
buf = @io.read_nonblock(len, buf)
|
31
|
+
else
|
32
|
+
buf = @io.readpartial(len, buf)
|
33
|
+
end
|
34
|
+
if buf == nil
|
35
|
+
return 0
|
36
|
+
else
|
37
|
+
return buf.length
|
38
|
+
end
|
39
|
+
rescue EOFError => e
|
40
|
+
return 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def write(buf)
|
45
|
+
if @non_blocking
|
46
|
+
return @io.write_nonblock(buf)
|
47
|
+
else
|
48
|
+
return @io.write(buf)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def close
|
53
|
+
@io.close()
|
54
|
+
end
|
55
|
+
|
56
|
+
def io
|
57
|
+
return @io
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Baykit
|
3
|
+
module BayServer
|
4
|
+
module Rudders
|
5
|
+
module Rudder # interface
|
6
|
+
|
7
|
+
def key
|
8
|
+
raise NotImplementedError.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_non_blocking
|
12
|
+
raise NotImplementedError.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def read(buf, len)
|
16
|
+
raise NotImplementedError.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(buf)
|
20
|
+
raise NotImplementedError.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def close
|
24
|
+
raise NotImplementedError.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,7 +3,7 @@ require 'baykit/bayserver/util/counter'
|
|
3
3
|
|
4
4
|
module Baykit
|
5
5
|
module BayServer
|
6
|
-
module
|
6
|
+
module Ships
|
7
7
|
class Ship
|
8
8
|
include Baykit::BayServer::Util::Reusable # implements
|
9
9
|
|
@@ -23,11 +23,10 @@ module Baykit
|
|
23
23
|
|
24
24
|
attr :object_id
|
25
25
|
attr :ship_id
|
26
|
-
attr :
|
27
|
-
attr :
|
28
|
-
attr :
|
26
|
+
attr :agent_id
|
27
|
+
attr :rudder
|
28
|
+
attr :transporter
|
29
29
|
attr :initialized
|
30
|
-
attr_accessor :protocol_handler
|
31
30
|
attr_accessor :keeping
|
32
31
|
|
33
32
|
def initialize()
|
@@ -35,67 +34,92 @@ module Baykit
|
|
35
34
|
@ship_id = INVALID_SHIP_ID
|
36
35
|
end
|
37
36
|
|
38
|
-
|
37
|
+
def init(agt_id, rd, tp)
|
38
|
+
if @initialized
|
39
|
+
raise Sink.new("Ship already initialized")
|
40
|
+
end
|
41
|
+
@ship_id = Ship.ship_id_counter.next
|
42
|
+
@agent_id = agt_id
|
43
|
+
@rudder = rd
|
44
|
+
@transporter = tp
|
45
|
+
@initialized = true
|
46
|
+
BayLog.debug("%s initialized", self)
|
47
|
+
end
|
48
|
+
|
49
|
+
#########################################
|
39
50
|
# implements Reusable
|
40
|
-
|
51
|
+
#########################################
|
41
52
|
def reset()
|
42
53
|
BayLog.debug("%s reset", self)
|
43
54
|
|
44
55
|
@initialized = false
|
45
|
-
@
|
46
|
-
@
|
47
|
-
@
|
56
|
+
@transporter = nil
|
57
|
+
@rudder = nil
|
58
|
+
@agent_id = -1
|
48
59
|
@ship_id = INVALID_SHIP_ID
|
49
|
-
@socket = nil
|
50
|
-
@protocol_handler = nil
|
51
60
|
@keeping = false
|
52
61
|
end
|
53
62
|
|
54
63
|
|
55
|
-
|
64
|
+
#########################################
|
56
65
|
# Other methods
|
57
|
-
|
66
|
+
#########################################
|
58
67
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
68
|
+
def id()
|
69
|
+
@ship_id
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_ship_id(check_id)
|
73
|
+
if !@initialized
|
74
|
+
raise Sink.new("#{self} ship not initialized (might be returned ship): #{check_id}")
|
75
|
+
end
|
76
|
+
if check_id != SHIP_ID_NOCHECK && check_id != @ship_id
|
77
|
+
raise Sink.new("#{self} Invalid ship id (might be returned ship): #{check_id}")
|
62
78
|
end
|
63
|
-
@ship_id = Ship.ship_id_counter.next
|
64
|
-
@agent = agt
|
65
|
-
@postman = postman
|
66
|
-
@socket = skt
|
67
|
-
@initialized = true
|
68
|
-
BayLog.debug("%s initialized", self)
|
69
79
|
end
|
70
80
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
#BayLog.debug("%s protocol handler is set", self)
|
81
|
+
def resume_read(check_id)
|
82
|
+
check_ship_id(check_id);
|
83
|
+
@transporter.req_read(@rudder)
|
75
84
|
end
|
76
85
|
|
77
|
-
def
|
78
|
-
@
|
86
|
+
def post_close
|
87
|
+
@transporter.req_close(@rudder)
|
79
88
|
end
|
80
89
|
|
81
|
-
|
82
|
-
|
90
|
+
#########################################
|
91
|
+
# Abstract methods
|
92
|
+
#########################################
|
93
|
+
def notify_handshake_done(proto)
|
94
|
+
raise NotImplementedError.new
|
83
95
|
end
|
84
96
|
|
97
|
+
def notify_connect()
|
98
|
+
raise NotImplementedError.new
|
99
|
+
end
|
85
100
|
|
101
|
+
def notify_read(buf)
|
102
|
+
raise NotImplementedError.new
|
103
|
+
end
|
86
104
|
|
87
|
-
def
|
88
|
-
|
89
|
-
@postman.open_valve();
|
105
|
+
def notify_eof()
|
106
|
+
raise NotImplementedError.new
|
90
107
|
end
|
91
108
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
109
|
+
def notify_error(e)
|
110
|
+
raise NotImplementedError.new
|
111
|
+
end
|
112
|
+
|
113
|
+
def notify_protocol_error(e)
|
114
|
+
raise NotImplementedError.new
|
115
|
+
end
|
116
|
+
|
117
|
+
def notify_close
|
118
|
+
raise NotImplementedError.new
|
119
|
+
end
|
120
|
+
|
121
|
+
def check_timeout(duration_sec)
|
122
|
+
raise NotImplementedError.new
|
99
123
|
end
|
100
124
|
end
|
101
125
|
end
|