Class: HbaseClient::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hbase-client/client.rb', line 6

def initialize(opts = {})
  host = opts[:host] || HbaseClient.config[:host]
  port = opts[:port] || HbaseClient.config[:port]

  @logger = opts[:logger] || HbaseClient.config[:logger]
  @socket = ::Thrift::Socket.new(host, port)
  @transport = (opts[:transport] || HbaseClient.config[:transport]).new(@socket)
  @protocol = (opts[:protocol] || HbaseClient.config[:protocol]).new(@transport)
  @client = HbaseClient::Thrift::Hbase::Client.new(@protocol)

  @logger.info "Connected to Hbase Thrift server #{host}:#{port}"
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/hbase-client/client.rb', line 4

def client
  @client
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/hbase-client/client.rb', line 4

def logger
  @logger
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/hbase-client/client.rb', line 23

def close
  @transport.close
end

#exec(method, *args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hbase-client/client.rb', line 27

def exec(method, *args)
  begin
    open
    @logger.info "Executing command #{method.to_s} with args: #{args.join(",")}"
    @client.send(method, *args)
  rescue => e
    @logger.error "#{e.message}"
    raise e
  ensure
    close
  end
end

#multi_execObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hbase-client/client.rb', line 40

def multi_exec
  begin
    open
    yield @client
  rescue => e
    @logger.error "#{e.message}"
    raise e
  ensure
    close
  end
end

#openObject



19
20
21
# File 'lib/hbase-client/client.rb', line 19

def open
  @transport.open
end