Class: DataCollector::Input::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/data_collector/input/generic.rb

Direct Known Subclasses

Dir, Queue, Rpc

Instance Method Summary collapse

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, options = {})
  @uri = URI(URI.decode_uri_component(uri.to_s)) #"#{uri.scheme}://#{URI.decode_uri_component(uri.host)}#{URI.decode_uri_component(uri.path)}"
  @options = options
  @running = false

  @input = DataCollector::Input.new
  @output = DataCollector::Output.new

  @name = options[: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 on_message(&block)
  @on_message_callback = block
end

#pauseObject



40
41
42
# File 'lib/data_collector/input/generic.rb', line 40

def pause
  @listener.pause
end

#paused?Boolean

Returns:

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/data_collector/input/generic.rb', line 44

def running?
  @running
end

#stopObject



36
37
38
# File 'lib/data_collector/input/generic.rb', line 36

def stop
  @listener.stop
end

#stopped?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/data_collector/input/generic.rb', line 48

def stopped?
  @running == false
end