Class: Carnivore::Source::Test

Inherits:
Carnivore::Source show all
Defined in:
lib/carnivore/source/test.rb

Overview

Test source

Constant Summary collapse

RAND_MAX =

Maximum rand value

99999
RAND_DIV =

Default rand divisor

3
RAND_SLEEP =

Sleep length when valid

10

Instance Attribute Summary

Attributes inherited from Carnivore::Source

#allow_multiple_matches, #arguments, #auto_confirm, #auto_process, #callback_supervisor, #callbacks, #message_loop, #message_registry, #message_remote, #name, #processing, #run_process

Instance Method Summary collapse

Methods inherited from Carnivore::Source

#_transmit, #add_callback, #auto_confirm?, #auto_process?, build, #callback_name, clear!, #confirm, #format, #init_registry, #initialize, #inspect, #loop_enabled?, #loop_receive, #loop_transmit, #multiple_callbacks?, #process, provide, #receive_messages, register, #remove_callback, require_path, reset_comms!, #restarted!, #run_connect, #run_setup, #setup, source, source_classes, sources, sources_registry, #start!, #terminate, #to_s, #touch, #valid_message?

Methods included from Utils::Failure

#execute_and_retry_forever

Methods included from Utils::Logging

#exception_log, #log

Constructor Details

This class inherits a constructor from Carnivore::Source

Instance Method Details

#connect(*args) ⇒ Object

Note that we are connected



14
15
16
# File 'lib/carnivore/source/test.rb', line 14

def connect(*args)
  info 'Test connect called'
end

#receive(*args) ⇒ Array<String>

Receive randomly generated message

Returns:

  • (Array<String>)


21
22
23
24
25
26
27
28
# File 'lib/carnivore/source/test.rb', line 21

def receive(*args)
  if(rand(RAND_MAX) % RAND_DIV == 0)
    sleep_for = rand(RAND_SLEEP)
    debug "Test source sleep for: #{sleep_for}"
    sleep sleep_for
  end
  20.times.map{('a'..'z').to_a.shuffle.first}.join
end

#transmit(message) ⇒ Object

Dummy transmit message

Parameters:



33
34
35
# File 'lib/carnivore/source/test.rb', line 33

def transmit(message)
  info "Transmit requested: #{message}"
end