Class: GameMachine::Actor::Ref
- Inherits:
-
Object
- Object
- GameMachine::Actor::Ref
- Defined in:
- server/lib/game_machine/actor/ref.rb
Instance Method Summary collapse
- #actor ⇒ Object
- #ask(message, timeout) ⇒ Object
-
#initialize(path_or_actor_ref, metric_name = nil) ⇒ Ref
constructor
A new instance of Ref.
- #path ⇒ Object
- #send_message(message, options = {}) ⇒ Object
- #tell(message, sender = nil) ⇒ Object
Constructor Details
#initialize(path_or_actor_ref, metric_name = nil) ⇒ Ref
Returns a new instance of 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
#actor ⇒ Object
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(,timeout) = convert_if_model() 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(,t) else future = Java::AkkaPattern.Patterns::ask(actor,,t) end Java::ScalaConcurrent.Await.result(future, duration) rescue Exception => e #Java::JavaUtilConcurrent::TimeoutException => e if .is_a?(MessageLib::ObjectdbGet) logmsg = "ObjectDbGet entity_id=#{.entity_id} klass=#{.klass}" else logmsg = end GameMachine.logger.debug("#{e.} to=#{@path_or_actor_ref} message=#{logmsg}") false end |
#path ⇒ Object
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 (,={}) = .merge() sender = sender_for([:sender]) if [:blocking] ask(,[:timeout]) else tell(,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(,sender=nil) = convert_if_model() actor.tell(,sender_for(sender)) true end |