class RJack::HTTPClient4::ManagerFacade

Facade over http client and connection manager, supporting setup -> start() -> shutdown()

Attributes

client[R]

org.apache.http.client.HttpClient available after start()

client_params[R]

Client parameters "bean", responding to various setters:

client_params.allow_circular_redirects   = false
client_params.cookie_policy              = CookiePolicy::BEST_MATCH
client_params.default_headers            = { "X-Name" => "value" }
client_params.handle_redirects           = true
client_params.reject_relative_redirect   = true
connection_params[R]

Connection parameters "bean", responding to various setters:

connection_params.connection_timeout     = 2000     #milliseconds
connection_params.so_timeout             = 3000     #milliseconds
connection_params.linger                 = 2        #seconds
connection_params.socket_buffer_size     = 2 * 1024 #bytes
connection_params.stale_checking_enabled = true
connection_params.tcp_no_delay           = false
manager_params[R]

Manager parameters "bean", responding to various setters:

manager_params.max_total_connections     = 200
manager_params.timeout                   = 2000     #milliseconds
manager_params.connections_per_route     = 10

Public Class Methods

new() click to toggle source

New facade ready for setup

# File lib/rjack-httpclient-4.rb, line 84
def initialize
  @mparams = BasicHttpParams.new
  @cparams = BasicHttpParams.new

  @manager_params    = ConnManagerParamBean.new( @mparams )
  @client_params     = ClientParamBean.new( @cparams )
  @connection_params = HttpConnectionParamBean.new( @cparams )

  @client = nil
  @connection_manager = nil
  @retry_handler = nil
end

Public Instance Methods

create_connection_manager() click to toggle source

Create default ThreadSafeClientConnManager using a set #manager_params

# File lib/rjack-httpclient-4.rb, line 138
def create_connection_manager
  ThreadSafeClientConnManager.new( @mparams, @scheme_registry )
end
create_http_client() click to toggle source

Create DefaultHttpClient given connection manager and any set client or #connection_params

# File lib/rjack-httpclient-4.rb, line 144
def create_http_client
  c = DefaultHttpClient.new( @connection_manager, @cparams )
  c.http_request_retry_handler = @retry_handler if @retry_handler
  c
end
create_scheme_registry() click to toggle source

Create a default SchemeRegistry with http and https enabled.

# File lib/rjack-httpclient-4.rb, line 120
def create_scheme_registry
  sr = SchemeRegistry.new
  sr.register( Scheme.new( "http",  80, plain_factory ) )
  sr.register( Scheme.new( "https", 443, ssl_factory ) )
  sr
end
plain_factory() click to toggle source

Return MultihomePlainSocketFactory instance

# File lib/rjack-httpclient-4.rb, line 128
def plain_factory
  PlainSocketFactory::socket_factory
end
set_retry_handler( count, retry_if_sent = false ) click to toggle source

Setup a DefaultHttpRequestRetryHandler

# File lib/rjack-httpclient-4.rb, line 98
def set_retry_handler( count, retry_if_sent = false )
  @retry_handler =
    DefaultHttpRequestRetryHandler.new( count, retry_if_sent )
end
shutdown() click to toggle source

Shutdown client and connection manager.

# File lib/rjack-httpclient-4.rb, line 113
def shutdown
  @connection_manager.shutdown if @connection_manager
  @client = nil
  @connection_manager = nil
end
ssl_factory() click to toggle source

Return SSLSocketFactory instance

# File lib/rjack-httpclient-4.rb, line 133
def ssl_factory
  SSLSocketFactory::socket_factory
end
start() click to toggle source

Given previous setup, create connection manager, create, and return client.

# File lib/rjack-httpclient-4.rb, line 105
def start
  @scheme_registry = create_scheme_registry
  @connection_manager = create_connection_manager

  @client = create_http_client
end