Class: GameMachine::WriteBehindCache
- Inherits:
-
Actor::Base
- Object
- JavaLib::GameActor
- Actor::Base
- GameMachine::WriteBehindCache
- Defined in:
- lib/game_machine/write_behind_cache.rb
Constant Summary collapse
- WRITE_COUNT =
java.util.concurrent.atomic.AtomicInteger.new
Constants inherited from Actor::Base
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#max_writes_per_second ⇒ Object
Returns the value of attribute max_writes_per_second.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#write_interval ⇒ Object
Returns the value of attribute write_interval.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Actor::Base
aspect, aspects, find, find_by_address, find_distributed, find_distributed_local, find_remote, hashring, local_path, model_filter, #onReceive, player_controller, #receive_message, #schedule_message, #sender, set_player_controller
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
23 24 25 |
# File 'lib/game_machine/write_behind_cache.rb', line 23 def cache @cache end |
#max_writes_per_second ⇒ Object
Returns the value of attribute max_writes_per_second.
22 23 24 |
# File 'lib/game_machine/write_behind_cache.rb', line 22 def max_writes_per_second @max_writes_per_second end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
23 24 25 |
# File 'lib/game_machine/write_behind_cache.rb', line 23 def queue @queue end |
#write_interval ⇒ Object
Returns the value of attribute write_interval.
22 23 24 |
# File 'lib/game_machine/write_behind_cache.rb', line 22 def write_interval @write_interval end |
Class Method Details
.max_writes_per_second ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/game_machine/write_behind_cache.rb', line 6 def self.max_writes_per_second if @max_writes_per_second @max_writes_per_second else @max_writes_per_second = Application.config.datastore.cache_writes_per_second end end |
.write_interval ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/game_machine/write_behind_cache.rb', line 14 def self.write_interval if @write_interval @write_interval else @write_interval = Application.config.datastore.cache_write_interval end end |
Instance Method Details
#on_receive(message) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/game_machine/write_behind_cache.rb', line 42 def on_receive() if .is_a?(String) () else () if () write() elsif eligible_for_write?() write() else enqueue(.id) end end end |
#post_init(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/game_machine/write_behind_cache.rb', line 25 def post_init(*args) @write_interval = self.class.write_interval @max_writes_per_second = self.class.max_writes_per_second @store = DataStore.instance @cache = {} @updates = {} @queue = [] @queue_map = {} @last_write = current_time - (120 * 1000) @scheduler = get_context.system.scheduler @dispatcher = get_context.system.dispatcher unless @write_interval == -1 && @max_writes_per_second == -1 schedule_queue_run schedule_queue_stats end end |