class SNMP::RequestId

Manage a request-id in the range 1..2**31-1

Constants

MAX_REQUEST_ID

Public Class Methods

new() click to toggle source
# File lib/snmp/manager.rb, line 63
def initialize
  @lock = Mutex.new
  @request_id = rand(MAX_REQUEST_ID)
end

Public Instance Methods

force_next(next_id) click to toggle source
# File lib/snmp/manager.rb, line 76
def force_next(next_id)
  new_request_id = next_id.to_i
  if new_request_id < 1 || new_request_id >= MAX_REQUEST_ID
    raise "Invalid request id: #{new_request_id}"
  end
  new_request_id = MAX_REQUEST_ID if new_request_id == 1
  @lock.synchronize do
    @request_id = new_request_id - 1
  end
end
next() click to toggle source
# File lib/snmp/manager.rb, line 68
def next
  @lock.synchronize do
    @request_id += 1
    @request_id = 1 if @request_id == MAX_REQUEST_ID
    return @request_id
  end
end