Class: GameMachine::GridReplicator

Inherits:
Actor::Base
  • Object
show all
Defined in:
server/lib/game_machine/grid_replicator.rb

Constant Summary

Constants inherited from Actor::Base

Actor::Base::ON_RECEIVE_HOOKS

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, logger, model_filter, #onReceive, player_controller, #receive_message, #schedule_message, #schedule_message_once, #sender, set_player_controller

Instance Method Details

#on_receive(message) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'server/lib/game_machine/grid_replicator.rb', line 9

def on_receive(message)
  if message.is_a?(String)
    delta = Grid.default_grid.current_delta
    return if delta.length == 0
    GameMachine::ClusterMonitor.remote_members.keys.each do |address|
      @paths[address] ||= "#{address}#{self.class.local_path(self.class.name)}"
      Actor::Ref.new(@paths[address],self.class.name).tell(delta)
    end
  else
    Grid.default_grid.update_from_delta(message)
  end
  
end

#post_init(*args) ⇒ Object


4
5
6
7
# File 'server/lib/game_machine/grid_replicator.rb', line 4

def post_init(*args)
  @paths = {}
  #schedule_update(80)
end

#schedule_update(update_interval) ⇒ Object


23
24
25
26
27
28
# File 'server/lib/game_machine/grid_replicator.rb', line 23

def schedule_update(update_interval)
  duration = GameMachine::JavaLib::Duration.create(update_interval, java.util.concurrent.TimeUnit::MILLISECONDS)
  scheduler = get_context.system.scheduler
  dispatcher = get_context.system.dispatcher
  scheduler.schedule(duration, duration, get_self, "replicate_grid", dispatcher, nil)
end