FileDocCategorySizeDatePackage
ServerSessionContext.javaAPI DocAndroid 1.5 API3807Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

ServerSessionContext

public class ServerSessionContext extends AbstractSessionContext
Caches server sessions. Indexes by session ID. Users typically look up sessions using the ID provided by an SSL client.

Fields Summary
private final Map
sessions
private final SSLServerSessionCache
persistentCache
Constructors Summary
public ServerSessionContext(SSLParameters parameters, SSLServerSessionCache persistentCache)


      
              
        super(parameters, 100, 0);
        this.persistentCache = persistentCache;
    
Methods Summary
public javax.net.ssl.SSLSessiongetSession(byte[] sessionId)

        ByteArray key = new ByteArray(sessionId);
        synchronized (sessions) {
            SSLSession session = sessions.get(key);
            if (session != null) {
                return session;
            }
        }

        // Check persistent cache.
        if (persistentCache != null) {
            byte[] data = persistentCache.getSessionData(sessionId);
            if (data != null) {
                SSLSession session = toSession(data, null, -1);
                if (session != null) {
                    synchronized (sessions) {
                        sessions.put(key, session);
                    }
                    return session;
                }
            }
        }

        return null;
    
voidputSession(javax.net.ssl.SSLSession session)

        ByteArray key = new ByteArray(session.getId());
        synchronized (sessions) {
            sessions.put(key, session);
        }

        // TODO: In background thread.
        if (persistentCache != null) {
            byte[] data = toBytes(session);
            if (data != null) {
                persistentCache.putSessionData(session, data);
            }
        }
    
java.util.IteratorsessionIterator()

        synchronized (sessions) {
            SSLSession[] array = sessions.values().toArray(
                    new SSLSession[sessions.size()]);
            return Arrays.asList(array).iterator();
        }
    
public voidsetSessionTimeout(int seconds)

        if (seconds < 0) {
            throw new IllegalArgumentException("seconds < 0");
        }
        timeout = seconds;
    
voidtrimToSize()

        synchronized (sessions) {
            int size = sessions.size();
            if (size > maximumSize) {
                int removals = size - maximumSize;
                Iterator<SSLSession> i = sessions.values().iterator();
                do {
                    i.next();
                    i.remove();
                } while (--removals > 0);
            }
        }