Class: EMRPC::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/emrpc/client.rb

Constant Summary collapse

DEFAULT_TIMEOUT =

5 sec.

5
DEFAULT_PROTOCOL =

Default EventMachine connection protocol

:ClientProtocol
DEFAULT_CONNECTIONS =

10 threads can operate concurrently, others will wait.

10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
# File 'lib/emrpc/client.rb', line 17

def initialize(options = {})
  @host     = options[:host] or raise ":host required!"
  @port     = options[:port] or raise ":port required!"
  @timeout  = options[:timeout] || DEFAULT_TIMEOUT
  @protocol = options[:protocol] || DEFAULT_PROTOCOL 
  @connections = Array.new(options.delete(:connections) || DEFAULT_CONNECTIONS) do 
    ClientConnection.new(options)
  end
end

Instance Attribute Details

#connectionsObject (readonly)

Returns the value of attribute connections.



7
8
9
# File 'lib/emrpc/client.rb', line 7

def connections
  @connections
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/emrpc/client.rb', line 7

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/emrpc/client.rb', line 7

def port
  @port
end

#protocolObject (readonly)

Returns the value of attribute protocol.



7
8
9
# File 'lib/emrpc/client.rb', line 7

def protocol
  @protocol
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/emrpc/client.rb', line 7

def timeout
  @timeout
end

Class Method Details

.new(*args, &blk) ⇒ Object

Create a regular object holding configuration, but returns a method proxy.



10
11
12
13
14
15
# File 'lib/emrpc/client.rb', line 10

def self.new(*args, &blk)
  client = super(*args)
  backend = MultithreadedClient.new(:backends => client.connections, 
                                    :timeout => client.timeout)
  MethodProxy.new(backend)
end