Top Description Inners Fields Constructors Methods
org.conscrypt

public final Class FileClientSessionCache

extends Object
Class Inheritance
Annotations
@Internal
Imports
java.io.DataInputStream, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, java.util.Arrays, .HashMap, .Iterator, .LinkedHashMap, .Map, .Set, .TreeSet, java.util.logging.Level, .Logger, javax.net.ssl.SSLSession, org.conscrypt.io.IoUtils

File-based cache implementation. Only one process should access the underlying directory at a time.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
FileClientSessionCache.CacheFile

A file containing a piece of cached data.

pack-priv static class
FileClientSessionCache.Impl

This cache creates one file per SSL session using "host.port" for the file name.

Field Summary

Modifier and TypeField and Description
pack-priv static final Map<File, FileClientSessionCache.Impl>
caches

Maps directories to the cache instances that are backed by those directories.

private static final Logger
public static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static synchronized void
reset()

For testing.

public static synchronized SSLClientSessionCache

Returns:

a cache backed by the given directory
usingDirectory
(File
to store files in
directory
)

Returns a cache backed by the given directory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachesback to summary
pack-priv static final Map<File, FileClientSessionCache.Impl> caches

Maps directories to the cache instances that are backed by those directories. We synchronize access using the cache instance, so it's important that everyone shares the same instance.

loggerback to summary
private static final Logger logger
MAX_SIZEback to summary
public static final int MAX_SIZE

Constructor Detail

FileClientSessionCacheback to summary
private FileClientSessionCache()

Method Detail

resetback to summary
pack-priv static synchronized void reset()

For testing.

usingDirectoryback to summary
public static synchronized SSLClientSessionCache usingDirectory(File directory) throws IOException

Returns a cache backed by the given directory. Creates the directory (including parent directories) if necessary. This cache should have exclusive access to the given directory.

Parameters
directory:File

to store files in

Returns:SSLClientSessionCache

a cache backed by the given directory

Exceptions
IOException:
if the file exists and is not a directory or if creating the directories fails
org.conscrypt back to summary

pack-priv Class FileClientSessionCache.CacheFile

extends File
Class Inheritance
Annotations
@SuppressWarnings:serial

A file containing a piece of cached data.

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv final String
Inherited from java.io.File:
pathSeparatorpathSeparatorCharseparatorseparatorChar

Constructor Summary

AccessConstructor and Description
pack-priv
CacheFile(File dir, String name)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(File
The abstract pathname to be compared to this abstract pathname
another
)

Overrides java.io.File.compareTo.

Implements java.lang.Comparable.compareTo.

Compares two abstract pathnames lexicographically.
public long
lastModified()

Overrides java.io.File.lastModified.

Returns the time that the file denoted by this abstract pathname was last modified.
Inherited from java.io.File:
canExecutecanReadcanWritecreateNewFilecreateTempFilecreateTempFiledeletedeleteOnExitequalsexistsgetAbsoluteFilegetAbsolutePathgetCanonicalFilegetCanonicalPathgetFreeSpacegetNamegetParentgetParentFilegetPathgetTotalSpacegetUsableSpacehashCodeisAbsoluteisDirectoryisFileisHiddenlengthlistlistlistFileslistFileslistFileslistRootsmkdirmkdirsrenameTosetExecutablesetExecutablesetLastModifiedsetReadablesetReadablesetReadOnlysetWritablesetWritabletoPathtoStringtoURItoURL

Field Detail

lastModifiedback to summary
pack-priv long lastModified
nameback to summary
pack-priv final String name

Constructor Detail

CacheFileback to summary
pack-priv CacheFile(File dir, String name)

Method Detail

compareToback to summary
public int compareTo(File another)

Overrides java.io.File.compareTo.

Implements java.lang.Comparable.compareTo.

Doc from java.io.File.compareTo.

Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.

Parameters
another:File

The abstract pathname to be compared to this abstract pathname

Returns:int

Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument

Annotations
@Override
lastModifiedback to summary
public long lastModified()

Overrides java.io.File.lastModified.

Doc from java.io.File.lastModified.

Returns the time that the file denoted by this abstract pathname was last modified.

Returns:long

A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs. The value may be negative indicating the number of milliseconds before the epoch

Annotations
@Override
org.conscrypt back to summary

pack-priv Class FileClientSessionCache.Impl

extends Object
implements SSLClientSessionCache
Class Inheritance
All Implemented Interfaces
org.conscrypt.SSLClientSessionCache

This cache creates one file per SSL session using "host.port" for the file name. Files are created or replaced when session data is put in the cache (see putSessionData). Files are read on cache hits, but not on cache misses.

When the number of session files exceeds MAX_SIZE, we delete the least-recently-used file. We don't current persist the last access time, so the ordering actually ends up being least-recently-modified in some cases and even just "not accessed in this process" if the filesystem doesn't track last modified times.

Field Summary

Modifier and TypeField and Description
pack-priv Map<String, File>
accessOrder

Map of name -> File.

pack-priv final File
directory

Directory to store session files in.

pack-priv String[]
initialFiles

The initial set of files.

pack-priv int
size

The number of files on disk.

Constructor Summary

AccessConstructor and Description
pack-priv
Impl(File directory)

Constructs a new cache backed by the given directory.

Method Summary

Modifier and TypeMethod and Description
private void
delete(File file)

private static String
fileName(String host, int port)

Gets the file name for the given host and port.

public synchronized byte[]
getSessionData(String host, int port)

Implements org.conscrypt.SSLClientSessionCache.getSessionData.

Gets data from a pre-existing session for a given server host and port.
private void
indexFiles()

Lazily updates accessOrder to know about all files as opposed to just the files accessed since this process started.

pack-priv static void
pack-priv static void
private void
makeRoom()

Deletes old files if necessary.

private static Map<String, File>
newAccessOrder()

Creates a new access-ordered linked hash map.

public synchronized void
putSessionData(SSLSession
to cache data for
session
,
byte[]
to cache
sessionData
)

Implements org.conscrypt.SSLClientSessionCache.putSessionData.

Stores session data for the given session.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessOrderback to summary
pack-priv Map<String, File> accessOrder

Map of name -> File. Keeps track of the order files were accessed in.

directoryback to summary
pack-priv final File directory

Directory to store session files in.

initialFilesback to summary
pack-priv String[] initialFiles

The initial set of files. We use this to defer adding information about all files to accessOrder until necessary.

sizeback to summary
pack-priv int size

The number of files on disk.

Constructor Detail

Implback to summary
pack-priv Impl(File directory) throws IOException

Constructs a new cache backed by the given directory.

Method Detail

deleteback to summary
private void delete(File file)
Annotations
@SuppressWarnings:ThrowableInstanceNeverThrown
fileNameback to summary
private static String fileName(String host, int port)

Gets the file name for the given host and port.

getSessionDataback to summary
public synchronized byte[] getSessionData(String host, int port)

Implements org.conscrypt.SSLClientSessionCache.getSessionData.

Doc from org.conscrypt.SSLClientSessionCache.getSessionData.

Gets data from a pre-existing session for a given server host and port.

Parameters
host:String

from javax.net.ssl.SSLSession#getPeerHost()

port:int

from javax.net.ssl.SSLSession#getPeerPort()

Returns:byte[]

the session data or null if none is cached

Annotations
@Override
indexFilesback to summary
private void indexFiles()

Lazily updates accessOrder to know about all files as opposed to just the files accessed since this process started.

logReadErrorback to summary
pack-priv static void logReadError(String host, File file, Throwable t)
logWriteErrorback to summary
pack-priv static void logWriteError(String host, File file, Throwable t)
makeRoomback to summary
private void makeRoom()

Deletes old files if necessary.

newAccessOrderback to summary
private static Map<String, File> newAccessOrder()

Creates a new access-ordered linked hash map.

putSessionDataback to summary
public synchronized void putSessionData(SSLSession session, byte[] sessionData)

Implements org.conscrypt.SSLClientSessionCache.putSessionData.

Doc from org.conscrypt.SSLClientSessionCache.putSessionData.

Stores session data for the given session.

Parameters
session:SSLSession

to cache data for

sessionData:byte[]

to cache

Annotations
@Override