Class: Baykit::BayServer::Common::WarpShipStore
- Inherits:
-
Util::ObjectStore
- Object
- Util::ObjectStore
- Baykit::BayServer::Common::WarpShipStore
- Includes:
- Baykit::BayServer::Common, Protocol, Util
- Defined in:
- lib/baykit/bayserver/common/warp_ship_store.rb
Instance Attribute Summary collapse
-
#busy_list ⇒ Object
readonly
Returns the value of attribute busy_list.
-
#keep_list ⇒ Object
readonly
Returns the value of attribute keep_list.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#max_ships ⇒ Object
readonly
Returns the value of attribute max_ships.
Attributes inherited from Util::ObjectStore
#active_list, #factory, #free_list
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(max_ships) ⇒ WarpShipStore
constructor
A new instance of WarpShipStore.
- #keep(wsip) ⇒ Object
- #print_usage(indent) ⇒ Object
- #rent ⇒ Object
- #Return(wsip) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Util::ObjectStore
Constructor Details
#initialize(max_ships) ⇒ WarpShipStore
Returns a new instance of WarpShipStore.
18 19 20 21 22 23 24 25 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 18 def initialize(max_ships) super() @keep_list = [] @busy_list = [] @lock = Mutex.new @max_ships = max_ships @factory = -> { WarpShip.new() } end |
Instance Attribute Details
#busy_list ⇒ Object (readonly)
Returns the value of attribute busy_list.
13 14 15 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 13 def busy_list @busy_list end |
#keep_list ⇒ Object (readonly)
Returns the value of attribute keep_list.
12 13 14 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 12 def keep_list @keep_list end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
16 17 18 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 16 def lock @lock end |
#max_ships ⇒ Object (readonly)
Returns the value of attribute max_ships.
15 16 17 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 15 def max_ships @max_ships end |
Instance Method Details
#count ⇒ Object
83 84 85 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 83 def count() @keep_list.length + @busy_list.length end |
#keep(wsip) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 57 def keep(wsip) BayLog.trace("keep: before keepList=%s busyList=%s", @keep_list, @busy_list) if !@busy_list.delete(wsip) BayLog.error("%s not in busy list", wsip) end @keep_list.append(wsip) BayLog.trace("keep: after keepList=%s busyList=%s", @keep_list, @busy_list) end |
#print_usage(indent) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 87 def print_usage(indent) BayLog.info("%sWarpShipStore Usage:", StringUtil.indent(indent)) BayLog.info("%skeepList: %d", StringUtil.indent(indent+1), @keep_list.length()) if BayLog.debug_mode? @keep_list.each do |obj| BayLog.debug("%s%s", StringUtil.indent(indent+1), obj) end end BayLog.info("%sbusyList: %d", StringUtil.indent(indent+1), @busy_list.length()) if BayLog.debug_mode? @busy_list.each do |obj| BayLog.debug("%s%s", StringUtil.indent(indent+1), obj) end end super end |
#rent ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 31 def rent() if @max_ships > 0 && count() >= @max_ships return nil end if @keep_list.empty? BayLog.debug("rent from Object Store") wsip = super() if wsip == nil return nil end else BayLog.trace("rent from keep list: %s", @keep_list) wsip = @keep_list.delete_at(@keep_list.length - 1) end if wsip == nil raise Sink.new("BUG! ship is null") end @busy_list.append(wsip) BayLog.trace(" rent keepList=%s busyList=%s", @keep_list, @busy_list) return wsip end |
#Return(wsip) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 69 def Return(wsip) BayLog.trace("Return: before keepList=%s busyList=%s", @keep_list, @busy_list) removed_from_keep = @keep_list.delete(wsip) removed_from_busy = @busy_list.delete(wsip) if !removed_from_keep && !removed_from_busy BayLog.error("%s not in both keep list and busy list", wsip) end super BayLog.trace("Return: after keepList=%s busyList=%s", @keep_list, @busy_list) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/baykit/bayserver/common/warp_ship_store.rb', line 27 def to_s return "warp_ship_store" end |