Class: Connfu::Listener
- Inherits:
-
Object
- Object
- Connfu::Listener
- Includes:
- ConnfuLogger
- Defined in:
- lib/connfu/listener.rb
Overview
Class that listen to external events. Delegates the behavior in ConnfuStream so any new external resource can be added and no need to change the interface is required
Instance Attribute Summary collapse
-
#app_stream ⇒ Object
readonly
Returns the value of attribute app_stream.
-
#continue ⇒ Object
readonly
checks if the thread should continue listening or return.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#max_messages ⇒ Object
max amount of messages to receive.
Instance Method Summary collapse
-
#initialize(queue, app_stream, token, stream_endpoint) ⇒ Listener
constructor
Listener initializer.
-
#join ⇒ Object
Wait to get external events.
-
#start(queue = nil) ⇒ Object
start listening.
-
#stop ⇒ Object
stop waiting for external events.
Methods included from ConnfuLogger
Constructor Details
#initialize(queue, app_stream, token, stream_endpoint) ⇒ Listener
Listener initializer.
Parameters
-
queueConnfu::Events instance to forward incoming events to be processed by the Dispatcher class -
app_streamvalid HTTP stream url to connect and listen events -
tokenvalid token to get access to a connFu Stream -
stream_endpointendpoint to open a keepalive HTTP connection
27 28 29 30 31 32 33 |
# File 'lib/connfu/listener.rb', line 27 def initialize(queue, app_stream, token, stream_endpoint) @connfu_stream = Connfu::ConnfuStream.new(app_stream, token, stream_endpoint) @continue = true @counter = 0 @max_messages = 0 @queue = queue end |
Instance Attribute Details
#app_stream ⇒ Object (readonly)
Returns the value of attribute app_stream.
16 17 18 |
# File 'lib/connfu/listener.rb', line 16 def app_stream @app_stream end |
#continue ⇒ Object (readonly)
checks if the thread should continue listening or return
75 76 77 |
# File 'lib/connfu/listener.rb', line 75 def continue @continue end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
15 16 17 |
# File 'lib/connfu/listener.rb', line 15 def counter @counter end |
#max_messages ⇒ Object
max amount of messages to receive
17 18 19 |
# File 'lib/connfu/listener.rb', line 17 def @max_messages end |
Instance Method Details
#join ⇒ Object
Wait to get external events
63 64 65 |
# File 'lib/connfu/listener.rb', line 63 def join @thread.join end |
#start(queue = nil) ⇒ Object
start listening. Should create a new thread and wait to new events to come
Parameters
-
queueto send incoming events to the Dispatcher class
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/connfu/listener.rb', line 40 def start(queue = nil) queue.nil? and queue = @queue logger.debug "Listener starts..." @thread = Thread.new { # listen to connFu @connfu_stream.start_listening } while continue do logger.debug "Waiting for a message from connFu stream" = @connfu_stream.get @counter = @counter + 1 logger.debug "#{self.class} got message => #{}" # Write in internal Queue queue.put() end end |
#stop ⇒ Object
stop waiting for external events
69 70 71 |
# File 'lib/connfu/listener.rb', line 69 def stop @continue = false end |