Class: HbaseAdapter::Connection
- Inherits:
-
Object
- Object
- HbaseAdapter::Connection
- Defined in:
- lib/hbase_adapter/connection.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #client ⇒ Object
- #connect! ⇒ Object
- #connected? ⇒ Boolean
- #create_table!(table_name, *column_families) ⇒ Object
- #delete_table!(table_name) ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #table_names ⇒ Object
- #tables ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 |
# File 'lib/hbase_adapter/connection.rb', line 7 def initialize() @host = [:host] || ["host"] @port = [:port] || ["port"] @client = nil end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/hbase_adapter/connection.rb', line 5 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/hbase_adapter/connection.rb', line 5 def port @port end |
Instance Method Details
#client ⇒ Object
18 19 20 21 |
# File 'lib/hbase_adapter/connection.rb', line 18 def client connect! unless connected? @client end |
#connect! ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/hbase_adapter/connection.rb', line 23 def connect! t = Thrift::BufferedTransport.new(Thrift::Socket.new(host, port)) p = Thrift::BinaryProtocol.new(t) c = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(p) t.open @client = c end |
#connected? ⇒ Boolean
14 15 16 |
# File 'lib/hbase_adapter/connection.rb', line 14 def connected? @client end |
#create_table!(table_name, *column_families) ⇒ Object
43 44 45 |
# File 'lib/hbase_adapter/connection.rb', line 43 def create_table!(table_name, *column_families) client.createTable(table_name.to_s, column_families.map {|cd| cd.column_descriptor}) end |
#delete_table!(table_name) ⇒ Object
47 48 49 50 |
# File 'lib/hbase_adapter/connection.rb', line 47 def delete_table!(table_name) client.disableTable(table_name.to_s) client.deleteTable(table_name.to_s) end |
#table_names ⇒ Object
32 33 34 |
# File 'lib/hbase_adapter/connection.rb', line 32 def table_names client.getTableNames end |
#tables ⇒ Object
36 37 38 39 40 41 |
# File 'lib/hbase_adapter/connection.rb', line 36 def tables table_names.inject({}) do|hash, table_name| hash[table_name.to_sym] = HbaseAdapter::Table.new(client, table_name) hash end end |