Class: Broker::Poller

Inherits:
Object
  • Object
show all
Includes:
Event, Utility
Defined in:
lib/broker/launcher.rb

Instance Method Summary collapse

Methods included from Event

#register, #transport

Methods included from Utility

#safe_thread, #timestamp, #watcher

Constructor Details

#initializePoller

Returns a new instance of Poller.



68
69
70
71
72
73
74
# File 'lib/broker/launcher.rb', line 68

def initialize
  @finished  = false
  @wait_time = Broker.options[:poll_interval]
  @folder    = Broker.options[:queue]
  @queue     = Broker::Queue.new
  @finder		 = Broker::Finder.new(@queue)
end

Instance Method Details

#startObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/broker/launcher.rb', line 87

def start
  @thread ||= safe_thread("poller") do 
    pause_first
    
    while !@finished
      register(@finder.check)
      wait
    end
  end
end

#terminateObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/broker/launcher.rb', line 76

def terminate
  @finished = true
  if @thread
    t = @thread
    @thread = nil
    wait 1
    t.value
    puts "Polling thread terminated"
  end
end