Class: HC::HTTPClient::ManagerFacade

Inherits:
Object
  • Object
show all
Defined in:
lib/hc-httpclient.rb

Overview

Facade over http client and connection manager, setup, start, shutdown

Example Settings

See: hc.apache.org/httpclient-3.x/preference-api.html

manager_params.max_total_connections = 200
manager_params.connection_timeout = 1500 #ms
manager_params.default_max_connections_per_host = 20
manager_params.stale_checking_enabled = false
client_params.connection_manager_timeout = 3000 #ms
client_params.so_timeout = 3000 #ms
client_params.set_parameter( HttpMethodParams::RETRY_HANDLER, 
                             DefaultHttpMethodRetryHandler.new( 2, false ) )
client_params.cookie_policy = CookiePolicy::IGNORE_COOKIES

Note, use of set_parameter style settings will increase the likelihood of 4.x compatibility

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManagerFacade

Returns a new instance of ManagerFacade.



76
77
78
79
80
81
82
83
# File 'lib/hc-httpclient.rb', line 76

def initialize
  @manager_params = HttpConnectionManagerParams.new

  @client_params = HttpClientParams.new
  
  @client = nil
  @connection_manager = nil
end

Instance Attribute Details

#clientObject (readonly)

The HttpClient instance available after start



68
69
70
# File 'lib/hc-httpclient.rb', line 68

def client
  @client
end

#client_paramsObject (readonly)

Client parameters



74
75
76
# File 'lib/hc-httpclient.rb', line 74

def client_params
  @client_params
end

#manager_paramsObject (readonly)

Manager parameters



71
72
73
# File 'lib/hc-httpclient.rb', line 71

def manager_params
  @manager_params
end

Instance Method Details

#shutdownObject

Shutdown and close the connection manager and client.



95
96
97
98
99
# File 'lib/hc-httpclient.rb', line 95

def shutdown
  @connection_manager.shutdown if @connection_manager
  @client = nil
  @connection_manager = nil
end

#startObject

Given previously set parameters, construct connection manager and client.



87
88
89
90
91
92
# File 'lib/hc-httpclient.rb', line 87

def start
  @connection_manager = MultiThreadedHttpConnectionManager.new()
  @connection_manager.params = @manager_params

  @client = HttpClient.new( @client_params, @connection_manager );
end