Class MPv3.Cache

java.lang.Object
org.snmp4j.mp.MPv3.Cache
Enclosing class:
MPv3

protected static class MPv3.Cache extends Object
The Cache stores state reference information for the MPv3.
Version:
3.4.0
Author:
Frank Fock
  • Constructor Details

    • Cache

      protected Cache()
  • Method Details

    • addEntry

      public int addEntry(StateReference<?> entry)
      Adds a StateReference to the cache. The PduHandle of the supplied entry will be set to null when the new entry is already part of the cache, because the cache uses a WeakHashMap internally which uses the PduHandle as key. If the new entry equals an existing entry except of the message ID then the new message ID will be added to the existing entry.
      Parameters:
      entry - the state reference to add.
      Returns:
      SnmpConstants.SNMP_MP_DOUBLED_MESSAGE if the entry already exists, SnmpConstants.SNMP_MP_MATCH_ERROR if any of the message IDs of the supplied entry is already associated with another live cache entry (since 3.13.0), and SnmpConstants.SNMP_MP_OK on success.
    • consumeEntry

      public boolean consumeEntry(MessageID messageID, StateReference<?> expectedEntry)
      Removes the cache entry with the supplied message ID from the cache, but only if it is still the same entry instance that has been looked up before with getEntry(MessageID, boolean).

      This provides the atomicity needed to validate a received response or report against a cache entry without consuming that entry when the validation fails: a mismatching message leaves the entry in place for the legitimate response, while a matching message consumes it exactly once, even if two matching messages are processed concurrently.

      Parameters:
      messageID - the message ID of the entry to consume.
      expectedEntry - the entry instance that is expected to be found for messageID.
      Returns:
      true if the entry has been removed by this call. The PduHandle of expectedEntry is restored in that case.
      Since:
      3.13.0
    • deleteEntry

      public boolean deleteEntry(PduHandle pduHandle)
      Delete the cache entry with the supplied PduHandle.
      Parameters:
      pduHandle - a pduHandle.
      Returns:
      true if an entry has been deleted, false otherwise.
    • getEntry

      public StateReference<?> getEntry(MessageID messageID, boolean removeFoundEntry)
      Gets the cache entry with the supplied ID from the cache.
      Parameters:
      messageID - a message ID.
      removeFoundEntry - if true, the found entry will be removed from the cache before it is returned, otherwise it is returned only.
      Returns:
      a MPv3.CacheEntry instance with the given message ID or null if such an entry cannot be found.
      Since:
      3.4.0
    • popEntry

      public StateReference<?> popEntry(MessageID messageID)
      Pop the cache entry with the supplied ID from the cache.
      Parameters:
      messageID - a message ID.
      Returns:
      a MPv3.CacheEntry instance with the given message ID or null if such an entry cannot be found. If a cache entry is returned, the same is removed from the cache.