Package org.eclipse.jgit.util
Class FS.FileStoreAttributes
- java.lang.Object
-
- org.eclipse.jgit.util.FS.FileStoreAttributes
-
- Enclosing class:
- FS
public static final class FS.FileStoreAttributes extends java.lang.ObjectAttributes of FileStores on this system- Since:
- 5.1.9
-
-
Field Summary
Fields Modifier and Type Field Description private static SimpleLruCache<java.nio.file.Path,FS.FileStoreAttributes>attrCacheByPathprivate static java.util.Map<java.nio.file.FileStore,FS.FileStoreAttributes>attributeCacheprivate static java.util.concurrent.atomic.AtomicBooleanbackgroundstatic FS.FileStoreAttributesFALLBACK_FILESTORE_ATTRIBUTESFallback FileStore attributes used when we can't measure the filesystem timestamp resolution.private static java.time.DurationFALLBACK_MIN_RACY_INTERVALstatic java.time.DurationFALLBACK_TIMESTAMP_RESOLUTIONFallback filesystem timestamp resolution.private java.time.DurationfsTimestampResolutionprivate static java.util.concurrent.ExecutorFUTURE_RUNNERDon't use the default thread factory of the ForkJoinPool for the CompletableFuture; it runs without any privileges, which causes trouble if a SecurityManager is present.private static java.lang.StringJAVA_VERSION_PREFIXprivate static java.util.Map<java.nio.file.FileStore,java.util.concurrent.locks.Lock>locksprivate java.time.DurationminimalRacyIntervalprivate static longMINIMUM_RESOLUTION_NANOSMinimum file system timestamp resolution granularity to check, in nanoseconds.private static longONE_MICROSECONDprivate static longONE_MILLISECONDprivate static longONE_SECONDprivate static java.util.concurrent.ExecutorSAVE_RUNNERUse a separate executor with at most one thread to synchronize writing to the config.private static java.util.concurrent.atomic.AtomicIntegerthreadNumberprivate static java.time.DurationUNDEFINED_DURATIONMarker to detect undefined values when reading from the config file.
-
Constructor Summary
Constructors Constructor Description FileStoreAttributes(java.time.Duration fsTimestampResolution)Construct a FileStoreAttributeCache entry for the given filesystem timestamp resolution
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidconfigureAttributesPathCache(int maxSize, float purgeFactor)Configures size and purge factor of the path-based cache for file system attributes.private static voiddeleteProbe(java.nio.file.Path probe)static FS.FileStoreAttributesget(java.nio.file.Path path)Get the FileStoreAttributes for the given FileStoreprivate static java.lang.StringgetConfigKey(java.nio.file.FileStore s)private static FS.FileStoreAttributesgetFileStoreAttributes(java.nio.file.Path dir)private static java.time.DurationgetFsResolution(java.nio.file.FileStore s, java.nio.file.Path dir, java.nio.file.Path probe)java.time.DurationgetFsTimestampResolution()java.time.DurationgetMinimalRacyInterval()private static java.util.concurrent.TimeUnitgetUnit(long nanos)private static java.time.DurationmeasureClockResolution()private static java.util.Optional<java.time.Duration>measureFsTimestampResolution(java.nio.file.FileStore s, java.nio.file.Path dir)private static java.time.DurationmeasureMinimalRacyInterval(java.nio.file.Path dir)private static java.lang.Stringread(java.nio.file.Path p)private static java.util.Optional<FS.FileStoreAttributes>readFromConfig(java.nio.file.FileStore s)private static voidsaveToConfig(java.nio.file.FileStore s, FS.FileStoreAttributes c)static voidsetBackground(boolean async)Whether FileStore attributes should be determined asynchronouslyjava.lang.StringtoString()private static voidwrite(java.nio.file.Path p, java.lang.String body)
-
-
-
Field Detail
-
UNDEFINED_DURATION
private static final java.time.Duration UNDEFINED_DURATION
Marker to detect undefined values when reading from the config file.
-
FALLBACK_TIMESTAMP_RESOLUTION
public static final java.time.Duration FALLBACK_TIMESTAMP_RESOLUTION
Fallback filesystem timestamp resolution. The worst case timestamp resolution on FAT filesystems is 2 seconds.Must be at least 1 second.
-
FALLBACK_FILESTORE_ATTRIBUTES
public static final FS.FileStoreAttributes FALLBACK_FILESTORE_ATTRIBUTES
Fallback FileStore attributes used when we can't measure the filesystem timestamp resolution. The last modified time granularity of FAT filesystems is 2 seconds.
-
ONE_MICROSECOND
private static final long ONE_MICROSECOND
-
ONE_MILLISECOND
private static final long ONE_MILLISECOND
-
ONE_SECOND
private static final long ONE_SECOND
-
MINIMUM_RESOLUTION_NANOS
private static final long MINIMUM_RESOLUTION_NANOS
Minimum file system timestamp resolution granularity to check, in nanoseconds. Should be a positive power of ten smaller thanONE_SECOND. Must be strictly greater than zero, i.e., minimum value is 1 nanosecond.Currently set to 1 microsecond, but could also be lower still.
-
JAVA_VERSION_PREFIX
private static final java.lang.String JAVA_VERSION_PREFIX
-
FALLBACK_MIN_RACY_INTERVAL
private static final java.time.Duration FALLBACK_MIN_RACY_INTERVAL
-
attributeCache
private static final java.util.Map<java.nio.file.FileStore,FS.FileStoreAttributes> attributeCache
-
attrCacheByPath
private static final SimpleLruCache<java.nio.file.Path,FS.FileStoreAttributes> attrCacheByPath
-
background
private static final java.util.concurrent.atomic.AtomicBoolean background
-
locks
private static final java.util.Map<java.nio.file.FileStore,java.util.concurrent.locks.Lock> locks
-
threadNumber
private static final java.util.concurrent.atomic.AtomicInteger threadNumber
-
FUTURE_RUNNER
private static final java.util.concurrent.Executor FUTURE_RUNNER
Don't use the default thread factory of the ForkJoinPool for the CompletableFuture; it runs without any privileges, which causes trouble if a SecurityManager is present.Instead use normal daemon threads. They'll belong to the SecurityManager's thread group, or use the one of the calling thread, as appropriate.
- See Also:
Executors.newCachedThreadPool()
-
SAVE_RUNNER
private static final java.util.concurrent.Executor SAVE_RUNNER
Use a separate executor with at most one thread to synchronize writing to the config. We write asynchronously since the config itself might be on a different file system, which might otherwise lead to locking problems.Writing the config must not use a daemon thread, otherwise we may leave an inconsistent state on disk when the JVM shuts down. Use a small keep-alive time to avoid delays on shut-down.
-
fsTimestampResolution
@NonNull private final java.time.Duration fsTimestampResolution
-
minimalRacyInterval
private java.time.Duration minimalRacyInterval
-
-
Constructor Detail
-
FileStoreAttributes
public FileStoreAttributes(@NonNull java.time.Duration fsTimestampResolution)
Construct a FileStoreAttributeCache entry for the given filesystem timestamp resolution- Parameters:
fsTimestampResolution-
-
-
Method Detail
-
setBackground
public static void setBackground(boolean async)
Whether FileStore attributes should be determined asynchronously- Parameters:
async- whether FileStore attributes should be determined asynchronously. If false access to cached attributes may block for some seconds for the first call per FileStore- Since:
- 5.6.2
-
configureAttributesPathCache
public static void configureAttributesPathCache(int maxSize, float purgeFactor)Configures size and purge factor of the path-based cache for file system attributes. Caching of file system attributes avoids recurring lookup of @{code FileStore} of files which may be expensive on some platforms.- Parameters:
maxSize- maximum size of the cache, default is 100purgeFactor- when the size of the map reaches maxSize the oldest entries will be purged to free up some space for new entries,purgeFactoris the fraction ofmaxSizeto purge when this happens- Since:
- 5.1.9
-
get
public static FS.FileStoreAttributes get(java.nio.file.Path path)
Get the FileStoreAttributes for the given FileStore- Parameters:
path- file residing in the FileStore to get attributes for- Returns:
- FileStoreAttributes for the given path.
-
getFileStoreAttributes
private static FS.FileStoreAttributes getFileStoreAttributes(java.nio.file.Path dir)
-
measureMinimalRacyInterval
private static java.time.Duration measureMinimalRacyInterval(java.nio.file.Path dir)
-
write
private static void write(java.nio.file.Path p, java.lang.String body) throws java.io.IOException- Throws:
java.io.IOException
-
read
private static java.lang.String read(java.nio.file.Path p) throws java.io.IOException- Throws:
java.io.IOException
-
measureFsTimestampResolution
private static java.util.Optional<java.time.Duration> measureFsTimestampResolution(java.nio.file.FileStore s, java.nio.file.Path dir)
-
getFsResolution
private static java.time.Duration getFsResolution(java.nio.file.FileStore s, java.nio.file.Path dir, java.nio.file.Path probe) throws java.io.IOException- Throws:
java.io.IOException
-
measureClockResolution
private static java.time.Duration measureClockResolution()
-
deleteProbe
private static void deleteProbe(java.nio.file.Path probe)
-
readFromConfig
private static java.util.Optional<FS.FileStoreAttributes> readFromConfig(java.nio.file.FileStore s)
-
saveToConfig
private static void saveToConfig(java.nio.file.FileStore s, FS.FileStoreAttributes c)
-
getConfigKey
private static java.lang.String getConfigKey(java.nio.file.FileStore s)
-
getUnit
private static java.util.concurrent.TimeUnit getUnit(long nanos)
-
getMinimalRacyInterval
public java.time.Duration getMinimalRacyInterval()
- Returns:
- the measured minimal interval after a file has been modified in which we cannot rely on lastModified to detect modifications
-
getFsTimestampResolution
@NonNull public java.time.Duration getFsTimestampResolution()
- Returns:
- the measured filesystem timestamp resolution
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-