Class: PbActor::BasicProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/pb_actor/proxy.rb

Direct Known Subclasses

AsyncProxy, FutureProxy, Proxy

Instance Method Summary collapse

Constructor Details

#initialize(origin, pid, wr, rd) ⇒ BasicProxy

Returns a new instance of BasicProxy.



23
24
25
# File 'lib/pb_actor/proxy.rb', line 23

def initialize origin, pid, wr, rd
  @origin, @pid, @wr, @rd = origin, pid, wr, rd
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
# File 'lib/pb_actor/proxy.rb', line 38

def method_missing method, *args, &blk
  raise ArgumentError, 'actor not support block' if blk
  raise DeadActorError, 'dead actor call' unless alive?
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'lib/pb_actor/proxy.rb', line 27

def alive?
  begin
    # Have any other way to check a process status?
    timeout(0.001){Process.wait}
  rescue Timeout::Error => e
  end
  Process.kill(0, @pid) == 1
rescue Errno::ESRCH, Errno::ECHILD => e
  false
end

#to_sObject



43
44
45
# File 'lib/pb_actor/proxy.rb', line 43

def to_s
  "#{self.class}(#{@origin.class})"
end