======================================================== ``DirPool``: A Storm pool stored in a directory of files ======================================================== :Author: Benja Fallenstein :Target: DirPool.java :Language: Java THIS IS A MOCK-UP. Ly using reStructuredText hasn't been implemented yet. Javadoc ======= A StormPool storing blocks in individual files in a directory. File names have the form ``b_idstring``, where ``idstring`` is the hexadecimal representation of a block's id. State and constructor ===================== A ``DirPool`` knows the directory it stores blocks in. -- public class DirPool extends AbstractLocalPool: protected File dir; For simplicity, we do not cache anything, including ``Block`` objects. This makes our implementation more robust in the face of concurrent changes to the directory from another process. If we run into performance problems, we may implement caching in a subclass. Our constructor simply takes the ``dir``: /** Create a new DirPool. * @param dir The directory blocks are stored in. * Must already exist. * @throws IllegalArgumentException if the file isn't a directory * or does not exist yet. */ public DirPool(File dir) { this.dir = dir; } Blocks ====== ``DirPool`` blocks are represented by the following class: protected class FileBlock extends AbstractBlock { File file; -- protected FileBlock(BlockId id) throws IOException. -- ... } (``FileBlock`` and not ``DirBlock`` because the block is one file, not one directory. ``DirPool`` and not ``FilePool`` because the pool is one directory, not one file.) Constructed with only the block id, ``FileBlock`` reads all other data it needs from the disk. Since it is a non-static inner class, it can use the ``dir`` variable from ``DirPool``. Convenience functions ===================== In the code below, we will use following two convenience methods: -- protected final File getFile(BlockId id). ``getFile()`` returns the ``File`` object in which we store the block with the given id. Since ``File`` objects are basically just wrappers for a file name, no file of that name has to exist yet. -- protected final Header822 getFileHeader(BlockId id) throws IOException. ``getFileHeader()`` reads the header of a block from the corresponding file. Obviously, this has to be to ``StormPool`` implementation ============================ Out ``get()`` method is trivial. public Block get(BlockId id) throws IOException { return new FileBlock(id); } So is ``delete()``, using the convenience function we've just defined. public void delete(Block b) throws IOException { getFile(b.getId()).delete(); } In ``getIds()``, we go through a directory listing, ignoring all files starting with ``b_``. XXX: The ``b_*`` files we convert to block ids-- meaning that we blow up if one of the ``b_`` file names does not represent a legal block id! public SetCollector getIds() { HashSet ids = new HashSet(); String[] list = dir.list(); for(int i=0; i