Class: GameMachine::WriteBehindCache

Inherits:
Actor::Base
  • Object
show all
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

Actor::Base::ON_RECEIVE_HOOKS

Instance Attribute Summary collapse

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

#cacheObject (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_secondObject

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

#queueObject (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_intervalObject

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_secondObject



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_intervalObject



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(message)
  if message.is_a?(String)
    handle_scheduled_message(message)
  else
    set_message(message)
    if new_message?(message)
      write(message)
    elsif eligible_for_write?(message)
      write(message)
    else
      enqueue(message.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