Class: Cinch::MessageQueue Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/message_queue.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class manages all outgoing messages, applying rate throttling and fair distribution.

Instance Method Summary collapse

Constructor Details

#initialize(socket, bot) ⇒ MessageQueue

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MessageQueue.



11
12
13
14
15
16
17
18
19
20
# File 'lib/cinch/message_queue.rb', line 11

def initialize(socket, bot)
  @socket = socket
  @bot = bot
  @queues = {generic: OpenEndedQueue.new}
  @queues_to_process = Queue.new
  @queued_queues = Set.new
  @mutex = Mutex.new
  @time_since_last_send = nil
  @log = []
end

Instance Method Details

#process!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



53
54
55
56
57
58
# File 'lib/cinch/message_queue.rb', line 53

def process!
  loop do
    wait
    process_one
  end
end

#queue(message) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cinch/message_queue.rb', line 23

def queue(message)
  command, target, _ = message.split(" ", 3)

  queue = nil
  case command
  when "PRIVMSG", "NOTICE"
    @mutex.synchronize do
      # we are assuming that each message has only one target,
      # which will be true as long as the user does not send raw
      # messages.
      #
      # this assumption is also reflected in the computation of
      # passed time and processed messages, since our score does
      # not take weights into account.
      queue = @queues[target] ||= OpenEndedQueue.new
    end
  else
    queue = @queues[:generic]
  end
  queue << message

  @mutex.synchronize do
    unless @queued_queues.include?(queue)
      @queued_queues << queue
      @queues_to_process << queue
    end
  end
end