Class: SNMP::RequestId
- Inherits:
-
Object
- Object
- SNMP::RequestId
- Defined in:
- lib/snmp/manager.rb
Overview
Manage a request-id in the range 1..2**31-1
Constant Summary collapse
- MAX_REQUEST_ID =
2**31
Instance Method Summary collapse
- #force_next(next_id) ⇒ Object
-
#initialize ⇒ RequestId
constructor
A new instance of RequestId.
- #next ⇒ Object
Constructor Details
#initialize ⇒ RequestId
Returns a new instance of RequestId.
49 50 51 52 |
# File 'lib/snmp/manager.rb', line 49 def initialize @lock = Mutex.new @request_id = rand(MAX_REQUEST_ID) end |
Instance Method Details
#force_next(next_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/snmp/manager.rb', line 62 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 ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/snmp/manager.rb', line 54 def next @lock.synchronize do @request_id += 1 @request_id = 1 if @request_id == MAX_REQUEST_ID return @request_id end end |