Class: ICWS::Messages::MessageQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/icws/messages/messagequeue.rb

Overview

The message queue manages callbacks for different objects that are receiving messages from CIC.

Defined Under Namespace

Classes: EventHandlerArray

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ MessageQueue

Returns a new instance of MessageQueue.



28
29
30
31
32
33
34
35
# File 'lib/icws/messages/messagequeue.rb', line 28

def initialize(connection)
    @message_handlers = {}
    @client = ICWS::Client.new connection

    @pollingThread = Thread.new() {
        poll_loop
    }
end

Instance Method Details

#deregister(messageType, code) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/icws/messages/messagequeue.rb', line 48

def deregister(messageType, code)
    if(@message_handlers[messageType] == nil)
        return
    end

    @message_handlers[messageType].remove_handler(code)
end

#register(messageType, &block) ⇒ Object

register for a new message type.

Parameters:

  • messageType (String)

    The type of messages to receive notifications for.

  • block (&block)

    Block to call when a message of that type is received.



40
41
42
43
44
45
46
# File 'lib/icws/messages/messagequeue.rb', line 40

def register(messageType, &block)
    if(@message_handlers[messageType] == nil)
        @message_handlers[messageType] = EventHandlerArray.new
    end
    callback = block
    @message_handlers[messageType].add_handler {|e| callback.call(e)}
end