Sha256: 19e42a0c6b5bb9bee9e7d4bcf6e146b053d41dc64a4de5b91458a9d318948888

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

# include path hack
$:.push(File.dirname(__FILE__) + '/gen-rb')

require 'thrift'
require 'thrift/protocol/binaryprotocolaccelerated'
require 'HqlService'
require File.dirname(__FILE__) + '/thrift_transport_monkey_patch'

module Hypertable
  class ThriftClient < ThriftGen::HqlService::Client
    def initialize(host, port = 38080, timeout_ms = 20000, do_open = true)
      socket = Thrift::Socket.new(host, port, timeout_ms)
      @transport = Thrift::FramedTransport.new(socket)
      protocol = Thrift::BinaryProtocolAccelerated.new(@transport)
      super(protocol)
      open() if do_open
    end

    def open()
      @transport.open()
      @do_close = true
    end

    def close()
      @transport.close() if @do_close
    end

    # more convenience methods

    def with_scanner(table, scan_spec)
      scanner = open_scanner(table, scan_spec)
      begin
        yield scanner
      ensure
        close_scanner(scanner)
      end
    end

    def with_mutator(table)
      mutator = open_mutator(table);
      begin
        yield mutator
      ensure
        close_mutator(mutator, 1)
      end
    end

    # scanner iterator
    def each_cell(scanner)
      cells = next_cells(scanner);

      while (cells.size > 0)
        cells.each {|cell| yield cell}
        cells = next_cells(scanner);
      end
    end
  end

  def self.with_thrift_client(host, port, timeout_ms = 20000)
    client = ThriftClient.new(host, port, timeout_ms)
    begin
      yield client
    ensure
      client.close()
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tylerkovacs-hyper_record-0.2.2 lib/hypertable/thrift_client.rb
tylerkovacs-hyper_record-0.2.3 lib/hypertable/thrift_client.rb
tylerkovacs-hyper_record-0.2.4 lib/hypertable/thrift_client.rb