Class: HbaseClient::Client
- Inherits:
-
Object
- Object
- HbaseClient::Client
- Defined in:
- lib/hbase-client/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #close ⇒ Object
- #exec(method, *args) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #multi_exec ⇒ Object
- #open ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/hbase-client/client.rb', line 4 def client @client end |
#logger ⇒ Object (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
#close ⇒ Object
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.}" raise e ensure close end end |
#multi_exec ⇒ Object
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.}" raise e ensure close end end |
#open ⇒ Object
19 20 21 |
# File 'lib/hbase-client/client.rb', line 19 def open @transport.open end |