Class: Arpie::ProxyClient

Inherits:
RPCClient show all
Defined in:
lib/arpie/proxy.rb

Overview

A Proxy is a wrapper around a Client, which transparently tunnels method calls to the remote ProxyServer. Note that the methods of Client cannot be proxied.

Instance Attribute Summary collapse

Attributes inherited from Client

#connect_retry, #connect_sleep, #protocol

Instance Method Summary collapse

Methods inherited from RPCClient

#post_call, #pre_call, #request

Methods inherited from Client

#connect, #io_retry, #on_error, #read_message, #write_message

Constructor Details

#initialize(*protocols) ⇒ ProxyClient

Returns a new instance of ProxyClient.



85
86
87
88
89
90
91
# File 'lib/arpie/proxy.rb', line 85

def initialize *protocols
  super
  @protocol, @namespace = protocol, ""
  @uuid_generator = lambda {|client, method, argv|
    UUID.random_create.to_i
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *argv) ⇒ Object

:nodoc:



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/arpie/proxy.rb', line 105

def method_missing meth, *argv # :nodoc:
  uuid = @uuid_generator ?
    @uuid_generator.call(self, meth, argv) : nil

  call = Arpie::RPCall.new(@namespace, meth, argv, uuid)
  ret = self.request(call)
  case ret
    when Exception
      raise ret
    else
      ret
  end
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



83
84
85
# File 'lib/arpie/proxy.rb', line 83

def namespace
  @namespace
end

Instance Method Details

#uuid_generator(&handler) ⇒ Object

Set up a new UUID generator for this proxy client. Make sure that this yields really random numbers. The default uses the uuidtools gem and is usually okay. You can simply set this to nil (by calling it without a block).

Note that disabling this disables replay protection.



100
101
102
103
# File 'lib/arpie/proxy.rb', line 100

def uuid_generator &handler #:yields: client, method, argv
  @uuid_generator = handler
  self
end