Class: BERT::Client

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

Defined Under Namespace

Classes: BadData, BadHeader, InvalidResponse, NoSuchFunction, NoSuchModule, RPCError, UnknownError, UserError

Constant Summary collapse

GZIP_BERP =
t[:info, :encoding, [t[:gzip]]
ACCEPT_ENCODING_BERP =
t[:info, :accept_encoding, [t[:gzip]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bertclient.rb', line 21

def initialize(opts={}, &block)
  @host = opts[:host] || 'localhost'
  @port = opts[:port] || 9999
  @timeout = opts[:timeout] || 15

  @gzip = opts[:gzip] || false
  @gzip_threshold = opts[:gzip_threshold] || 1024 # bytes
  @gzip_accept_sent = false

  @ssl = opts[:ssl] || false
  @verify_ssl = opts.has_key?(:verify_ssl) ? opts[:verify_ssl] : true

  @socket = get_socket_or_create Thread.current
  
  execute(&block) if block_given?
end

Class Method Details

.create_berp(data) ⇒ Object

Accepts a string and returns a berp



218
219
220
# File 'lib/bertclient.rb', line 218

def create_berp(data)
  [[data.bytesize].pack('N'), data].join
end

.del_socket(thread) ⇒ Object



231
232
233
# File 'lib/bertclient.rb', line 231

def del_socket thread
  @socket_pool.delete thread
end

.get_socket(thread) ⇒ Object



222
223
224
# File 'lib/bertclient.rb', line 222

def get_socket thread
  @socket_pool[thread]
end

.set_socket(sock, thread) ⇒ Object



226
227
228
229
# File 'lib/bertclient.rb', line 226

def set_socket sock, thread
  @socket_pool[thread] = sock
  @socket_pool[thread]
end

Instance Method Details

#call(mod, fun, *args) ⇒ Object



38
39
40
41
42
43
# File 'lib/bertclient.rb', line 38

def call(mod, fun, *args)
  response = cast_or_call(:call, mod, fun, *args)
  return response[1] if response[0] == :reply

  handle_error(response)
end

#cast(mod, fun, *args) ⇒ Object



45
46
47
48
49
50
# File 'lib/bertclient.rb', line 45

def cast(mod, fun, *args)
  response = cast_or_call(:cast, mod, fun, *args)
  return nil if response[0] == :noreply

  handle_error(response)
end