Class: ElasticSearch::Transport::Thrift

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticsearch/transport/thrift.rb

Constant Summary collapse

DEFAULTS =
{
  :timeout => 5,
  :thrift_protocol => ::Thrift::BinaryProtocol,
  :thrift_protocol_extra_params => [],
  :thrift_transport => ::Thrift::Socket,
  :thrift_transport_wrapper => ::Thrift::BufferedTransport,
  :client_class => ElasticSearch::Thrift::Rest::Client
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#options, #server

Instance Method Summary collapse

Methods inherited from Base

#encoder

Methods included from BaseProtocol

#all_nodes

Methods included from ClusterAdminProtocol

#cluster_health, #cluster_state, #nodes_info, #nodes_stats, #restart_nodes, #shutdown_nodes

Methods included from IndexAdminProtocol

#alias_index, #create_index, #delete_index, #flush, #index_status, #optimize, #refresh, #snapshot, #update_mapping

Methods included from IndexProtocol

#count, #delete, #get, #index, #scroll, #search

Constructor Details

#initialize(server, options = {}) ⇒ Thrift

Returns a new instance of Thrift.



18
19
20
21
# File 'lib/elasticsearch/transport/thrift.rb', line 18

def initialize(server, options={})
  super
  @options = DEFAULTS.merge(@options)
end

Instance Method Details

#closeObject



36
37
38
# File 'lib/elasticsearch/transport/thrift.rb', line 36

def close
  @transport.close rescue nil
end

#connect!Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/transport/thrift.rb', line 23

def connect!
  host, port = parse_server(@server)

  @transport = @options[:thrift_transport].new(host, port.to_i, @options[:timeout])
  @transport = @transport_wrapper.new(@transport) if @transport_wrapper
  @transport.open

  @client = @options[:client_class].new(@options[:thrift_protocol].new(@transport, *@options[:thrift_protocol_extra_params]))
rescue ::Thrift::TransportException, Errno::ECONNREFUSED
  close
  raise ConnectionFailed
end