Class: Metering::MeteringRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_appconfiguration_ruby_sdk/core/metering.rb

Overview

Inner class for storing metering records Tracks count and latest evaluation time with thread-safe operations

Instance Method Summary collapse

Constructor Details

#initialize(time) ⇒ MeteringRecord

Initialize a new metering record

Parameters:

  • time (String)

    Initial evaluation time in ISO 8601 format



78
79
80
81
82
# File 'lib/ibm_appconfiguration_ruby_sdk/core/metering.rb', line 78

def initialize(time)
  @count = 1
  @latest_time = time
  @mutex = Mutex.new
end

Instance Method Details

#get_countInteger

Get the current count (thread-safe)

Returns:

  • (Integer)

    The evaluation count



99
100
101
# File 'lib/ibm_appconfiguration_ruby_sdk/core/metering.rb', line 99

def get_count
  @mutex.synchronize { @count }
end

#get_latest_timeString

Get the latest evaluation time (thread-safe)

Returns:

  • (String)

    The latest evaluation time



107
108
109
# File 'lib/ibm_appconfiguration_ruby_sdk/core/metering.rb', line 107

def get_latest_time
  @mutex.synchronize { @latest_time }
end

#increment(new_time) ⇒ Object

Increment the count and update latest time if newer

Parameters:

  • new_time (String)

    New evaluation time in ISO 8601 format



88
89
90
91
92
93
# File 'lib/ibm_appconfiguration_ruby_sdk/core/metering.rb', line 88

def increment(new_time)
  @mutex.synchronize do
    @count += 1
    @latest_time = new_time if new_time > @latest_time
  end
end