Class OpenSslCachingKeyMaterialProvider

java.lang.Object
io.netty.handler.ssl.OpenSslKeyMaterialProvider
io.netty.handler.ssl.OpenSslCachingKeyMaterialProvider

final class OpenSslCachingKeyMaterialProvider extends OpenSslKeyMaterialProvider
OpenSslKeyMaterialProvider that will cache the OpenSslKeyMaterial to reduce the overhead of parsing the chain and the key for generation of the material.

Cache reads are lock-free (ConcurrentHashMap.get(Object) + retain()); if a concurrent eviction releases the material in between, retain() detects the dead reference count and the read falls back to a cache miss. Mutations (insert, evict, destroy) use ConcurrentHashMap.compute(K, BiFunction) / ConcurrentHashMap.computeIfPresent(K, BiFunction) for atomicity.

  • Field Details

    • maxCachedEntries

      private final int maxCachedEntries
    • cache

      private final java.util.concurrent.ConcurrentHashMap<java.lang.String, OpenSslKeyMaterial> cache
    • destroyed

      private volatile boolean destroyed
  • Constructor Details

    • OpenSslCachingKeyMaterialProvider

      OpenSslCachingKeyMaterialProvider(javax.net.ssl.X509KeyManager keyManager, java.lang.String password, int maxEntries)
  • Method Details

    • getAndRetain

      private OpenSslKeyMaterial getAndRetain(java.lang.String alias)
      Lock-free cache lookup. If a concurrent eviction releases the material between get and retain, the dead reference count is detected and treated as a cache miss.
    • putIfAbsentAndRetain

      private OpenSslKeyMaterial putIfAbsentAndRetain(java.lang.String alias, OpenSslKeyMaterial material)
      Atomically inserts material if absent, or retains the existing entry.
    • removeAndRelease

      private void removeAndRelease(java.lang.String alias)
      Atomically removes and releases the entry for the given alias.
    • evictStaleEntries

      private void evictStaleEntries()
    • chooseKeyMaterial

      OpenSslKeyMaterial chooseKeyMaterial(ByteBufAllocator allocator, java.lang.String alias) throws java.lang.Exception
      Description copied from class: OpenSslKeyMaterialProvider
      Returns the OpenSslKeyMaterial or null (if none) that should be used during the handshake by OpenSSL.
      Overrides:
      chooseKeyMaterial in class OpenSslKeyMaterialProvider
      Throws:
      java.lang.Exception
    • cacheSize

      int cacheSize()
    • destroy

      void destroy()
      Description copied from class: OpenSslKeyMaterialProvider
      Will be invoked once the provider should be destroyed.
      Overrides:
      destroy in class OpenSslKeyMaterialProvider
    • removeAndReleaseAllEntries

      private void removeAndReleaseAllEntries()