File Handle
A FileHandle is an abstraction which wraps an AsynchronousFileChannel with some additional information like filename and buffer alignment. It gets stuffed in a pojo in a property of the atom that serves as Avail's most basic view of a file handle. Sockets use a substantially similar technique.
In addition, the FileHandle weakly tracks which buffers need to be evicted from Avail's file buffer cache.
Author
Mark van Gulik
Parameters
The name of the file.
The alignment by which to access the file.
Whether the file can be read.
Whether the file can be written.
The AsynchronousFileChannel with which to do reading and writing.
Constructors
Construct a new file handle.
Properties
The buffer alignment for the file. Reading is only ever attempted on this file at buffer boundaries. There is a global file buffer cache, which is an LRUCache of buffers across all open files. Each buffer in the cache has a length exactly equal to that file handle's alignment. A file will often have a partial buffer at the end due to its size not being an integral multiple of the alignment. Such a partial buffer is always excluded from the global file buffer cache.
A weak set of BufferKeys pertaining to this file, for which there may be entries in the global. Since the buffer keys are specific to each FileHandle, they are removed from the cache explicitly when the file is closed. This weak set allows the cache removals to happen efficiently.
The underlying AsynchronousFileChannel through which input and/or output takes place.