class Elementary::Connection

Constants

DEFAULT_HOSTS

Attributes

raise_on_error[R]
service[R]

Public Class Methods

new(service, opts={}) click to toggle source

Initialize a connection to the Protobuf::Rpc::Service

@param [Protobuf::Rpc::Service] service @param [Hash] opts @options opts [Symbol] :transport Defaults to :http, must map to a class

in the +Elementary::Transport+ module

@options opts [Array] :hosts An array of {:host => 'localhost', :port =>

8080} hashes to instruct the connection

@option opts [Hash] :transport_options A Hash of request options that

will be passed down to the transport layer. This will depend on what
options are available by the underlying transport

@option opts [Hash] :future_options A Hash of options to use when

constructing the Concurrent::Future to run the RPC. In particular, it
allows specifying the :executor for the Concurrent::Future.
# File lib/elementary/connection.rb, line 28
def initialize(service, opts={})
  opts = Hashie::Mash.new(opts)

  if service.nil? || service.superclass != Protobuf::Rpc::Service
    raise ArgumentError,
      "Cannot construct an Elementary::Connection with `#{service}` (#{service.class})"
  end

  @service = service
  @transport = opts[:transport]
  @hosts = opts[:hosts] || DEFAULT_HOSTS
  @transport_opts = opts[:transport_options] || {}
  @future_opts = opts[:future_options] || {}
  # Create exectutor here to avoid threading issues later. See Issue #43
  rpc
end

Public Instance Methods

rpc() click to toggle source
# File lib/elementary/connection.rb, line 45
def rpc
  @rpc ||= Elementary::Executor.new(@service, select_transport, @future_opts)
end
select_transport() click to toggle source
# File lib/elementary/connection.rb, line 49
def select_transport
  Elementary::Transport::HTTP.new(@hosts, @transport_opts)
end