Skip to content

Commit

Permalink
Added reconnect logic to latest branch of rhino
Browse files Browse the repository at this point in the history
  • Loading branch information
drujensen authored and sqs committed Jul 30, 2010
1 parent 93ef2e7 commit 5e3db71
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/rhino/interface/hbase-thrift/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Rhino
module HBaseThriftInterface
class Base < Rhino::Interface::Base
THRIFT_RETRY_COUNT = 3
attr_reader :host, :port, :client

def initialize(host, port)
Expand All @@ -16,14 +17,41 @@ def connect
@client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
transport.open()
end

def connect
count = 1
while @client == nil and count < THRIFT_RETRY_COUNT
transport = TBufferedTransport.new(TSocket.new(host, port))
protocol = TBinaryProtocol.new(transport)
@client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
begin
transport.open()
rescue Thrift::TransportException
@client = nil
debug("Could not connect to HBase. Retrying in 5 seconds..." + count.to_s + " of " + THRIFT_RETRY_COUNT.to_s)
sleep 5
count = count + 1
end
end
if count == THRIFT_RETRY_COUNT
debug("Failed to connect to HBase after " + THRIFT_RETRY_COUNT.to_s + " tries.")
end
end

def table_names
client.getTableNames()
end

def method_missing(method, *args)
debug("#{self.class.name}#method_missing(#{method.inspect}, #{args.inspect})")
client.send(method, *args)
begin
connect() if not @client
client.send(method, *args) if @client
rescue Thrift::TransportException
@client = nil
connect()
client.send(method, *args) if @client
end
end
end
end
Expand Down

0 comments on commit 5e3db71

Please sign in to comment.