Class: DataCollector::Input::Generic
- Inherits:
-
Object
- Object
- DataCollector::Input::Generic
- Defined in:
- lib/data_collector/input/generic.rb
Instance Method Summary collapse
-
#initialize(uri, options = {}) ⇒ Generic
constructor
A new instance of Generic.
- #on_message(&block) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #run(should_block = false, &block) ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(uri, options = {}) ⇒ Generic
Returns a new instance of Generic.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/data_collector/input/generic.rb', line 9 def initialize(uri, = {}) @uri = URI(URI.decode_uri_component(uri.to_s)) #"#{uri.scheme}://#{URI.decode_uri_component(uri.host)}#{URI.decode_uri_component(uri.path)}" @options = @running = false @input = DataCollector::Input.new @output = DataCollector::Output.new @name = [:name] || "input-#{Time.now.to_i}-#{rand(10000)}" create_listener end |
Instance Method Details
#on_message(&block) ⇒ Object
56 57 58 |
# File 'lib/data_collector/input/generic.rb', line 56 def (&block) @on_message_callback = block end |
#pause ⇒ Object
40 41 42 |
# File 'lib/data_collector/input/generic.rb', line 40 def pause @listener.pause end |
#paused? ⇒ Boolean
52 53 54 |
# File 'lib/data_collector/input/generic.rb', line 52 def paused? @listener.paused? end |
#run(should_block = false, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/data_collector/input/generic.rb', line 21 def run(should_block = false, &block) raise DataCollector::Error, 'Please supply a on_message block' if @on_message_callback.nil? @running = true if should_block while running? yield block if block_given? sleep 2 end else yield block if block_given? end end |
#running? ⇒ Boolean
44 45 46 |
# File 'lib/data_collector/input/generic.rb', line 44 def running? @running end |
#stop ⇒ Object
36 37 38 |
# File 'lib/data_collector/input/generic.rb', line 36 def stop @listener.stop end |
#stopped? ⇒ Boolean
48 49 50 |
# File 'lib/data_collector/input/generic.rb', line 48 def stopped? @running == false end |