Class: MintHttp::PoolEntry
- Inherits:
-
Object
- Object
- MintHttp::PoolEntry
- Defined in:
- lib/mint_http/pool_entry.rb
Instance Attribute Summary collapse
-
#acquired ⇒ Object
readonly
Returns the value of attribute acquired.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#last_used ⇒ Object
readonly
Returns the value of attribute last_used.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#unhealthy ⇒ Object
readonly
Returns the value of attribute unhealthy.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #acquire! ⇒ Object
- #available? ⇒ Boolean
- #expired? ⇒ Boolean
- #healthy? ⇒ Boolean
- #idle_ttl_reached? ⇒ Boolean
-
#initialize(pool, client, namespace) ⇒ PoolEntry
constructor
A new instance of PoolEntry.
- #matches?(other) ⇒ Boolean
- #release! ⇒ Object
- #to_clean? ⇒ Boolean
- #ttl_reached? ⇒ Boolean
- #usage_reached? ⇒ Boolean
Constructor Details
#initialize(pool, client, namespace) ⇒ PoolEntry
Returns a new instance of PoolEntry.
11 12 13 14 15 16 17 18 19 |
# File 'lib/mint_http/pool_entry.rb', line 11 def initialize(pool, client, namespace) @pool = pool @client = client @namespace = namespace @acquired = false @birth_time = time_ms @last_used = time_ms @usage = 0 end |
Instance Attribute Details
#acquired ⇒ Object (readonly)
Returns the value of attribute acquired.
6 7 8 |
# File 'lib/mint_http/pool_entry.rb', line 6 def acquired @acquired end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/mint_http/pool_entry.rb', line 4 def client @client end |
#last_used ⇒ Object (readonly)
Returns the value of attribute last_used.
7 8 9 |
# File 'lib/mint_http/pool_entry.rb', line 7 def last_used @last_used end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/mint_http/pool_entry.rb', line 5 def namespace @namespace end |
#unhealthy ⇒ Object (readonly)
Returns the value of attribute unhealthy.
9 10 11 |
# File 'lib/mint_http/pool_entry.rb', line 9 def unhealthy @unhealthy end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
8 9 10 |
# File 'lib/mint_http/pool_entry.rb', line 8 def usage @usage end |
Instance Method Details
#acquire! ⇒ Object
41 42 43 44 45 |
# File 'lib/mint_http/pool_entry.rb', line 41 def acquire! @acquired = true @last_used = time_ms @usage += 1 end |
#available? ⇒ Boolean
51 52 53 |
# File 'lib/mint_http/pool_entry.rb', line 51 def available? !@acquired && !expired? && healthy? end |
#expired? ⇒ Boolean
37 38 39 |
# File 'lib/mint_http/pool_entry.rb', line 37 def expired? idle_ttl_reached? || ttl_reached? || usage_reached? end |
#healthy? ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/mint_http/pool_entry.rb', line 55 def healthy? socket = client. unless socket.is_a?(TCPSocket) return false end !socket.closed? && !(socket.wait_readable(0) && client.buffered_socket.eof?) end |
#idle_ttl_reached? ⇒ Boolean
29 30 31 |
# File 'lib/mint_http/pool_entry.rb', line 29 def idle_ttl_reached? (time_ms - @last_used) > @pool.idle_ttl end |
#matches?(other) ⇒ Boolean
21 22 23 |
# File 'lib/mint_http/pool_entry.rb', line 21 def matches?(other) @client.object_id == other.object_id end |
#release! ⇒ Object
47 48 49 |
# File 'lib/mint_http/pool_entry.rb', line 47 def release! @acquired = false end |
#to_clean? ⇒ Boolean
64 65 66 |
# File 'lib/mint_http/pool_entry.rb', line 64 def to_clean? (expired? || !healthy?) && !@acquired end |
#ttl_reached? ⇒ Boolean
25 26 27 |
# File 'lib/mint_http/pool_entry.rb', line 25 def ttl_reached? (time_ms - @birth_time) > @pool.ttl end |
#usage_reached? ⇒ Boolean
33 34 35 |
# File 'lib/mint_http/pool_entry.rb', line 33 def usage_reached? @usage >= @pool.usage_limit end |