java.lang.Object | |
↳ | com.facebook.common.statfs.StatFsHelper |
Helper class that periodically checks the amount of free space available.
To keep the overhead low, it caches the free space information, and only updates that info after two minutes.
It is a singleton, and is thread-safe.
Initialization is delayed until first use, so the first call to any method may incur some additional cost.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
enum | StatFsHelper.StorageType |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | DEFAULT_DISK_OLIVE_LEVEL_IN_BYTES | ||||||||||
long | DEFAULT_DISK_RED_LEVEL_IN_BYTES | ||||||||||
int | DEFAULT_DISK_RED_LEVEL_IN_MB | ||||||||||
long | DEFAULT_DISK_YELLOW_LEVEL_IN_BYTES | ||||||||||
int | DEFAULT_DISK_YELLOW_LEVEL_IN_MB |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
StatFsHelper()
Constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long |
getAvailableStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the available storage space either internal or external depends on
the give input
| ||||||||||
long |
getFreeStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the free storage space, including reserved blocks, either internal
or external depends on the given input
| ||||||||||
synchronized static StatFsHelper | getInstance() | ||||||||||
long |
getTotalStorageSpace(StatFsHelper.StorageType storageType)
Gets the information about the total storage space, either internal or external depends on the
given input
| ||||||||||
boolean | isHighSpaceCondition() | ||||||||||
boolean | isLowSpaceCondition() | ||||||||||
boolean | isVeryLowSpaceCondition() | ||||||||||
void |
resetStats()
Thread-safe call to reset the disk stats.
| ||||||||||
boolean |
testLowDiskSpace(StatFsHelper.StorageType storageType, long freeSpaceThreshold)
Check if available space in the filesystem is greater than the given threshold.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static StatFs | createStatFs(String path) |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Constructor.
Initialization is delayed until first use, so we must call #ensureInitialized() when implementing member methods.
Gets the information about the available storage space either internal or external depends on the give input
storageType | Internal or external storage type |
---|
Gets the information about the free storage space, including reserved blocks, either internal or external depends on the given input
storageType | Internal or external storage type |
---|
Gets the information about the total storage space, either internal or external depends on the given input
storageType | Internal or external storage type |
---|
Thread-safe call to reset the disk stats. If we know that the free space has changed recently (for example, if we have deleted files), use this method to reset the internal state and start tracking disk stats afresh, resetting the internal timer for updating stats.
Check if available space in the filesystem is greater than the given threshold. Note that the free space stats are cached and updated in intervals of RESTAT_INTERVAL_MS. If the amount of free space has crossed over the threshold since the last update, it will return incorrect results till the space stats are updated again.
storageType | StorageType (internal or external) to test |
---|---|
freeSpaceThreshold | compare the available free space to this size |