Class: Baykit::BayServer::Ships::Ship

Inherits:
Object
  • Object
show all
Includes:
Util, Util::Reusable
Defined in:
lib/baykit/bayserver/ships/ship.rb

Constant Summary collapse

SHIP_ID_NOCHECK =
-1
INVALID_SHIP_ID =
0

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShip

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_counterObject (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_counterObject (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_idObject (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

#initializedObject (readonly)

Returns the value of attribute initialized.



29
30
31
# File 'lib/baykit/bayserver/ships/ship.rb', line 29

def initialized
  @initialized
end

#keepingObject

Returns the value of attribute keeping.



30
31
32
# File 'lib/baykit/bayserver/ships/ship.rb', line 30

def keeping
  @keeping
end

#object_idObject (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

#rudderObject (readonly)

Returns the value of attribute rudder.



27
28
29
# File 'lib/baykit/bayserver/ships/ship.rb', line 27

def rudder
  @rudder
end

#ship_idObject (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

#transporterObject (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

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/baykit/bayserver/ships/ship.rb', line 121

def check_timeout(duration_sec)
  raise NotImplementedError.new
end

#idObject

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_closeObject

Raises:

  • (NotImplementedError)


117
118
119
# File 'lib/baykit/bayserver/ships/ship.rb', line 117

def notify_close
  raise NotImplementedError.new
end

#notify_connectObject

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/baykit/bayserver/ships/ship.rb', line 97

def notify_connect()
  raise NotImplementedError.new
end

#notify_eofObject

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/baykit/bayserver/ships/ship.rb', line 105

def notify_eof()
  raise NotImplementedError.new
end

#notify_error(e) ⇒ Object

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


101
102
103
# File 'lib/baykit/bayserver/ships/ship.rb', line 101

def notify_read(buf)
  raise NotImplementedError.new
end

#post_closeObject



86
87
88
# File 'lib/baykit/bayserver/ships/ship.rb', line 86

def post_close
  @transporter.req_close(@rudder)
end

#resetObject

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