/** * Makes sure cache size is < maximumSize. */ private void trimToSize() { synchronized (sessions) { int size = sessions.size(); if (size > maximumSize) { int removals = size - maximumSize; Iterator<NativeSslSession> i = sessions.values().iterator(); while (removals-- > 0) { NativeSslSession session = i.next(); onBeforeRemoveSession(session); i.remove(); } } } } }
/** * Makes sure cache size is < maximumSize. */ private void trimToSize() { synchronized (sessions) { int size = sessions.size(); if (size > maximumSize) { int removals = size - maximumSize; Iterator<NativeSslSession> i = sessions.values().iterator(); while (removals-- > 0) { NativeSslSession session = i.next(); onBeforeRemoveSession(session); i.remove(); } } } } }
@Override protected boolean removeEldestEntry( Map.Entry<ByteArray, NativeSslSession> eldest) { // NOTE: does not take into account any session that may have become // invalid. if (maximumSize > 0 && size() > maximumSize) { // Let the subclass know. onBeforeRemoveSession(eldest.getValue()); return true; } return false; } };
@Override protected boolean removeEldestEntry( Map.Entry<ByteArray, NativeSslSession> eldest) { // NOTE: does not take into account any session that may have become // invalid. if (maximumSize > 0 && size() > maximumSize) { // Let the subclass know. onBeforeRemoveSession(eldest.getValue()); return true; } return false; } };
/** * Removes the given session from the cache. */ final void removeSession(NativeSslSession session) { byte[] id = session.getId(); if (id == null || id.length == 0) { return; } onBeforeRemoveSession(session); ByteArray key = new ByteArray(id); synchronized (sessions) { sessions.remove(key); } }
/** * Removes the given session from the cache. */ final void removeSession(NativeSslSession session) { byte[] id = session.getId(); if (id == null || id.length == 0) { return; } onBeforeRemoveSession(session); ByteArray key = new ByteArray(id); synchronized (sessions) { sessions.remove(key); } }
@Override public final void setSessionTimeout(int seconds) throws IllegalArgumentException { if (seconds < 0) { throw new IllegalArgumentException("seconds < 0"); } synchronized (sessions) { // Set the timeout on this context. timeout = seconds; // setSessionTimeout(0) is defined to remove the timeout, but passing 0 // to SSL_CTX_set_timeout in BoringSSL sets it to the default timeout instead. // Pass INT_MAX seconds (68 years), since that's equivalent for practical purposes. if (seconds > 0) { NativeCrypto.SSL_CTX_set_timeout(sslCtxNativePointer, this, seconds); } else { NativeCrypto.SSL_CTX_set_timeout(sslCtxNativePointer, this, Integer.MAX_VALUE); } Iterator<NativeSslSession> i = sessions.values().iterator(); while (i.hasNext()) { NativeSslSession session = i.next(); // SSLSession's know their context and consult the // timeout as part of their validity condition. if (!session.isValid()) { // Let the subclass know. onBeforeRemoveSession(session); i.remove(); } } } }
@Override public final void setSessionTimeout(int seconds) throws IllegalArgumentException { if (seconds < 0) { throw new IllegalArgumentException("seconds < 0"); } synchronized (sessions) { // Set the timeout on this context. timeout = seconds; // setSessionTimeout(0) is defined to remove the timeout, but passing 0 // to SSL_CTX_set_timeout in BoringSSL sets it to the default timeout instead. // Pass INT_MAX seconds (68 years), since that's equivalent for practical purposes. if (seconds > 0) { NativeCrypto.SSL_CTX_set_timeout(sslCtxNativePointer, this, seconds); } else { NativeCrypto.SSL_CTX_set_timeout(sslCtxNativePointer, this, Integer.MAX_VALUE); } Iterator<NativeSslSession> i = sessions.values().iterator(); while (i.hasNext()) { NativeSslSession session = i.next(); // SSLSession's know their context and consult the // timeout as part of their validity condition. if (!session.isValid()) { // Let the subclass know. onBeforeRemoveSession(session); i.remove(); } } } }