Package io.netty.handler.ssl
Class OpenSslCachingKeyMaterialProvider
- java.lang.Object
-
- io.netty.handler.ssl.OpenSslKeyMaterialProvider
-
- io.netty.handler.ssl.OpenSslCachingKeyMaterialProvider
-
final class OpenSslCachingKeyMaterialProvider extends OpenSslKeyMaterialProvider
OpenSslKeyMaterialProviderthat will cache theOpenSslKeyMaterialto reduce the overhead of parsing the chain and the key for generation of the material.Cache reads are lock-free (
ConcurrentHashMap.get(java.lang.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) useConcurrentHashMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>)/ConcurrentHashMap.computeIfPresent(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>)for atomicity.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentHashMap<java.lang.String,OpenSslKeyMaterial>cacheprivate booleandestroyedprivate intmaxCachedEntries
-
Constructor Summary
Constructors Constructor Description OpenSslCachingKeyMaterialProvider(javax.net.ssl.X509KeyManager keyManager, java.lang.String password, int maxEntries)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intcacheSize()(package private) OpenSslKeyMaterialchooseKeyMaterial(ByteBufAllocator allocator, java.lang.String alias)Returns theOpenSslKeyMaterialornull(if none) that should be used during the handshake by OpenSSL.(package private) voiddestroy()Will be invoked once the provider should be destroyed.private voidevictStaleEntries()private OpenSslKeyMaterialgetAndRetain(java.lang.String alias)Lock-free cache lookup.private OpenSslKeyMaterialputIfAbsentAndRetain(java.lang.String alias, OpenSslKeyMaterial material)Atomically inserts material if absent, or retains the existing entry.private voidremoveAndRelease(java.lang.String alias)Atomically removes and releases the entry for the given alias.private voidremoveAndReleaseAllEntries()-
Methods inherited from class io.netty.handler.ssl.OpenSslKeyMaterialProvider
keyManager, validateKeyMaterialSupported
-
-
-
-
Field Detail
-
maxCachedEntries
private final int maxCachedEntries
-
cache
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,OpenSslKeyMaterial> cache
-
destroyed
private volatile boolean destroyed
-
-
Method Detail
-
getAndRetain
private OpenSslKeyMaterial getAndRetain(java.lang.String alias)
Lock-free cache lookup. If a concurrent eviction releases the material betweengetandretain, 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:OpenSslKeyMaterialProviderReturns theOpenSslKeyMaterialornull(if none) that should be used during the handshake by OpenSSL.- Overrides:
chooseKeyMaterialin classOpenSslKeyMaterialProvider- Throws:
java.lang.Exception
-
cacheSize
int cacheSize()
-
destroy
void destroy()
Description copied from class:OpenSslKeyMaterialProviderWill be invoked once the provider should be destroyed.- Overrides:
destroyin classOpenSslKeyMaterialProvider
-
removeAndReleaseAllEntries
private void removeAndReleaseAllEntries()
-
-