Package com.google.common.jimfs
Class HeapDisk
java.lang.Object
com.google.common.jimfs.HeapDisk
A 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
FieldsModifier and TypeFieldDescriptionprivate int
The current total number of blocks that are currently allocated to files.(package private) final RegularFile
Cache of free blocks to be allocated to files.private final int
Fixed size of each block for this disk.private final int
Maximum total number of blocks that the disk may contain at any time.private final int
Maximum total number of unused blocks that may be cached for reuse at any time. -
Constructor Summary
ConstructorsConstructorDescriptionHeapDisk
(int blockSize, int maxBlockCount, int maxCachedBlockCount) Creates a new disk with the givenblockSize
,maxBlockCount
andmaxCachedBlockCount
.HeapDisk
(Configuration config) Creates a new disk using settings from the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
allocate
(RegularFile file, int count) Allocates the given number of blocks and adds them to the given file.int
Returns the size of blocks created by this disk.private RegularFile
createBlockCache
(int maxCachedBlockCount) void
free
(RegularFile file) Frees all blocks in the given file.void
free
(RegularFile file, int count) Frees the lastcount
blocks from the given file.long
Returns the total size of this disk.long
Returns the current number of unallocated bytes on this disk.private static int
toBlockCount
(long size, int blockSize) Returns the nearest multiple ofblockSize
that is invalid input: '<'=size
.
-
Field Details
-
blockSize
private final int blockSizeFixed size of each block for this disk. -
maxBlockCount
private final int maxBlockCountMaximum total number of blocks that the disk may contain at any time. -
maxCachedBlockCount
private final int maxCachedBlockCountMaximum total number of unused blocks that may be cached for reuse at any time. -
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 allocatedBlockCountThe current total number of blocks that are currently allocated to files.
-
-
Constructor Details
-
HeapDisk
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
,maxBlockCount
andmaxCachedBlockCount
.
-
-
Method Details
-
toBlockCount
private static int toBlockCount(long size, int blockSize) Returns the nearest multiple ofblockSize
that is invalid input: '<'=size
. -
createBlockCache
-
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
Allocates the given number of blocks and adds them to the given file.- Throws:
IOException
-
free
Frees all blocks in the given file. -
free
Frees the lastcount
blocks from the given file.
-