Class: Baykit::BayServer::Ships::Ship
- Inherits:
-
Object
- Object
- Baykit::BayServer::Ships::Ship
- Includes:
- Util, Util::Reusable
- Defined in:
- lib/baykit/bayserver/ships/ship.rb
Direct Known Subclasses
Agent::CommandReceiver, Common::InboundShip, Common::ReadOnlyShip, Common::WarpShip
Constant Summary collapse
- SHIP_ID_NOCHECK =
-1- INVALID_SHIP_ID =
0
Class Attribute Summary collapse
-
.oid_counter ⇒ Object
readonly
Returns the value of attribute oid_counter.
-
.ship_id_counter ⇒ Object
readonly
Returns the value of attribute ship_id_counter.
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#initialized ⇒ Object
readonly
Returns the value of attribute initialized.
-
#keeping ⇒ Object
Returns the value of attribute keeping.
-
#object_id ⇒ Object
readonly
Returns the value of attribute object_id.
-
#rudder ⇒ Object
readonly
Returns the value of attribute rudder.
-
#ship_id ⇒ Object
readonly
Returns the value of attribute ship_id.
-
#transporter ⇒ Object
readonly
Returns the value of attribute transporter.
Instance Method Summary collapse
- #check_ship_id(check_id) ⇒ Object
- #check_timeout(duration_sec) ⇒ Object
-
#id ⇒ Object
Other methods.
- #init(agt_id, rd, tp) ⇒ Object
-
#initialize ⇒ Ship
constructor
A new instance of Ship.
- #notify_close ⇒ Object
- #notify_connect ⇒ Object
- #notify_eof ⇒ Object
- #notify_error(e) ⇒ Object
-
#notify_handshake_done(proto) ⇒ Object
Abstract methods.
- #notify_protocol_error(e) ⇒ Object
- #notify_read(buf) ⇒ Object
- #post_close ⇒ Object
-
#reset ⇒ Object
implements Reusable.
- #resume_read(check_id) ⇒ Object
Constructor Details
#initialize ⇒ Ship
Returns a new instance of Ship.
32 33 34 35 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 32 def initialize() @object_id = Ship.oid_counter.next @ship_id = INVALID_SHIP_ID end |
Class Attribute Details
.oid_counter ⇒ Object (readonly)
Returns the value of attribute oid_counter.
14 15 16 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 14 def oid_counter @oid_counter end |
.ship_id_counter ⇒ Object (readonly)
Returns the value of attribute ship_id_counter.
15 16 17 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 15 def ship_id_counter @ship_id_counter end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
26 27 28 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 26 def agent_id @agent_id end |
#initialized ⇒ Object (readonly)
Returns the value of attribute initialized.
29 30 31 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 29 def initialized @initialized end |
#keeping ⇒ Object
Returns the value of attribute keeping.
30 31 32 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 30 def keeping @keeping end |
#object_id ⇒ Object (readonly)
Returns the value of attribute object_id.
24 25 26 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 24 def object_id @object_id end |
#rudder ⇒ Object (readonly)
Returns the value of attribute rudder.
27 28 29 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 27 def rudder @rudder end |
#ship_id ⇒ Object (readonly)
Returns the value of attribute ship_id.
25 26 27 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 25 def ship_id @ship_id end |
#transporter ⇒ Object (readonly)
Returns the value of attribute transporter.
28 29 30 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 28 def transporter @transporter end |
Instance Method Details
#check_ship_id(check_id) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 72 def check_ship_id(check_id) if !@initialized raise Sink.new("#{self} ship not initialized (might be returned ship): #{check_id}") end if check_id != SHIP_ID_NOCHECK && check_id != @ship_id raise Sink.new("#{self} Invalid ship id (might be returned ship): #{check_id}") end end |
#check_timeout(duration_sec) ⇒ Object
121 122 123 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 121 def check_timeout(duration_sec) raise NotImplementedError.new end |
#id ⇒ Object
Other methods
68 69 70 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 68 def id() @ship_id end |
#init(agt_id, rd, tp) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 37 def init(agt_id, rd, tp) if @initialized raise Sink.new("Ship already initialized") end @ship_id = Ship.ship_id_counter.next @agent_id = agt_id @rudder = rd @transporter = tp @initialized = true BayLog.debug("%s initialized", self) end |
#notify_close ⇒ Object
117 118 119 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 117 def notify_close raise NotImplementedError.new end |
#notify_connect ⇒ Object
97 98 99 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 97 def notify_connect() raise NotImplementedError.new end |
#notify_eof ⇒ Object
105 106 107 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 105 def notify_eof() raise NotImplementedError.new end |
#notify_error(e) ⇒ Object
109 110 111 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 109 def notify_error(e) raise NotImplementedError.new end |
#notify_handshake_done(proto) ⇒ Object
Abstract methods
93 94 95 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 93 def notify_handshake_done(proto) raise NotImplementedError.new end |
#notify_protocol_error(e) ⇒ Object
113 114 115 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 113 def notify_protocol_error(e) raise NotImplementedError.new end |
#notify_read(buf) ⇒ Object
101 102 103 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 101 def notify_read(buf) raise NotImplementedError.new end |
#post_close ⇒ Object
86 87 88 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 86 def post_close @transporter.req_close(@rudder) end |
#reset ⇒ Object
implements Reusable
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 52 def reset() BayLog.debug("%s reset", self) @initialized = false @transporter = nil @rudder = nil @agent_id = -1 @ship_id = INVALID_SHIP_ID @keeping = false end |
#resume_read(check_id) ⇒ Object
81 82 83 84 |
# File 'lib/baykit/bayserver/ships/ship.rb', line 81 def resume_read(check_id) check_ship_id(check_id); @transporter.req_read(@rudder) end |