Class: NetuitiveRubyApi::DataCache

Inherits:
Object
  • Object
show all
Defined in:
lib/netuitive_ruby_api/data_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeDataCache

Returns a new instance of DataCache.



3
4
5
6
7
8
# File 'lib/netuitive_ruby_api/data_cache.rb', line 3

def initialize
  @sample_count_mutex = Mutex.new
  @event_count_mutex = Mutex.new
  reset_samples
  reset_events
end

Instance Method Details

#add_aggregate_counter_metric(value) ⇒ Object



39
40
41
42
43
44
# File 'lib/netuitive_ruby_api/data_cache.rb', line 39

def add_aggregate_counter_metric(value)
  @sample_count_mutex.synchronize do
    @aggregate_counter_metrics.push(value)
    sample_added
  end
end

#add_aggregate_metric(value) ⇒ Object



32
33
34
35
36
37
# File 'lib/netuitive_ruby_api/data_cache.rb', line 32

def add_aggregate_metric(value)
  @sample_count_mutex.synchronize do
    @aggregate_metrics.push(value)
    sample_added
  end
end

#add_counter_sample(value) ⇒ Object



25
26
27
28
29
30
# File 'lib/netuitive_ruby_api/data_cache.rb', line 25

def add_counter_sample(value)
  @sample_count_mutex.synchronize do
    @counter_samples.push(value)
    sample_added
  end
end

#add_event(value) ⇒ Object



46
47
48
49
50
51
# File 'lib/netuitive_ruby_api/data_cache.rb', line 46

def add_event(value)
  @event_count_mutex.synchronize do
    @events.push(value)
    event_added
  end
end

#add_exception_event(value) ⇒ Object



53
54
55
56
57
58
# File 'lib/netuitive_ruby_api/data_cache.rb', line 53

def add_exception_event(value)
  @event_count_mutex.synchronize do
    @exception_events.push(value)
    event_added
  end
end

#add_sample(value) ⇒ Object



18
19
20
21
22
23
# File 'lib/netuitive_ruby_api/data_cache.rb', line 18

def add_sample(value)
  @sample_count_mutex.synchronize do
    @samples.push(value)
    sample_added
  end
end

#clear_event_cacheObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/netuitive_ruby_api/data_cache.rb', line 76

def clear_event_cache
  NetuitiveRubyApi::ErrorLogger.guard('error during clear_event_cache') do
    @event_count_mutex.synchronize do
      NetuitiveRubyApi::NetuitiveLogger.log.debug 'clearing event cache'
      ret = {
        events: @events.dup,
        exception_events: @exception_events.dup
      }
      reset_events
      ret
    end
  end
end

#clear_sample_cacheObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/netuitive_ruby_api/data_cache.rb', line 60

def clear_sample_cache
  NetuitiveRubyApi::ErrorLogger.guard('error during clear_sample_cache') do
    @sample_count_mutex.synchronize do
      NetuitiveRubyApi::NetuitiveLogger.log.debug 'clearing sample cache'
      ret = {
        samples: @samples.dup,
        counter_samples: @counter_samples.dup,
        aggregate_metrics: @aggregate_metrics.dup,
        aggregate_counter_metrics: @aggregate_counter_metrics.dup
      }
      reset_samples
      ret
    end
  end
end

#event_addedObject



14
15
16
# File 'lib/netuitive_ruby_api/data_cache.rb', line 14

def event_added
  @event_count += 1
end

#reset_eventsObject



98
99
100
101
102
# File 'lib/netuitive_ruby_api/data_cache.rb', line 98

def reset_events
  @events = []
  @exception_events = []
  @event_count = 0
end

#reset_samplesObject



90
91
92
93
94
95
96
# File 'lib/netuitive_ruby_api/data_cache.rb', line 90

def reset_samples
  @samples = []
  @counter_samples = []
  @aggregate_metrics = []
  @aggregate_counter_metrics = []
  @sample_count = 0
end

#sample_addedObject



10
11
12
# File 'lib/netuitive_ruby_api/data_cache.rb', line 10

def sample_added
  @sample_count += 1
end