Class: RhetButler::SlideMessageQueue

Inherits:
Object
  • Object
show all
Includes:
Thin::Logging
Defined in:
lib/rhet-butler/messaging.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSlideMessageQueue

Returns a new instance of SlideMessageQueue.



47
48
49
# File 'lib/rhet-butler/messaging.rb', line 47

def initialize
  @listeners = {}
end

Instance Attribute Details

#current_slideObject

Returns the value of attribute current_slide.



46
47
48
# File 'lib/rhet-butler/messaging.rb', line 46

def current_slide
  @current_slide
end

Instance Method Details

#enqueue(message) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/rhet-butler/messaging.rb', line 64

def enqueue(message)
  @listeners.keys.each do |session|
    begin
      session.send(message)
    rescue MetaState::WrongStateError => wse
      log_info("Follower in wrong state: #{wse.inspect}")
      @listeners.delete(session)
    end
  end
end

#inspectObject



51
52
53
# File 'lib/rhet-butler/messaging.rb', line 51

def inspect
  "<<#{self.class.name} Listeners: #{@listeners.keys.length}>>"
end

#subscribe(session) ⇒ Object



55
56
57
58
# File 'lib/rhet-butler/messaging.rb', line 55

def subscribe(session)
  @listeners[session] = true
  session.send(current_slide) unless current_slide.nil?
end

#unsubscribe(session) ⇒ Object



60
61
62
# File 'lib/rhet-butler/messaging.rb', line 60

def unsubscribe(session)
  @listeners.delete(session)
end