Class: Redistat::Buffer

Inherits:
Object
  • Object
show all
Includes:
Synchronize
Defined in:
lib/redistat/buffer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Synchronize

included, monitor, thread_safe, thread_safe=

Class Method Details

.instanceObject



7
8
9
# File 'lib/redistat/buffer.rb', line 7

def self.instance
  @instance ||= self.new
end

Instance Method Details

#countObject



23
24
25
# File 'lib/redistat/buffer.rb', line 23

def count
  @count ||= 0
end

#flush(force = false) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/redistat/buffer.rb', line 53

def flush(force = false)
  to_flush = {}
  synchronize do
    to_flush = reset_queue(force)
  end
  flush_data(to_flush)
end

#sizeObject



11
12
13
14
15
# File 'lib/redistat/buffer.rb', line 11

def size
  synchronize do
    @size ||= 0
  end
end

#size=(value) ⇒ Object



17
18
19
20
21
# File 'lib/redistat/buffer.rb', line 17

def size=(value)
  synchronize do
    @size = value
  end
end

#store(key, stats, depth_limit, opts) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/redistat/buffer.rb', line 27

def store(key, stats, depth_limit, opts)
  return false unless should_buffer?

  to_flush = {}
  buffkey = buffer_key(key, opts)

  synchronize do
    if !queue.has_key?(buffkey)
      queue[buffkey] = { :key         => key,
                         :stats       => {},
                         :depth_limit => depth_limit,
                         :opts        => opts }
    end

    queue[buffkey][:stats].merge_and_incr!(stats)
    incr_count

    # return items to be flushed if buffer size limit has been reached
    to_flush = reset_queue
  end

  # flush any data that's been cleared from the queue
  flush_data(to_flush)
  true
end