Class: Baykit::BayServer::Docker::Base::PortBase
- Inherits:
-
DockerBase
- Object
- DockerBase
- Baykit::BayServer::Docker::Base::PortBase
- Includes:
- Agent, Agent::Multiplexer, Bcf, Common, Baykit::BayServer::Docker, Baykit::BayServer::Docker::Base, Port, Protocol, Rudders, Util
- Defined in:
- lib/baykit/bayserver/docker/base/port_base.rb
Instance Attribute Summary collapse
-
#additional_headers ⇒ Object
readonly
Returns the value of attribute additional_headers.
-
#anchored ⇒ Object
readonly
Returns the value of attribute anchored.
-
#cities ⇒ Object
readonly
Returns the value of attribute cities.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#permission_list ⇒ Object
readonly
Returns the value of attribute permission_list.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#secure_docker ⇒ Object
readonly
Returns the value of attribute secure_docker.
-
#socket_path ⇒ Object
readonly
Returns the value of attribute socket_path.
-
#timeout_sec ⇒ Object
readonly
Returns the value of attribute timeout_sec.
Attributes inherited from DockerBase
Class Method Summary collapse
Instance Method Summary collapse
-
#address ⇒ Object
implements Port.
- #find_city(name) ⇒ Object
-
#init(elm, parent) ⇒ Object
Implements Docker.
-
#init_docker(dkr) ⇒ Object
Implements DockerBase.
- #init_key_val(kv) ⇒ Object
-
#initialize ⇒ PortBase
constructor
A new instance of PortBase.
- #on_connected(agt_id, rd) ⇒ Object
- #return_protocol_handler(agt_id, proto_hnd) ⇒ Object
- #return_ship(sip) ⇒ Object
- #secure ⇒ Object
-
#support_anchored ⇒ Object
Abstract methods.
- #support_unanchored ⇒ Object
- #to_s ⇒ Object
Methods included from Port
Methods included from Docker
Constructor Details
#initialize ⇒ PortBase
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 39 def initialize() = [] @timeout_sec = -1 @host = nil @port = -1 @anchored = true @additional_headers = [] @socket_path = nil @secure_docker = nil @cities = Cities.new() end |
Instance Attribute Details
#additional_headers ⇒ Object (readonly)
Returns the value of attribute additional_headers.
33 34 35 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 33 def additional_headers @additional_headers end |
#anchored ⇒ Object (readonly)
Returns the value of attribute anchored.
32 33 34 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 32 def anchored @anchored end |
#cities ⇒ Object (readonly)
Returns the value of attribute cities.
37 38 39 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 37 def cities @cities end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
30 31 32 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 30 def host @host end |
#permission_list ⇒ Object (readonly)
Returns the value of attribute permission_list.
29 30 31 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 29 def end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
31 32 33 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 31 def port @port end |
#secure_docker ⇒ Object (readonly)
Returns the value of attribute secure_docker.
36 37 38 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 36 def secure_docker @secure_docker end |
#socket_path ⇒ Object (readonly)
Returns the value of attribute socket_path.
34 35 36 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 34 def socket_path @socket_path end |
#timeout_sec ⇒ Object (readonly)
Returns the value of attribute timeout_sec.
35 36 37 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 35 def timeout_sec @timeout_sec end |
Class Method Details
.get_protocol_handler_store(proto, agt_id) ⇒ Object
251 252 253 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 251 def PortBase.get_protocol_handler_store(proto, agt_id) return ProtocolHandlerStore.get_store(proto, true, agt_id) end |
.get_ship_store(agt_id) ⇒ Object
247 248 249 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 247 def PortBase.get_ship_store(agt_id) return InboundShipStore.get_store(agt_id) end |
Instance Method Details
#address ⇒ Object
implements Port
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 167 def address() if @socket_path # Unix domain socket return @socket_path elsif @host == nil return [@port, "0.0.0.0"] else return [@port, @host] end end |
#find_city(name) ⇒ Object
183 184 185 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 183 def find_city(name) return @cities.find_city(name) end |
#init(elm, parent) ⇒ Object
Implements Docker
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 70 def init(elm, parent) if StringUtil.empty?(elm.arg) raise ConfigException.new(elm.file_name, elm.line_no, BayMessage.get(:CFG_INVALID_PORT_NAME, elm.name)) end super port_name = elm.arg.downcase() if port_name.start_with?(":unix:") # unix domain sokcet @port = -1 @socket_path = elm.arg[6 .. -1] @host = elm.arg else # TCP or UDP port if port_name.start_with?(":tcp:") # tcp server socket @anchored = true host_port = elm.arg[5 .. -1] elsif port_name.start_with?(":udp:") # udp server socket @anchored = false host_port = elm.arg[5 .. -1] else # default: tcp server socket @anchored = true host_port = elm.arg end begin idx = host_port.index(':') if idx != nil @host = host_port[0 .. idx] @port = host_port[idx+1 .. -1].to_i else @host = nil @port = host_port.to_i end rescue => e raise ConfigException.new(elm.file_name, elm.line_no, BayMessage.get(:CFG_INVALID_PORT_NAME, elm.name)) end if @anchored if !support_anchored() raise ConfigException.new(elm.file_name, elm.line_no, BayMessage.get(:CFG_TCP_NOT_SUPPORTED)) end else if !support_unanchored() raise ConfigException.new(elm.file_name, elm.line_no, BayMessage.get(:CFG_UDP_NOT_SUPPORTED)) end end end end |
#init_docker(dkr) ⇒ Object
Implements DockerBase
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 130 def init_docker(dkr) if dkr.kind_of? Permission .append(dkr) elsif dkr.kind_of? City @cities.add(dkr) elsif dkr.kind_of? Secure @secure_docker = dkr else return super end return true end |
#init_key_val(kv) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 143 def init_key_val(kv) case kv.key.downcase when "timeout" @timeout_sec = Integer(kv.value) when "addheader" idx = kv.value.index(':') if idx == nil raise ConfigException.new(kv.file_name, kv.line_no, BayMessage.get(:CFG_INVALID_PARAMETER_VALUE, kv.value)) end name = kv.value[0, idx].strip value = kv.value[idx+1, kv.value.length].strip @additional_headers << [name, value] else return super end return true end |
#on_connected(agt_id, rd) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 187 def on_connected(agt_id, rd) check_admitted(rd) sip = PortBase.get_ship_store(agt_id).rent() agt = GrandAgent.get(agt_id) if secure() tp = @secure_docker.new_transporter( agt_id, sip, IOUtil.get_sock_recv_buf_size(rd.io)) ssl_socket = tp.new_ssl_socket(rd.io) rd = IORudder.new(ssl_socket) if agt.net_multiplexer.is_non_blocking rd.set_non_blocking end else size = IOUtil.get_sock_recv_buf_size(rd.io) tp = PlainTransporter.new( agt.net_multiplexer, sip, true, size, false) end proto_hnd = PortBase.get_protocol_handler_store(protocol(), agt_id).rent() sip.init_inbound(rd, agt_id, tp, self, proto_hnd) st = RudderStateStore.get_store(agt_id).rent() st.init(rd, tp) agt.net_multiplexer.add_rudder_state(rd, st) agt.net_multiplexer.req_read(rd) end |
#return_protocol_handler(agt_id, proto_hnd) ⇒ Object
226 227 228 229 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 226 def return_protocol_handler(agt_id, proto_hnd) BayLog.debug("%s Return protocol handler", proto_hnd) PortBase.get_protocol_handler_store(proto_hnd.protocol, agt_id).Return(proto_hnd) end |
#return_ship(sip) ⇒ Object
231 232 233 234 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 231 def return_ship(sip) BayLog.debug("%s end (return ship)", sip) PortBase.get_ship_store(sip.agent_id).Return(sip) end |
#secure ⇒ Object
178 179 180 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 178 def secure() return @secure_docker != nil end |
#support_anchored ⇒ Object
Abstract methods
58 59 60 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 58 def support_anchored() raise NotImplementedError.new end |
#support_unanchored ⇒ Object
62 63 64 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 62 def support_unanchored() raise NotImplementedError.new end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/baykit/bayserver/docker/base/port_base.rb', line 51 def to_s() return super + "[#{@port}]" end |