Class: Arpie::ProxyClient
- 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
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#replay_protection ⇒ Object
Set to false to disable replay protection.
-
#serial ⇒ Object
The current serial for this transport.
-
#uuid ⇒ Object
The generated uuid for this Client.
Attributes inherited from Client
#connect_retry, #connect_sleep, #protocol
Instance Method Summary collapse
-
#initialize(*protocols) ⇒ ProxyClient
constructor
A new instance of ProxyClient.
-
#method_missing(meth, *argv) ⇒ Object
:nodoc:.
-
#uuid_generator(&handler) ⇒ Object
Set up a new UUID generator for this proxy client.
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.
104 105 106 107 108 109 110 111 112 |
# File 'lib/arpie/proxy.rb', line 104 def initialize *protocols super @protocol, @namespace = protocol, "" @serial = 0 @uuid_generator = lambda {|client, method, argv| UUIDTools::UUID.random_create.to_i } @replay_protection = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *argv) ⇒ Object
:nodoc:
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/arpie/proxy.rb', line 124 def method_missing meth, *argv # :nodoc: serial = nil if @replay_protection serial = [ @uuid ||= @uuid_generator.call(self, meth, argv), @serial += 1 ] end call = Arpie::RPCall.new(@namespace, meth, argv, serial) ret = self.request(call) case ret when Exception raise ret else ret end end |
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
91 92 93 |
# File 'lib/arpie/proxy.rb', line 91 def namespace @namespace end |
#replay_protection ⇒ Object
Set to false to disable replay protection. Default is true.
95 96 97 |
# File 'lib/arpie/proxy.rb', line 95 def replay_protection @replay_protection end |
#serial ⇒ Object
The current serial for this transport.
98 99 100 |
# File 'lib/arpie/proxy.rb', line 98 def serial @serial end |
#uuid ⇒ Object
The generated uuid for this Client. nil if no call has been made yet.
102 103 104 |
# File 'lib/arpie/proxy.rb', line 102 def uuid @uuid 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.
This gets called exactly once for each created ProxyClient.
119 120 121 122 |
# File 'lib/arpie/proxy.rb', line 119 def uuid_generator &handler #:yields: client, method, argv @uuid_generator = handler self end |