Class: MintHttp::PoolEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/mint_http/pool_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#acquiredObject (readonly)

Returns the value of attribute acquired.



6
7
8
# File 'lib/mint_http/pool_entry.rb', line 6

def acquired
  @acquired
end

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/mint_http/pool_entry.rb', line 4

def client
  @client
end

#last_usedObject (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

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/mint_http/pool_entry.rb', line 5

def namespace
  @namespace
end

#unhealthyObject (readonly)

Returns the value of attribute unhealthy.



9
10
11
# File 'lib/mint_http/pool_entry.rb', line 9

def unhealthy
  @unhealthy
end

#usageObject (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/mint_http/pool_entry.rb', line 51

def available?
  !@acquired && !expired? && healthy?
end

#expired?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/mint_http/pool_entry.rb', line 55

def healthy?
  socket = client.underlying_tcp_socket
  unless socket.is_a?(TCPSocket)
    return false
  end

  !socket.closed? && !(socket.wait_readable(0) && client.buffered_socket.eof?)
end

#idle_ttl_reached?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


64
65
66
# File 'lib/mint_http/pool_entry.rb', line 64

def to_clean?
  (expired? || !healthy?) && !@acquired
end

#ttl_reached?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/mint_http/pool_entry.rb', line 33

def usage_reached?
  @usage >= @pool.usage_limit
end