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.
63 64 65 66 |
# File 'lib/snmp/manager.rb', line 63 def initialize @lock = Mutex.new @request_id = rand(MAX_REQUEST_ID) end |
Instance Method Details
#force_next(next_id) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# 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 ⇒ Object
68 69 70 71 72 73 74 |
# 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 |