Module: BufQueue

Defined in:
lib/buf_queue.rb,
lib/buf_queue/version.rb

Constant Summary collapse

NUMBER_OF_SUBSCRIBERS =

Number of subscribers

5
MAP_SIZE =

Map size - n

100
QUEUE_MAX_SIZE =

Max queue size - but generates the queue size randomly within this range(0-queue_size)

5
RANDOM_INPUT_RANGE =

For generating data within range

1000
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.generate_inputObject

Generating input randomly



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/buf_queue.rb', line 39

def self.generate_input
  bq = Bq.new
  initialize_subscribers(bq, NUMBER_OF_SUBSCRIBERS)
  i = 0
  begin
    # Iterating over the given map size for enough random input to publish data
    # And also giving the random queue size within the range of QUEUE_MAX_SIZE for changing B value
    while i < MAP_SIZE
      queue_size = rand(1..QUEUE_MAX_SIZE)
      index = rand(0..MAP_SIZE)
      bq.initialize_queue index, queue_size
      bq.add(index, generate_random_type_of_strings(rand(0..RANDOM_INPUT_RANGE)))
      sleep(2)
      i += 1
    end 
  rescue Exception => e
    puts "Exception :: #{e}"
  end
end

.generate_random_type_of_strings(val) ⇒ Object

This method is just for generating random type of objects like jsons, strings and integer



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/buf_queue.rb', line 26

def self.generate_random_type_of_strings(val)
  random = rand(0..2)
  case random
  when 0 #generates JSON obj
    {"key" => val.to_s}
  when 1 #generates string
    val.to_s
  else        #send integer value
    val
  end
end

.initialize_subscribers(bq, number_of_subscribers) ⇒ Object

Initializing the subscribers with the given size



16
17
18
19
20
21
22
23
# File 'lib/buf_queue.rb', line 16

def self.initialize_subscribers(bq, number_of_subscribers)
  # Creating subscribers..
  subscribers = []
  (1..number_of_subscribers).each do |i|
    subscribers << Subscriber.new(i)
  end
  bq.add_subscribers subscribers
end