Class: HTTP::Session::ConnectionPool
- Inherits:
-
Object
- Object
- HTTP::Session::ConnectionPool
- Includes:
- MonitorMixin
- Defined in:
- lib/http/session/connection_pool.rb
Constant Summary collapse
- DEFAULT_POOL_TIMEOUT =
5
- DEFAULT_POOL_MAXSIZE =
5
- DEFAULT_CONN_KEEP_ALIVE_TIMEOUT =
5
Instance Attribute Summary collapse
-
#maxsize ⇒ Object
readonly
The number of connections can be reused.
Instance Method Summary collapse
-
#initialize(opts, &blk) ⇒ ConnectionPool
constructor
Returns a new instance of ConnectionPool.
-
#size ⇒ Object
The number of connections available.
-
#with(timeout: DEFAULT_POOL_TIMEOUT, &blk) ⇒ Object
Obtain a connection.
Constructor Details
#initialize(opts, &blk) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/http/session/connection_pool.rb', line 15 def initialize(opts, &blk) super() @host = opts.fetch(:host) @timeout = opts.fetch(:timeout, DEFAULT_CONN_KEEP_ALIVE_TIMEOUT) @maxsize = opts.fetch(:maxsize, DEFAULT_POOL_MAXSIZE) @create_blk = blk @created = 0 @que = [] @resource = new_cond end |
Instance Attribute Details
#maxsize ⇒ Object (readonly)
The number of connections can be reused.
10 11 12 |
# File 'lib/http/session/connection_pool.rb', line 10 def maxsize @maxsize end |
Instance Method Details
#size ⇒ Object
The number of connections available.
37 38 39 |
# File 'lib/http/session/connection_pool.rb', line 37 def size @maxsize - @created + @que.size end |
#with(timeout: DEFAULT_POOL_TIMEOUT, &blk) ⇒ Object
Obtain a connection.
29 30 31 32 33 34 |
# File 'lib/http/session/connection_pool.rb', line 29 def with(timeout: DEFAULT_POOL_TIMEOUT, &blk) conn = checkout(timeout: timeout) blk.call(conn) ensure checkin(conn) if conn end |