Class: GameMachine::Actor::Ref

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/actor/ref.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_or_actor_ref, metric_name = nil) ⇒ Ref


6
7
8
9
# File 'server/lib/game_machine/actor/ref.rb', line 6

def initialize(path_or_actor_ref,metric_name=nil)
  @path_or_actor_ref = path_or_actor_ref
  @metric_name = metric_name
end

Instance Method Details

#actorObject


23
24
25
# File 'server/lib/game_machine/actor/ref.rb', line 23

def actor
  @actor ||= @path_or_actor_ref.is_a?(JavaLib::ActorRef) ? @path_or_actor_ref : actor_selection
end

#ask(message, timeout) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'server/lib/game_machine/actor/ref.rb', line 37

def ask(message,timeout)
  message = convert_if_model(message)
  duration = duration_in_ms(timeout)
  t = Java::AkkaUtil.Timeout.new(duration)
  if actor.is_a?(JavaLib::ActorSelection)
    sel = Java::AkkaPattern::AskableActorSelection.new(actor)
    future = sel.ask(message,t)
  else
    future = Java::AkkaPattern.Patterns::ask(actor,message,t)
  end
  Java::ScalaConcurrent.Await.result(future, duration)
rescue Exception => e #Java::JavaUtilConcurrent::TimeoutException => e
  if message.is_a?(MessageLib::ObjectdbGet)
    logmsg = "ObjectDbGet entity_id=#{message.entity_id} klass=#{message.klass}"
  else
    logmsg = message
  end
  GameMachine.logger.debug("#{e.message} to=#{@path_or_actor_ref} message=#{logmsg}")
  false
end

#pathObject


27
28
29
# File 'server/lib/game_machine/actor/ref.rb', line 27

def path
  @path_or_actor_ref.is_a?(String) ? @path_or_actor_ref : nil
end

#send_message(message, options = {}) ⇒ Object


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

def send_message(message,options={})
  options = default_options.merge(options)
  sender = sender_for(options[:sender])

  if options[:blocking]
    ask(message,options[:timeout])
  else
    tell(message,sender)
    true
  end
end

#tell(message, sender = nil) ⇒ Object


31
32
33
34
35
# File 'server/lib/game_machine/actor/ref.rb', line 31

def tell(message,sender=nil)
  message = convert_if_model(message)
  actor.tell(message,sender_for(sender))
  true
end