Class: SuperPoller::BufferedHandler
- Inherits:
-
Handler
- Object
- Handler
- SuperPoller::BufferedHandler
show all
- Defined in:
- lib/super_poller/buffered_handler.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Handler
#can_handle?, handles, message_names
Constructor Details
Returns a new instance of BufferedHandler.
12
13
14
|
# File 'lib/super_poller/buffered_handler.rb', line 12
def initialize
@buffer = []
end
|
Class Method Details
.buffer_size(size) ⇒ Object
3
4
5
|
# File 'lib/super_poller/buffered_handler.rb', line 3
def buffer_size(size)
@max_buffer_size = size
end
|
.max_buffer_size ⇒ Object
7
8
9
|
# File 'lib/super_poller/buffered_handler.rb', line 7
def max_buffer_size
@max_buffer_size || []
end
|
Instance Method Details
#call(msg) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/super_poller/buffered_handler.rb', line 16
def call(msg)
@buffer.push msg
if @buffer.size >= self.class.max_buffer_size
handle_batch @buffer
@buffer = []
end
end
|
#handle_batch(batch) ⇒ Object
24
25
26
|
# File 'lib/super_poller/buffered_handler.rb', line 24
def handle_batch(batch)
raise NotImplementedError, "You must define a batch handler."
end
|