Class: SDEE::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/sdee/client.rb', line 6

def initialize(options={})
  @options = options

  # buffer to retain alerts, threads
  @events = @threads = []
end

Instance Method Details

#getObject

Retrieves but doesn’t remove events from buffer



36
37
38
# File 'lib/sdee/client.rb', line 36

def get
  @events
end

#popObject

Removes events from buffer



31
32
33
# File 'lib/sdee/client.rb', line 31

def pop
  @events.delete
end

#start_polling(num_threads = 5) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sdee/client.rb', line 13

def start_polling(num_threads=5)
  stop_polling unless @threads.empty?

  num_threads.times do
    @threads << Thread.new do
      poller = Poller.new(@options)
      poller.poll
    end
  end

  @threads.each { |t| t.join }
end

#stop_pollingObject



26
27
28
# File 'lib/sdee/client.rb', line 26

def stop_polling
  @threads.each { |thread| thread.terminate }
end