aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/processor.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-09-16 12:47:52 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-09-16 12:47:52 +0100
commit38e4d877abee3c8e40edd932057e2bf16ad01e13 (patch)
treed2201a1c18fbebec4e0594b81c27974057e886b2 /lib/mauve/processor.rb
parentf63d7076e52a8844f1cfe43e57330687d88e83b6 (diff)
Big documentation update.
Diffstat (limited to 'lib/mauve/processor.rb')
-rw-r--r--lib/mauve/processor.rb84
1 files changed, 56 insertions, 28 deletions
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb
index d68c551..c8a1dfb 100644
--- a/lib/mauve/processor.rb
+++ b/lib/mauve/processor.rb
@@ -4,12 +4,23 @@ require 'mauve/mauve_thread'
module Mauve
+ #
+ # This class is a singlton thread which pops updates off the
+ # Server#packet_buffer and processes them as alert updates.
+ #
+ # It is responsible for de-bouncing updates, i.e. ones with duplicate
+ # transmission IDs.
+ #
class Processor < MauveThread
include Singleton
+ # This is the time after which transmission IDs are expired.
+ #
attr_reader :transmission_cache_expire_time
+ # Initialize the processor
+ #
def initialize
super
#
@@ -20,15 +31,58 @@ module Mauve
@transmission_cache_checked_at = Time.now
end
+ # @return [Log4r::Logger]
def logger
@logger ||= Log4r::Logger.new(self.class.to_s)
end
+ # Set the expiry time
+ #
+ # @param [Integer] i The number of seconds after which transmission IDs are considered unseen.
+ # @raise [ArgumentError] If +i+ is not an Integer
def transmission_cache_expire_time=(i)
raise ArgumentError, "transmission_cache_expire_time must be an integer" unless i.is_a?(Integer)
@transmission_cache_expire_time = i
end
+ # This expries the transmission cache
+ #
+ #
+ def expire_transmission_id_cache
+ now = Time.now
+ #
+ # Only check once every minute.
+ #
+ return unless (now - @transmission_cache_checked_at) > 60
+
+ to_delete = []
+
+ @transmission_id_cache.each do |tid, received_at|
+ to_delete << tid if (now - received_at) > @transmission_cache_expire_time
+ end
+
+ to_delete.each do |tid|
+ @transmission_id_cache.delete(tid)
+ end
+
+ @transmission_cache_checked_at = now
+ end
+
+ # This stops the processor, making sure all pending updates are saved.
+ #
+ def stop
+ super
+
+ #
+ # flush the queue
+ #
+ main_loop
+ end
+
+ private
+
+ # This is the main loop that does the processing.
+ #
def main_loop
sz = Server.packet_buffer_size
@@ -92,33 +146,7 @@ module Mauve
Timer.instance.thaw if Timer.instance.frozen?
end
- def expire_transmission_id_cache
- now = Time.now
- #
- # Only check once every minute.
- #
- return unless (now - @transmission_cache_checked_at) > 60
-
- to_delete = []
-
- @transmission_id_cache.each do |tid, received_at|
- to_delete << tid if (now - received_at) > @transmission_cache_expire_time
- end
-
- to_delete.each do |tid|
- @transmission_id_cache.delete(tid)
- end
-
- @transmission_cache_checked_at = now
- end
-
- def stop
- super
-
- #
- # flush the queue
- #
- main_loop
- end
end
+
end
+