Class: Zoidberg::SoftShell::AsyncProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/zoidberg/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locked_async, proxy) ⇒ AsyncProxy

Returns a new instance of AsyncProxy.



34
35
36
37
38
# File 'lib/zoidberg/shell.rb', line 34

def initialize(locked_async, proxy)
  @locked = locked_async
  @origin_proxy = proxy
  @target = proxy._raw_instance
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zoidberg/shell.rb', line 39

def method_missing(*args, &block)
  origin_proxy._thread_pool << lambda{
    got_lock = false
    begin
      origin_proxy._aquire_lock! if locked
      got_lock = locked
      target.send(*args, &block)
    rescue Zoidberg::DeadException => e
      if(e.origin_object_id == target.object_id)
        got_lock = false
      end
      raise
    rescue StandardError, ScriptError => e
      origin_proxy._zoidberg_unexpected_error(e)
      raise
    ensure
      origin_proxy._release_lock! if got_lock
    end
  }
  nil
end

Instance Attribute Details

#lockedObject (readonly)

Returns the value of attribute locked.



31
32
33
# File 'lib/zoidberg/shell.rb', line 31

def locked
  @locked
end

#origin_proxyObject (readonly)

Returns the value of attribute origin_proxy.



33
34
35
# File 'lib/zoidberg/shell.rb', line 33

def origin_proxy
  @origin_proxy
end

#targetObject (readonly)

Returns the value of attribute target.



32
33
34
# File 'lib/zoidberg/shell.rb', line 32

def target
  @target
end