Class: GameMachine::MessageQueue

Inherits:
Actor::Base
  • Object
show all
Defined in:
server/lib/game_machine/message_queue.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

#fetch_mediator(game_id) ⇒ Object


11
12
13
14
15
16
17
# File 'server/lib/game_machine/message_queue.rb', line 11

def fetch_mediator(game_id)
  if getContext.system.name == 'cluster'
    JavaLib::ChatMediator.get_instance.get(game_id)
  else
    nil
  end
end

#on_receive(message) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'server/lib/game_machine/message_queue.rb', line 19

def on_receive(message)
  if message.is_a?(MessageLib::Publish)
    mediator = fetch_mediator(message.get_game_id)
    publish(mediator,message)
  elsif message.is_a?(MessageLib::Subscribe)
    mediator = fetch_mediator(message.get_game_id)
    subscribe(mediator,message)
  elsif message.is_a?(MessageLib::Unsubscribe)
    mediator = fetch_mediator(message.get_game_id)
    unsubscribe(mediator,message)
  elsif message.is_a?(JavaLib::DistributedPubSubMediator::SubscribeAck)
    GameMachine.logger.debug "Subscribed"
  else
    unhandled(message)
  end
end

#preStartObject


4
5
6
7
8
9
# File 'server/lib/game_machine/message_queue.rb', line 4

def preStart
  # Ensure system mediator is running
  if getContext.system.name == 'cluster'
    JavaLib::ChatMediator.get_instance.get('system')
  end
end