Class: HbaseAdapter::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @host = options[:host] || options["host"]
  @port = options[:port] || options["port"]
  
  @client = nil
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/hbase_adapter/connection.rb', line 5

def host
  @host
end

#portObject (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

#clientObject



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

Returns:

  • (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_namesObject



32
33
34
# File 'lib/hbase_adapter/connection.rb', line 32

def table_names
  client.getTableNames
end

#tablesObject



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