Class: TickrClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ TickrClient

Returns a new instance of TickrClient.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tickr_client.rb', line 9

def initialize(opts)
  self.servers = opts[:servers]
  self.timeout = opts[:timeout] || 1000
  self.cache_size = opts[:cache_size] || 100
  self.replenish_cache_at = opts[:replenish_cache_at] || 10

  self.query_in_progress = false
  self.next_server_index = Random.new.rand(servers.count)
  self.tickets = ThreadSafe::Array.new

  fetch_tickets
end

Instance Attribute Details

#cache_sizeObject

Returns the value of attribute cache_size.



7
8
9
# File 'lib/tickr_client.rb', line 7

def cache_size
  @cache_size
end

#replenish_cache_atObject

Returns the value of attribute replenish_cache_at.



7
8
9
# File 'lib/tickr_client.rb', line 7

def replenish_cache_at
  @replenish_cache_at
end

#serversObject

Returns the value of attribute servers.



7
8
9
# File 'lib/tickr_client.rb', line 7

def servers
  @servers
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/tickr_client.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#get_ticketObject



22
23
24
25
26
27
28
# File 'lib/tickr_client.rb', line 22

def get_ticket
  fetch_tickets if tickets.count == 0
  this_ticket = tickets.shift
  fetch_tickets_async if tickets.count <= replenish_cache_at

  this_ticket
end