Class: MassiveRecord::Wrapper::Connection
- Inherits:
-
Object
- Object
- MassiveRecord::Wrapper::Connection
show all
- Defined in:
- lib/massive_record/wrapper/connection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Connection
Returns a new instance of Connection.
7
8
9
10
11
|
# File 'lib/massive_record/wrapper/connection.rb', line 7
def initialize(opts = {})
@timeout = 4000
@host = opts[:host]
@port = opts[:port] || 9090
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Wrapp HBase API to be able to catch errors and try reconnect
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/massive_record/wrapper/connection.rb', line 53
def method_missing(method, *args)
begin
open if not @client
client.send(method, *args) if @client
rescue IOError
@client = nil
open
client.send(method, *args) if @client
rescue Thrift::TransportException
@transport = nil
@client = nil
open
client.send(method, *args) if @client
end
end
|
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5
6
7
|
# File 'lib/massive_record/wrapper/connection.rb', line 5
def host
@host
end
|
#port ⇒ Object
Returns the value of attribute port.
5
6
7
|
# File 'lib/massive_record/wrapper/connection.rb', line 5
def port
@port
end
|
#timeout ⇒ Object
Returns the value of attribute timeout.
5
6
7
|
# File 'lib/massive_record/wrapper/connection.rb', line 5
def timeout
@timeout
end
|
Instance Method Details
#active? ⇒ Boolean
37
38
39
|
# File 'lib/massive_record/wrapper/connection.rb', line 37
def active?
@transport.open?
end
|
#client ⇒ Object
33
34
35
|
# File 'lib/massive_record/wrapper/connection.rb', line 33
def client
@client
end
|
#close ⇒ Object
29
30
31
|
# File 'lib/massive_record/wrapper/connection.rb', line 29
def close
@transport.close.nil?
end
|
#load_table(table_name) ⇒ Object
48
49
50
|
# File 'lib/massive_record/wrapper/connection.rb', line 48
def load_table(table_name)
MassiveRecord::Wrapper::Table.new(self, table_name)
end
|
#open ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/massive_record/wrapper/connection.rb', line 17
def open
protocol = Thrift::BinaryProtocol.new(transport)
@client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
begin
transport.open()
true
rescue
raise MassiveRecord::ConnectionException.new, "Unable to connect to HBase on #{@host}, port #{@port}"
end
end
|
#tables ⇒ Object
41
42
43
44
45
46
|
# File 'lib/massive_record/wrapper/connection.rb', line 41
def tables
collection = TablesCollection.new
collection.connection = self
getTableNames().each{|table_name| collection.push(table_name)}
collection
end
|
#transport ⇒ Object
13
14
15
|
# File 'lib/massive_record/wrapper/connection.rb', line 13
def transport
@transport ||= Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port, @timeout))
end
|