Methods Summary |
---|
public javax.net.ssl.SSLSession | getSession(byte[] sessionId){@inheritDoc}
/*
* This method is typically used in conjunction with getIds() to
* iterate over the sessions linearly, so it doesn't make sense for
* it to impact access order.
*
* It also doesn't load sessions from the persistent cache as doing
* so would likely force every session to load.
*/
ByteArray id = new ByteArray(sessionId);
synchronized (sessions) {
indexById();
return sessionsById.get(id);
}
|
public javax.net.ssl.SSLSession | getSession(java.lang.String host, int port)Finds a cached session for the given host name and port.
synchronized (sessions) {
SSLSession session = sessions.get(new HostAndPort(host, port));
if (session != null) {
return session;
}
}
// Look in persistent cache.
if (persistentCache != null) {
byte[] data = persistentCache.getSessionData(host, port);
if (data != null) {
SSLSession session = toSession(data, host, port);
if (session != null) {
synchronized (sessions) {
sessions.put(new HostAndPort(host, port), session);
indexById(session);
}
return session;
}
}
}
return null;
|
private void | indexById()Ensures that the ID-based index is initialized.
if (sessionsById == null) {
sessionsById = new HashMap<ByteArray, SSLSession>();
for (SSLSession session : sessions.values()) {
sessionsById.put(new ByteArray(session.getId()), session);
}
}
|
private void | indexById(javax.net.ssl.SSLSession session)Adds the given session to the ID-based index if the index has already
been initialized.
if (sessionsById != null) {
sessionsById.put(new ByteArray(session.getId()), session);
}
|
void | putSession(javax.net.ssl.SSLSession session)
HostAndPort key = new HostAndPort(session.getPeerHost(),
session.getPeerPort());
synchronized (sessions) {
sessions.put(key, session);
indexById(session);
}
// TODO: This in a background thread.
if (persistentCache != null) {
byte[] data = toBytes(session);
if (data != null) {
persistentCache.putSessionData(session, data);
}
}
|
void | removeById(javax.net.ssl.SSLSession session)
if (sessionsById != null) {
sessionsById.remove(new ByteArray(session.getId()));
}
|
java.util.Iterator | sessionIterator()
synchronized (sessions) {
SSLSession[] array = sessions.values().toArray(
new SSLSession[sessions.size()]);
return Arrays.asList(array).iterator();
}
|
public final void | setSessionTimeout(int seconds)
if (seconds < 0) {
throw new IllegalArgumentException("seconds < 0");
}
timeout = seconds;
|
void | trimToSize()
synchronized (sessions) {
int size = sessions.size();
if (size > maximumSize) {
int removals = size - maximumSize;
Iterator<SSLSession> i = sessions.values().iterator();
do {
removeById(i.next());
i.remove();
} while (--removals > 0);
}
}
|