Package com.google.common.jimfs
Class HeapDisk
- java.lang.Object
-
- com.google.common.jimfs.HeapDisk
-
final class HeapDisk extends java.lang.ObjectA resizable pseudo-disk acting as a shared space for storing file data. A disk allocates fixed size blocks of bytes to files as needed and may cache blocks that have been freed for reuse. A memory disk has a fixed maximum number of blocks it will allocate at a time (which sets the total "size" of the disk) and a maximum number of unused blocks it will cache for reuse at a time (which sets the minimum amount of space the disk will use once
-
-
Field Summary
Fields Modifier and Type Field Description private intallocatedBlockCountThe current total number of blocks that are currently allocated to files.(package private) RegularFileblockCacheCache of free blocks to be allocated to files.private intblockSizeFixed size of each block for this disk.private intmaxBlockCountMaximum total number of blocks that the disk may contain at any time.private intmaxCachedBlockCountMaximum total number of unused blocks that may be cached for reuse at any time.
-
Constructor Summary
Constructors Constructor Description HeapDisk(int blockSize, int maxBlockCount, int maxCachedBlockCount)Creates a new disk with the givenblockSize,maxBlockCountandmaxCachedBlockCount.HeapDisk(Configuration config)Creates a new disk using settings from the given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallocate(RegularFile file, int count)Allocates the given number of blocks and adds them to the given file.intblockSize()Returns the size of blocks created by this disk.private RegularFilecreateBlockCache(int maxCachedBlockCount)voidfree(RegularFile file)Frees all blocks in the given file.voidfree(RegularFile file, int count)Frees the lastcountblocks from the given file.longgetTotalSpace()Returns the total size of this disk.longgetUnallocatedSpace()Returns the current number of unallocated bytes on this disk.private static inttoBlockCount(long size, int blockSize)Returns the nearest multiple ofblockSizethat is <=size.
-
-
-
Field Detail
-
blockSize
private final int blockSize
Fixed size of each block for this disk.
-
maxBlockCount
private final int maxBlockCount
Maximum total number of blocks that the disk may contain at any time.
-
maxCachedBlockCount
private final int maxCachedBlockCount
Maximum total number of unused blocks that may be cached for reuse at any time.
-
blockCache
final RegularFile blockCache
Cache of free blocks to be allocated to files. While this is stored as a file, it isn't used like a normal file: only the methods for accessing its blocks are used.
-
allocatedBlockCount
private int allocatedBlockCount
The current total number of blocks that are currently allocated to files.
-
-
Constructor Detail
-
HeapDisk
public HeapDisk(Configuration config)
Creates a new disk using settings from the given configuration.
-
HeapDisk
public HeapDisk(int blockSize, int maxBlockCount, int maxCachedBlockCount)Creates a new disk with the givenblockSize,maxBlockCountandmaxCachedBlockCount.
-
-
Method Detail
-
toBlockCount
private static int toBlockCount(long size, int blockSize)Returns the nearest multiple ofblockSizethat is <=size.
-
createBlockCache
private RegularFile createBlockCache(int maxCachedBlockCount)
-
blockSize
public int blockSize()
Returns the size of blocks created by this disk.
-
getTotalSpace
public long getTotalSpace()
Returns the total size of this disk. This is the maximum size of the disk and does not reflect the amount of data currently allocated or cached.
-
getUnallocatedSpace
public long getUnallocatedSpace()
Returns the current number of unallocated bytes on this disk. This is the maximum number of additional bytes that could be allocated and does not reflect the number of bytes currently actually cached in the disk.
-
allocate
public void allocate(RegularFile file, int count) throws java.io.IOException
Allocates the given number of blocks and adds them to the given file.- Throws:
java.io.IOException
-
free
public void free(RegularFile file)
Frees all blocks in the given file.
-
free
public void free(RegularFile file, int count)
Frees the lastcountblocks from the given file.
-
-