SnmpKit.SnmpMgr.RequestIdGenerator (snmpkit v2.0.1)
Atomic request ID generator using ETS for thread-safe counter operations.
Provides unique request IDs for SNMP operations without requiring GenServer synchronization, eliminating serialization bottlenecks.
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets the current counter value without incrementing.
Like next_id/0, but returns {:error, :services_not_started} instead of
raising when the generator is not running. There is no fallback id: a random
one could collide with a request already in flight.
Generates the next unique request ID.
Resets the counter to 0.
Starts the RequestIdGenerator GenServer.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets the current counter value without incrementing.
Useful for debugging and monitoring.
@spec fetch_next_id() :: {:ok, pos_integer()} | {:error, :services_not_started}
Like next_id/0, but returns {:error, :services_not_started} instead of
raising when the generator is not running. There is no fallback id: a random
one could collide with a request already in flight.
@spec next_id() :: pos_integer()
Generates the next unique request ID.
Uses atomic ETS operations for thread-safe counter increment. Wraps around
at 1000000; SnmpKit.SnmpMgr.Engine refuses to register an id
that is still pending, so a wrapped id is never reused while its earlier
request is in flight.
Raises ArgumentError when the generator is not running; fetch_next_id/0
is the non-raising form.
Examples
iex> SnmpKit.SnmpMgr.RequestIdGenerator.next_id()
1
iex> SnmpKit.SnmpMgr.RequestIdGenerator.next_id()
2
Resets the counter to 0.
Primarily used for testing.
Starts the RequestIdGenerator GenServer.
Creates the ETS table for atomic counter operations.