This object tracks the last modified time of a file. Later during an
invocation of isModified(File) the object will return true if the
file may have been modified and should be re-read from disk.
A snapshot does not "live update" when the underlying filesystem changes.
Callers must poll for updates by periodically invoking
isModified(File).
To work around the "racy git" problem (where a file may be modified multiple times within the granularity of the filesystem modification clock) this class may return true from isModified(File) if the last modification time of the file is less than 3 seconds ago.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | cannotBeRacilyClean
True once |
| private static final DateTimeFormatter | |
| private long | |
| public static final FileSnapshot | DIRTY
A FileSnapshot that is considered to always be modified. |
| private final File | |
| private final Object | fileKey
Object that uniquely identifies the given file, or |
| private boolean | |
| private FS. | fileStoreAttributeCache
measured FileStore attributes |
| private final Instant | lastModified
Last observed modification time of the path. |
| private boolean | |
| private volatile Instant | lastRead
Last wall-clock time the path was read. |
| private static final Logger | |
| public static final FileSnapshot | MISSING_FILE
A FileSnapshot that is clean if the file does not exist. |
| private static final Object | |
| private long | |
| private final long | size
Underlying file-system size in bytes. |
| private boolean | |
| public static final long | UNKNOWN_SIZE
An unknown file size. |
| private static final Instant | |
| private boolean | useConfig
if |
| private boolean |
| Access | Constructor and Description |
|---|---|
| protected | FileSnapshot(File
the path to remember meta data for. The path's current status
information is saved. file)Record a snapshot for a specific file path. |
| protected | FileSnapshot(File
the path to remember meta data for. The path's current status
information is saved. file, boolean if useConfig)true read filesystem time resolution from
configuration file otherwise use fallback resolutionRecord a snapshot for a specific file path. |
| private | FileSnapshot(Instant read, Instant modified, long size, Duration fsTimestampResolution, Object fileKey)
|
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the two snapshots share the same information.the other snapshot. other)Compare two snapshots to see if they cache the same information. |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| private FS. | |
| private long | |
| private static BasicFileAttributes | |
| private static Object | |
| public int | |
| private boolean | |
| public boolean | Returns: true if the path needs to be read again.the path the snapshot describes. path)Check if the path may have been modified since the snapshot was saved. |
| private boolean | |
| private boolean | |
| private boolean | |
| public long | Returns: the delta in nanoseconds between lastModified and lastRead during last racy checkGet the delta in nanoseconds between lastModified and lastRead during last racy check |
| public Instant | |
| public long | Returns: the racyLimitNanos threshold in nanoseconds during last racy checkGet the racyLimitNanos threshold in nanoseconds during last racy check |
| public static FileSnapshot | |
| public static FileSnapshot | |
| public static FileSnapshot | Returns: the snapshot.the path to later remember. The path's current status
information is saved. path)Record a snapshot for a specific file path without using config file to get filesystem timestamp resolution. |
| public void | setClean(FileSnapshot
the other snapshot. other)Update this snapshot when the content hasn't changed. |
| public long | Returns: file size in bytes of last snapshot updateGet file size in bytes of last snapshot update |
| public String | |
| public void | |
| pack-priv boolean | Returns: true if #isModified(File) found the file key changedWhether #isModified(File) found the file key changed |
| pack-priv boolean | Returns: true if #isModified(File) found the file's lastModified
changedWhether #isModified(File) found the file's lastModified changed |
| pack-priv boolean | Returns: true if #isModified(File) detected that lastModified is
racily cleanWhether #isModified(File) detected that lastModified is racily clean |
| pack-priv boolean | Returns: true if #isModified(File) found the file size changedWhether #isModified(File) found the file size changed |
| cannotBeRacilyClean | back to summary |
|---|---|
| private boolean cannotBeRacilyClean True once | |
| dateFmt | back to summary |
|---|---|
| private static final DateTimeFormatter dateFmt | |
| delta | back to summary |
|---|---|
| private long delta | |
| DIRTY | back to summary |
|---|---|
| public static final FileSnapshot DIRTY A FileSnapshot that is considered to always be modified.
This instance is useful for application code that wants to lazily read a
file, but only after | |
| file | back to summary |
|---|---|
| private final File file | |
| fileKey | back to summary |
|---|---|
| private final Object fileKey Object that uniquely identifies the given file, or | |
| fileKeyChanged | back to summary |
|---|---|
| private boolean fileKeyChanged | |
| fileStoreAttributeCache | back to summary |
|---|---|
| private FS. measured FileStore attributes | |
| lastModified | back to summary |
|---|---|
| private final Instant lastModified Last observed modification time of the path. | |
| lastModifiedChanged | back to summary |
|---|---|
| private boolean lastModifiedChanged | |
| lastRead | back to summary |
|---|---|
| private volatile Instant lastRead Last wall-clock time the path was read. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| MISSING_FILE | back to summary |
|---|---|
| public static final FileSnapshot MISSING_FILE A FileSnapshot that is clean if the file does not exist.
This instance is useful if the application wants to consider a missing
file to be clean. | |
| MISSING_FILEKEY | back to summary |
|---|---|
| private static final Object MISSING_FILEKEY | |
| racyThreshold | back to summary |
|---|---|
| private long racyThreshold | |
| size | back to summary |
|---|---|
| private final long size Underlying file-system size in bytes.
When set to | |
| sizeChanged | back to summary |
|---|---|
| private boolean sizeChanged | |
| UNKNOWN_SIZE | back to summary |
|---|---|
| public static final long UNKNOWN_SIZE An unknown file size. This value is used when a comparison needs to happen purely on the lastUpdate. | |
| UNKNOWN_TIME | back to summary |
|---|---|
| private static final Instant UNKNOWN_TIME | |
| useConfig | back to summary |
|---|---|
| private boolean useConfig if | |
| wasRacyClean | back to summary |
|---|---|
| private boolean wasRacyClean | |
| FileSnapshot | back to summary |
|---|---|
| protected FileSnapshot(File file) Record a snapshot for a specific file path. This method should be invoked before the file is accessed.
| |
| FileSnapshot | back to summary |
|---|---|
| protected FileSnapshot(File file, boolean useConfig) Record a snapshot for a specific file path. This method should be invoked before the file is accessed.
| |
| FileSnapshot | back to summary |
|---|---|
| private FileSnapshot(Instant read, Instant modified, long size, Duration fsTimestampResolution, Object fileKey) | |
| equals | back to summary |
|---|---|
| public boolean equals(FileSnapshot other) Compare two snapshots to see if they cache the same information.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| fileStoreAttributeCache | back to summary |
|---|---|
| private FS. | |
| getEffectiveRacyThreshold | back to summary |
|---|---|
| private long getEffectiveRacyThreshold() | |
| getFileAttributes | back to summary |
|---|---|
| private static BasicFileAttributes getFileAttributes(File path) throws NoSuchElementException | |
| getFileKey | back to summary |
|---|---|
| private static Object getFileKey(BasicFileAttributes fileAttributes) | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isFileKeyChanged | back to summary |
|---|---|
| private boolean isFileKeyChanged(Object currFileKey) | |
| isModified | back to summary |
|---|---|
| public boolean isModified(File path) Check if the path may have been modified since the snapshot was saved.
| |
| isModified | back to summary |
|---|---|
| private boolean isModified(Instant currLastModified) | |
| isRacyClean | back to summary |
|---|---|
| private boolean isRacyClean(Instant read) | |
| isSizeChanged | back to summary |
|---|---|
| private boolean isSizeChanged(long currSize) | |
| lastDelta | back to summary |
|---|---|
| public long lastDelta() Get the delta in nanoseconds between lastModified and lastRead during last racy check
| |
| lastModifiedInstant | back to summary |
|---|---|
| public Instant lastModifiedInstant() Get time of last snapshot update
| |
| lastRacyThreshold | back to summary |
|---|---|
| public long lastRacyThreshold() Get the racyLimitNanos threshold in nanoseconds during last racy check
| |
| save | back to summary |
|---|---|
| public static FileSnapshot save(File path) Record a snapshot for a specific file path. This method should be invoked before the file is accessed.
| |
| save | back to summary |
|---|---|
| public static FileSnapshot save(Instant modified) Record a snapshot for a file for which the last modification time is already known. This method should be invoked before the file is accessed. Note that this method cannot rely on measuring file timestamp resolution to avoid racy git issues caused by finite file timestamp resolution since it's unknown in which filesystem the file is located. Hence the worst case fallback for timestamp resolution is used.
| |
| saveNoConfig | back to summary |
|---|---|
| public static FileSnapshot saveNoConfig(File path) Record a snapshot for a specific file path without using config file to get filesystem timestamp resolution. This method should be invoked before the file is accessed. It is used by FileBasedConfig to avoid endless recursion.
| |
| setClean | back to summary |
|---|---|
| public void setClean(FileSnapshot other) Update this snapshot when the content hasn't changed.
If the caller gets true from
if (snapshot.isModified(path)) {
FileSnapshot other = FileSnapshot.save(path);
Content newContent = ...;
if (oldContent.equals(newContent) && snapshot.equals(other))
snapshot.setClean(other);
}
| |
| size | back to summary |
|---|---|
| public long size() Get file size in bytes of last snapshot update
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| waitUntilNotRacy | back to summary |
|---|---|
| public void waitUntilNotRacy() throws InterruptedException Wait until this snapshot's file can't be racy anymore
| |
| wasFileKeyChanged | back to summary |
|---|---|
| pack-priv boolean wasFileKeyChanged() Whether #isModified(File) found the file key changed
| |
| wasLastModifiedChanged | back to summary |
|---|---|
| pack-priv boolean wasLastModifiedChanged() Whether #isModified(File) found the file's lastModified changed
| |
| wasLastModifiedRacilyClean | back to summary |
|---|---|
| pack-priv boolean wasLastModifiedRacilyClean() Whether #isModified(File) detected that lastModified is racily clean
| |
| wasSizeChanged | back to summary |
|---|---|
| pack-priv boolean wasSizeChanged() Whether #isModified(File) found the file size changed
| |