Class: Elasticsearch::Transport::Transport::HTTP::Manticore
- Inherits:
-
Object
- Object
- Elasticsearch::Transport::Transport::HTTP::Manticore
- Includes:
- Base
- Defined in:
- lib/elasticsearch/transport/transport/http/manticore.rb
Overview
Alternative HTTP transport implementation for JRuby, using the [Manticore](github.com/cheald/manticore) client,
@example HTTPS (All SSL settings are optional,
see http://www.rubydoc.info/gems/manticore/Manticore/Client:initialize)
require 'elasticsearch/transport/transport/http/manticore'
client = Elasticsearch::Client.new \
url: 'https://elasticsearch.example.com',
transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore,
ssl: {
truststore: '/tmp/truststore.jks',
truststore_password: 'password',
keystore: '/tmp/keystore.jks',
keystore_password: 'secret',
}
client.transport.connections.first.connection
=> #<Manticore::Client:0xdeadbeef ...>
client.info['status']
=> 200
Constant Summary
Constants included from Base
Base::DEFAULT_MAX_RETRIES, Base::DEFAULT_PORT, Base::DEFAULT_PROTOCOL, Base::DEFAULT_RELOAD_AFTER, Base::DEFAULT_RESURRECT_AFTER, Base::DEFAULT_SERIALIZER_CLASS, Base::SANITIZED_PASSWORD
Instance Attribute Summary
Attributes included from Base
#connections, #counter, #hosts, #last_request_at, #logger, #options, #protocol, #reload_after, #reload_connections, #resurrect_after, #serializer, #sniffer, #tracer
Instance Method Summary collapse
-
#__build_connections ⇒ Connections::Collection
Builds and returns a collection of connections.
-
#__close_connections ⇒ Connections::Collection
Closes all connections by marking them as dead and closing the underlying HttpClient instances.
-
#build_client(options = {}) ⇒ Object
Should just be run once at startup.
-
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
-
#initialize(arguments = {}, &block) ⇒ Manticore
constructor
A new instance of Manticore.
-
#perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
Methods included from Base
#__build_connection, #__convert_to_json, #__full_url, #__log_response, #__raise_transport_error, #__rebuild_connections, #__trace, #get_connection, #reload_connections!, #resurrect_dead_connections!
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn
Constructor Details
#initialize(arguments = {}, &block) ⇒ Manticore
Returns a new instance of Manticore.
52 53 54 55 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 52 def initialize(arguments={}, &block) @manticore = build_client(arguments[:options] || {}) super(arguments, &block) end |
Instance Method Details
#__build_connections ⇒ Connections::Collection
Builds and returns a collection of connections. Each connection is a Manticore::Client
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 98 def __build_connections @request_options = {} apply_headers(@request_options, [:transport_options]) apply_headers(@request_options, ) Connections::Collection.new \ :connections => hosts.map { |host| host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL host[:port] ||= DEFAULT_PORT host.delete(:user) # auth is not supported here. host.delete(:password) # use the headers Connections::Connection.new \ :host => host, :connection => @manticore }, :selector_class => [:selector_class], :selector => [:selector] end |
#__close_connections ⇒ Connections::Collection
Closes all connections by marking them as dead and closing the underlying HttpClient instances
124 125 126 127 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 124 def __close_connections # The Manticore adapter uses a single long-lived instance # of Manticore::Client, so we don't close the connections. end |
#build_client(options = {}) ⇒ Object
Should just be run once at startup
58 59 60 61 62 63 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 58 def build_client(={}) = [:transport_options] || {} [:ssl] = [:ssl] || {} @manticore = ::Manticore::Client.new() end |
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
133 134 135 136 137 138 139 140 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 133 def host_unreachable_exceptions [ ::Manticore::Timeout, ::Manticore::SocketException, ::Manticore::ClientProtocolException, ::Manticore::ResolutionFailure ] end |
#perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/elasticsearch/transport/transport/http/manticore.rb', line 70 def perform_request(method, path, params={}, body=nil, headers=nil, opts={}) super do |connection, url| params[:body] = __convert_to_json(body) if body params[:headers] = headers if headers params = params.merge @request_options case method when "GET" resp = connection.connection.get(url, params) when "HEAD" resp = connection.connection.head(url, params) when "PUT" resp = connection.connection.put(url, params) when "POST" resp = connection.connection.post(url, params) when "DELETE" resp = connection.connection.delete(url, params) else raise ArgumentError.new "Method #{method} not supported" end Response.new resp.code, resp.read_body, resp.headers end end |