Class: Mizuno::Client
- Inherits:
-
Object
- Object
- Mizuno::Client
- Defined in:
- lib/mizuno/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear(exchange) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #request(url, options = {}, &block) ⇒ Object
- #stop(wait = true) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mizuno/client.rb', line 26 def initialize( = {}) defaults = { :timeout => 60 } = defaults.merge() @client = HttpClient.new @client.setConnectorType(HttpClient::CONNECTOR_SELECT_CHANNEL) @client.setMaxConnectionsPerAddress(100) @client.setThreadPool(QueuedThreadPool.new(50)) @client.setTimeout([:timeout] * 1000) @client.start @lock = Mutex.new @exchanges = [] end |
Class Method Details
.request(*args, &block) ⇒ Object
13 14 15 16 |
# File 'lib/mizuno/client.rb', line 13 def Client.request(*args, &block) @lock.synchronize { @root ||= new } @root.request(*args, &block) end |
.stop ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/mizuno/client.rb', line 18 def Client.stop @lock.synchronize do return unless @root @root.stop @root = nil end end |
Instance Method Details
#clear(exchange) ⇒ Object
47 48 49 50 51 |
# File 'lib/mizuno/client.rb', line 47 def clear(exchange) return unless @lock.try_lock @exchanges.delete(exchange) @lock.unlock end |
#request(url, options = {}, &block) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/mizuno/client.rb', line 53 def request(url, = {}, &block) exchange = ClientExchange.new(self) @lock.synchronize { @exchanges << exchange } exchange.setup(url, , &block) @client.send(exchange) return(exchange) end |
#stop(wait = true) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mizuno/client.rb', line 39 def stop(wait = true) wait and @lock.synchronize do @exchanges.each { |e| e.waitForDone } @exchanges.clear end @client.stop end |