OpenSslSessionCache Class — netty Architecture
Architecture documentation for the OpenSslSessionCache class in OpenSslSessionCache.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 6355c604_3e83_2b17_e056_558795a68fc3["OpenSslSessionCache"] 94dac1de_c6bf_c38a_f7ce_442307ca85ac["OpenSslSessionCache.java"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|defined in| 94dac1de_c6bf_c38a_f7ce_442307ca85ac 16720002_b775_564a_1581_acd54cf3f52f["OpenSslSessionCache()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 16720002_b775_564a_1581_acd54cf3f52f 919846fd_dbce_c55a_1683_045053f5dc5f["setSessionTimeout()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 919846fd_dbce_c55a_1683_045053f5dc5f 7c2bc31e_7c81_c6ab_d924_7c4a80f05341["getSessionTimeout()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 7c2bc31e_7c81_c6ab_d924_7c4a80f05341 b0c9f020_ce9e_89e3_fb97_acebd4a5fba9["sessionCreated()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| b0c9f020_ce9e_89e3_fb97_acebd4a5fba9 9e657eea_135c_cd04_0ad0_a5a82887f4e9["sessionRemoved()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 9e657eea_135c_cd04_0ad0_a5a82887f4e9 74024072_3aea_8389_5305_56f72736f6e7["setSessionCacheSize()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 74024072_3aea_8389_5305_56f72736f6e7 730e357f_913c_fdea_83b4_7614b436810f["getSessionCacheSize()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 730e357f_913c_fdea_83b4_7614b436810f 47cfafe5_3408_4ef1_83f8_ee5da65e49ad["expungeInvalidSessions()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 47cfafe5_3408_4ef1_83f8_ee5da65e49ad 219256b2_175f_0f2b_aca5_e31008ba7083["getSession()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 219256b2_175f_0f2b_aca5_e31008ba7083 44034663_ece6_251f_228b_89a3c8b66a99["setSession()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| 44034663_ece6_251f_228b_89a3c8b66a99 adc4a21b_2741_c870_2d79_c0b7f58a00b1["removeSessionWithId()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| adc4a21b_2741_c870_2d79_c0b7f58a00b1 db0b70e7_d057_76d1_b1ac_6e79d81c5058["containsSessionWithId()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| db0b70e7_d057_76d1_b1ac_6e79d81c5058 fffde80d_79d3_d174_a852_3dbd539cda36["notifyRemovalAndFree()"] 6355c604_3e83_2b17_e056_558795a68fc3 -->|method| fffde80d_79d3_d174_a852_3dbd539cda36
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/OpenSslSessionCache.java lines 39–526
class OpenSslSessionCache implements SSLSessionCache {
private static final OpenSslInternalSession[] EMPTY_SESSIONS = new OpenSslInternalSession[0];
private static final int DEFAULT_CACHE_SIZE;
static {
// Respect the same system property as the JDK implementation to make it easy to switch between implementations.
int cacheSize = SystemPropertyUtil.getInt("javax.net.ssl.sessionCacheSize", 20480);
if (cacheSize >= 0) {
DEFAULT_CACHE_SIZE = cacheSize;
} else {
DEFAULT_CACHE_SIZE = 20480;
}
}
private final Map<Long, ReferenceCountedOpenSslEngine> engines;
private final Map<OpenSslSessionId, NativeSslSession> sessions =
new LinkedHashMap<OpenSslSessionId, NativeSslSession>() {
private static final long serialVersionUID = -7773696788135734448L;
@Override
protected boolean removeEldestEntry(Map.Entry<OpenSslSessionId, NativeSslSession> eldest) {
int maxSize = maximumCacheSize.get();
if (maxSize >= 0 && size() > maxSize) {
removeSessionWithId(eldest.getKey());
}
// We always need to return false as we modify the map directly.
return false;
}
};
private final AtomicInteger maximumCacheSize = new AtomicInteger(DEFAULT_CACHE_SIZE);
// Let's use the same default value as OpenSSL does.
// See https://www.openssl.org/docs/man1.1.1/man3/SSL_get_default_timeout.html
private final AtomicInteger sessionTimeout = new AtomicInteger(300);
private int sessionCounter;
OpenSslSessionCache(Map<Long, ReferenceCountedOpenSslEngine> engines) {
this.engines = engines;
}
final void setSessionTimeout(int seconds) {
int oldTimeout = sessionTimeout.getAndSet(seconds);
if (oldTimeout > seconds) {
// Drain the whole cache as this way we can use the ordering of the LinkedHashMap to detect early
// if there are any other sessions left that are invalid.
clear();
}
}
final int getSessionTimeout() {
return sessionTimeout.get();
}
/**
* Called once a new {@link OpenSslInternalSession} was created.
*
* @param session the new session.
* @return {@code true} if the session should be cached, {@code false} otherwise.
*/
protected boolean sessionCreated(NativeSslSession session) {
return true;
}
/**
* Called once an {@link OpenSslInternalSession} was removed from the cache.
*
* @param session the session to remove.
*/
protected void sessionRemoved(NativeSslSession session) { }
final void setSessionCacheSize(int size) {
long oldSize = maximumCacheSize.getAndSet(size);
if (oldSize > size || size == 0) {
// Just keep it simple for now and drain the whole cache.
clear();
}
}
final int getSessionCacheSize() {
Source
Frequently Asked Questions
What is the OpenSslSessionCache class?
OpenSslSessionCache is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/OpenSslSessionCache.java.
Where is OpenSslSessionCache defined?
OpenSslSessionCache is defined in handler/src/main/java/io/netty/handler/ssl/OpenSslSessionCache.java at line 39.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free