Class: PbActor::Proxy
- Inherits:
-
BasicProxy
- Object
- BasicProxy
- PbActor::Proxy
- Defined in:
- lib/pb_actor/proxy.rb
Instance Method Summary collapse
- #async ⇒ Object
- #future ⇒ Object
-
#initialize(origin) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method, *args, &blk) ⇒ Object
- #terminate ⇒ Object
- #terminate! ⇒ Object
Methods inherited from BasicProxy
Constructor Details
#initialize(origin) ⇒ Proxy
Returns a new instance of Proxy.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pb_actor/proxy.rb', line 51 def initialize origin @origin = origin pr, cw = IO.pipe cr, pw = IO.pipe @pid = fork do [pr, pw].each &:close @future_values = {} loop do type, id, method, *args = begin Message.recv cr rescue EOFError => e [:terminate] end case type when :async_method_call @origin.public_send method, *args when :future_method_call @future_values[id] = @origin.public_send method, *args when :future_value_get Message.send(if @future_values.has_key? id [:future_value, @future_values.delete(id)] else [:no_value] end, cw) when :terminate exit else raise "what happend!? receive #{type.inspect}" end end end [cr, cw].each &:close @rd = pr @wr = pw end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
87 88 89 90 |
# File 'lib/pb_actor/proxy.rb', line 87 def method_missing method, *args, &blk super future.method_missing(method, *args).value end |
Instance Method Details
#async ⇒ Object
92 93 94 |
# File 'lib/pb_actor/proxy.rb', line 92 def async AsyncProxy.new @origin, @pid, @wr, @rd end |
#future ⇒ Object
96 97 98 |
# File 'lib/pb_actor/proxy.rb', line 96 def future FutureProxy.new @origin, @pid, @wr, @rd end |
#terminate ⇒ Object
100 101 102 103 104 |
# File 'lib/pb_actor/proxy.rb', line 100 def terminate Message.send [:terminate], @wr Process.wait @pid nil end |
#terminate! ⇒ Object
106 107 108 109 110 |
# File 'lib/pb_actor/proxy.rb', line 106 def terminate! Process.kill "KILL", @pid Process.wait @pid nil end |