public class

StatFsHelper

extends Object
java.lang.Object
   ↳ com.facebook.common.statfs.StatFsHelper

Class Overview

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.

Summary

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

Constants

public static final long DEFAULT_DISK_OLIVE_LEVEL_IN_BYTES

Constant Value: 1048576000 (0x000000003e800000)

public static final long DEFAULT_DISK_RED_LEVEL_IN_BYTES

Constant Value: 104857600 (0x0000000006400000)

public static final int DEFAULT_DISK_RED_LEVEL_IN_MB

Constant Value: 100 (0x00000064)

public static final long DEFAULT_DISK_YELLOW_LEVEL_IN_BYTES

Constant Value: 419430400 (0x0000000019000000)

public static final int DEFAULT_DISK_YELLOW_LEVEL_IN_MB

Constant Value: 400 (0x00000190)

Protected Constructors

protected StatFsHelper ()

Constructor.

Initialization is delayed until first use, so we must call #ensureInitialized() when implementing member methods.

Public Methods

public long getAvailableStorageSpace (StatFsHelper.StorageType storageType)

Gets the information about the available storage space either internal or external depends on the give input

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, 0 if no information is available

public 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

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, -1 if no information is available

public static synchronized StatFsHelper getInstance ()

public long getTotalStorageSpace (StatFsHelper.StorageType storageType)

Gets the information about the total storage space, either internal or external depends on the given input

Parameters
storageType Internal or external storage type
Returns
  • available space in bytes, -1 if no information is available

public boolean isHighSpaceCondition ()

public boolean isLowSpaceCondition ()

public boolean isVeryLowSpaceCondition ()

public void resetStats ()

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.

public boolean testLowDiskSpace (StatFsHelper.StorageType storageType, long freeSpaceThreshold)

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.

Parameters
storageType StorageType (internal or external) to test
freeSpaceThreshold compare the available free space to this size
Returns
  • whether free space is lower than the input freeSpaceThreshold, returns true if disk information is not available

Protected Methods

protected static StatFs createStatFs (String path)