Class: Baykit::BayServer::Docker::Base::WarpBase
- Inherits:
-
ClubBase
- Object
- DockerBase
- ClubBase
- Baykit::BayServer::Docker::Base::WarpBase
- Defined in:
- lib/baykit/bayserver/docker/base/warp_base.rb
Defined Under Namespace
Classes: AgentListener
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#host_addr ⇒ Object
readonly
Returns the value of attribute host_addr.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#max_ships ⇒ Object
readonly
Returns the value of attribute max_ships.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#stores ⇒ Object
readonly
Agent ID => WarpShipStore.
-
#timeout_sec ⇒ Object
readonly
Returns the value of attribute timeout_sec.
-
#tour_list ⇒ Object
readonly
Returns the value of attribute tour_list.
-
#warp_base ⇒ Object
readonly
Returns the value of attribute warp_base.
Attributes inherited from ClubBase
#charset, #decode_path_info, #extension, #file_name, #locale
Attributes inherited from DockerBase
Instance Method Summary collapse
-
#arrive(tur) ⇒ Object
Implements Club.
-
#get_ship_store(agent_id) ⇒ Object
Other methods.
-
#init(elm, parent) ⇒ Object
Implements DockerBase.
- #init_key_val(kv) ⇒ Object
-
#initialize ⇒ WarpBase
constructor
Initialize methods.
-
#keep(wsip) ⇒ Object
Implements Warp.
- #new_transporter(agent, rd, ship) ⇒ Object
- #on_end_ship(wsip) ⇒ Object
- #protocol ⇒ Object
-
#secure ⇒ Object
Abstract methods.
Methods included from Docker
Methods inherited from ClubBase
Methods included from Club
#charset, #decode_path_info, #extension, #file_name, #matches
Methods inherited from DockerBase
Constructor Details
#initialize ⇒ WarpBase
Initialize methods
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 74 def initialize super @scheme = nil @host = nil @port = 0 @warp_base = nil @max_ships = -1 @host_addr = nil @tour_list = [] @timeout_sec = -1 # -1 means "Use harbor.socketTimeoutSec" @stores = {} @lock = Mutex.new end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
44 45 46 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 44 def host @host end |
#host_addr ⇒ Object (readonly)
Returns the value of attribute host_addr.
48 49 50 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 48 def host_addr @host_addr end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
51 52 53 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 51 def lock @lock end |
#max_ships ⇒ Object (readonly)
Returns the value of attribute max_ships.
47 48 49 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 47 def max_ships @max_ships end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
45 46 47 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 45 def port @port end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
43 44 45 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 43 def scheme @scheme end |
#stores ⇒ Object (readonly)
Agent ID => WarpShipStore
54 55 56 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 54 def stores @stores end |
#timeout_sec ⇒ Object (readonly)
Returns the value of attribute timeout_sec.
49 50 51 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 49 def timeout_sec @timeout_sec end |
#tour_list ⇒ Object (readonly)
Returns the value of attribute tour_list.
50 51 52 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 50 def tour_list @tour_list end |
#warp_base ⇒ Object (readonly)
Returns the value of attribute warp_base.
46 47 48 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 46 def warp_base @warp_base end |
Instance Method Details
#arrive(tur) ⇒ Object
Implements Club
178 179 180 181 182 183 184 185 186 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 225 226 227 228 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 178 def arrive(tur) agt = GrandAgent.get(tur.ship.agent_id) sto = get_ship_store(agt.agent_id) wsip = sto.rent() if wsip == nil BayLog.warn("%s Busy!", self) raise HttpException.new HttpStatus::INTERNAL_SERVER_ERROR, "WarpDocker busy" end begin BayLog.trace("%s got from store", wsip) need_connect = false if !wsip.initialized if @host_addr[0] == :UNIX skt = Socket.new(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) else skt = Socket.new(@host_addr[1].ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0) end rd = IORudder.new(skt) tp = new_transporter(agt, rd, wsip) proto_hnd = ProtocolHandlerStore.get_store(protocol(), false, agt.agent_id).rent() wsip.init_warp(rd, agt.agent_id, tp, self, proto_hnd) BayLog.debug("%s init warp ship", wsip) BayLog.debug("%s Connect to %s:%d skt=%s", wsip, @host, @port, skt) need_connect = true end @lock.synchronize do @tour_list.append(tur) end wsip.start_warp_tour(tur) if need_connect agt.net_multiplexer.add_rudder_state(wsip.rudder, RudderState.new(wsip.rudder, tp)) agt.net_multiplexer.get_transporter(wsip.rudder).req_connect(wsip.rudder, @host_addr[1]) end rescue SystemCallError => e wsip.end_warp_tour(tur) raise e rescue HttpException => e raise e end end |
#get_ship_store(agent_id) ⇒ Object
Other methods
250 251 252 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 250 def get_ship_store(agent_id) return @stores[agent_id] end |
#init(elm, parent) ⇒ Object
Implements DockerBase
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 92 def init(elm, parent) super if @warp_base == nil @warp_base = "/" end @host_addr = [] if @host && @host.start_with?(":unix:") @host_addr << :UNIX @host_addr << Socket.sockaddr_un(@host[6 .. -1]) @port = -1 else if @port <= 0 @port = 80 end @host_addr << :INET begin addrs = Addrinfo.getaddrinfo(@host, @port, nil, :STREAM) rescue SocketError => e BayLog.error_e(e) raise ConfigException.new(elm.file_name, elm.line_no, "Invalid address: %s:%d", @host, @port) end inet4_addr = nil inet6_addr = nil if addrs addrs.each do |adr| if adr.ipv4? inet4_addr = adr elsif adr.ipv6? inet6_addr = adr end end end if inet4_addr @host_addr << inet4_addr elsif inet6_addr @host_addr << inet6_addr else raise ConfigException.new(elm.file_name, elm.line_no, "Host not found: %s", @host) end end GrandAgent.add_lifecycle_listener(AgentListener.new(self)); BayLog.info("WarpDocker[%s] host=%s port=%d adr=%s", @warp_base, @host, @port, @host_addr) end |
#init_key_val(kv) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 147 def init_key_val(kv) case kv.key.downcase when "destcity" @host = kv.value when "destport" @port = kv.value.to_i when "desttown" @warp_base = kv.value if !@warp_base.end_with?("/") @warp_base += "/" end when "maxships" @max_ships = kv.value.to_i when "timeout" @timeout_sec = kv.value.to_i else return super end return true end |
#keep(wsip) ⇒ Object
Implements Warp
235 236 237 238 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 235 def keep(wsip) BayLog.debug("%s keepShip: %s", self, wsip) get_ship_store(wsip.agent_id).keep(wsip) end |
#new_transporter(agent, rd, ship) ⇒ Object
67 68 69 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 67 def new_transporter(agent, rd, ship) raise NotImplementedError.new end |
#on_end_ship(wsip) ⇒ Object
240 241 242 243 244 245 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 240 def on_end_ship(wsip) BayLog.debug("%s Return protocol handler: ", wsip) get_protocol_handler_store(wsip.agent_id).Return(wsip.protocol_handler) BayLog.debug("%s return ship: %s", self, wsip); get_ship_store(wsip.agent_id).Return(wsip) end |
#protocol ⇒ Object
63 64 65 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 63 def protocol raise NotImplementedError.new end |
#secure ⇒ Object
Abstract methods
59 60 61 |
# File 'lib/baykit/bayserver/docker/base/warp_base.rb', line 59 def secure raise NotImplementedError.new end |