Class: RightScale::CloudApi::ConnectionProxy

Inherits:
Routine show all
Defined in:
lib/base/routines/connection_proxy.rb,
lib/base/routines/connection_proxies/net_http_persistent_proxy.rb,
lib/base/routines/connection_proxies/right_http_connection_proxy.rb

Overview

This routine generifies all HTTP requests so that the main code does not need to worry about the underlaying libraries (right_http_connection or persistent_connection).

Defined Under Namespace

Classes: Error, NetHttpPersistentProxy, RightHttpConnectionProxy

Instance Attribute Summary

Attributes inherited from Routine

#data

Instance Method Summary collapse

Methods inherited from Routine

#cloud_api_logger, #execute, #invoke_callback_method, #options, #reset, #with_timer

Instance Method Details

#processObject

Main entry point.

Performs an HTTP request.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/base/routines/connection_proxy.rb', line 38

def process
  unless @connection_proxy
    # Try to use a user defined connection proxy. The options are:
    #  - RightScale::CloudApi::ConnectionProxy::RightHttpConnectionProxy,
    #  - RightScale::CloudApi::ConnectionProxy::NetHttpPersistentProxy
    connection_proxy_class = data[:options][:connection_proxy]
    unless connection_proxy_class
      # If it is not defined then load right_http_connection gem and use it.
      # connection_proxy_class = ConnectionProxy::RightHttpConnectionProxy
      connection_proxy_class = RightScale::CloudApi::ConnectionProxy::NetHttpPersistentProxy
    end
    @connection_proxy = connection_proxy_class.new
  end        
  
  # Register a call back to close current connection
  data[:callbacks][:close_current_connection] = Proc::new do |reason|
    @connection_proxy.close_connection(nil, reason)
    cloud_api_logger.log("Current connection closed: #{reason}", :connection_proxy)
  end

  # Make a request.
  with_timer('HTTP request', :connection_proxy) do
    @connection_proxy.request(data)
  end
end