Class UnixFSUtils
java.lang.Object
dev.getelements.elements.rt.transact.unix.UnixFSUtils
A collection of useful utility routines when accessing the filesystem.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA result for thecommit(UnixFSHasFilesystemPath, String)operation.static interfaceDefines an operation which may throw an instance ofIOExceptionstatic interfaceDefines an operation which may throw an instance ofIOException -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Patternstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAllocates a directory in the garbage directory.appendExtension(Path path, String extension) Appends the file extension to the supplied path.appendResourceExtension(Path path) Appends theRESOURCE_EXTENSIONextension to the supplied path.Appends theREVERSE_PATH_EXTENSIONextension to the supplied path.appendTaskExtension(Path path) Appends theTASK_EXTENSIONextension to the supplied path.Checks that the suppliedPathis part of the datastore.voidcleanup(UnixFSHasFilesystemPath hasFilesystemPath, String transactionId) Cleans up the object with the transaction ID.voidCleans up any garbage in the garbage directory.voidcleanupGarbage(Path garbageDirectory) Cleans up the garbage in the suppliedPath.commit(UnixFSHasFilesystemPath hasFilesystemPath, String transactionId) Commits the supplied file, provided the transaction ID.<T> TdoOperation(UnixFSUtils.IOOperation<T> action) Performs and operation that may throw an instance ofIOException, and re-throws it wrapped inside of aInternalException.<T,ExceptionT extends InternalException>
TdoOperation(UnixFSUtils.IOOperation<T> action, Function<Throwable, ExceptionT> exceptionTFunction) Performs and operation that may throw an instance ofIOException, and re-throws it wrapped inside of aInternalException.voiddoOperationV(UnixFSUtils.IOOperationV action) Performs an IO Operation which may throw, catching the exception and wrapping it in the type specified in the function.<ExceptionT extends InternalException>
voiddoOperationV(UnixFSUtils.IOOperationV action, Function<Throwable, ExceptionT> exceptionTFunction) Performs an IO Operation which may throw, catching the exception and wrapping it in the type specified in the function.Gets the configured and preferred checksum algorithm.Gets the directory for temporary storge of garbage data.Gets thePathto the lock file.Gets the storage root for node storage.Returns the path separator string associated with the filesystem used by the storage directory.Gets the storage root directory.Gets thePathto the tombstone marker file.getTransactionFilePath(String transactionId) Allocates a journal file.Returns the path to the journal directory.Returns the path to the journal file.voidInitializes the directory contents for all the necessary sub directories.booleanisMatchingExtension(Path path, String extension) Checks if the path matches the supplied extension.booleanisRegularFile(UnixFSHasFilesystemPath hasFilesystemPath) Checks if the supplied FS Path is a regular file and not a tombstone.booleanisRegularFile(Path path) Checks if the suppliedPathis a regular file.booleanisTombstone(Path path) Checks if the suppliedPathis a tombstone.Safely lists the contents of the supplied directory.voidWrites a lock file in the storage root, throwing aFatalExceptionif there is already a lock file.voidmarkTombstone(Path path) Marks the suppliedPathas a tombstone.voidPrune the suppliedPath.resolveNodeStorageRoot(HasNodeId hasNodeId) resolvePathStorageRoot(HasNodeId hasNodeId) resolveResourceStorageRoot(HasNodeId hasNodeId) resolveReversePathStorageRoot(HasNodeId hasNodeId) Resolves the reverse paths storage directory.resolveTaskStorageRoot(HasNodeId hasNodeId) voidRecursively removes the object at the suppliedPath.stripExtension(Path path) Returns aPathwith the extension stripped.voidDeletes the lock file in the storage root, throwing aFatalExceptionif the was a problem unlocking.Safely lists the contents of the supplied directory as well as its children.
-
Field Details
-
UNIXFS_STORAGE_ROOT_DIRECTORY
- See Also:
-
LOCK_FILE_NAME
- See Also:
-
TOMBSTONE_FILE_NAME
- See Also:
-
TRANSACTION_JOURNAL_FILE_NAME
- See Also:
-
TRANSACTION_JOURNAL_DIRECTORY
- See Also:
-
NODE_DIRECTORY
- See Also:
-
GARBAGE_DIRECTORY
- See Also:
-
PATHS_DIRECTORY
- See Also:
-
TASKS_DIRECTORY
- See Also:
-
RESOURCES_DIRECTORY
- See Also:
-
REVERSE_PATHS_DIRECTORY
- See Also:
-
TEMP_NAME_LENGTH_CHARS
public static final int TEMP_NAME_LENGTH_CHARS- See Also:
-
TASK_EXTENSION
- See Also:
-
RESOURCE_EXTENSION
- See Also:
-
REVERSE_PATH_EXTENSION
- See Also:
-
TRANSACTION_EXTENSION
- See Also:
-
EXTENSION_REGEX
-
EXTENSION_PATTERN
-
TEMP_FILE_CHARACTERS
- See Also:
-
-
Constructor Details
-
UnixFSUtils
@Inject public UnixFSUtils(UnixFSChecksumAlgorithm checksumAlgorithm, @Named("dev.getelements.elements.rt.transact.unix.fs.root") Path storageRoot)
-
-
Method Details
-
initialize
public void initialize()Initializes the directory contents for all the necessary sub directories. -
doOperation
Performs and operation that may throw an instance ofIOException, and re-throws it wrapped inside of aInternalException.- Type Parameters:
T- the return type- Parameters:
action- the action to perform- Returns:
- the value returned from the
UnixFSUtils.IOOperation<T>
-
doOperation
public <T,ExceptionT extends InternalException> T doOperation(UnixFSUtils.IOOperation<T> action, Function<Throwable, ExceptionT> exceptionTFunction) throws ExceptionTPerforms and operation that may throw an instance ofIOException, and re-throws it wrapped inside of aInternalException.- Type Parameters:
T- the return type- Parameters:
action- the action to perform- Returns:
- the value returned from the
UnixFSUtils.IOOperation<T> - Throws:
ExceptionT
-
doOperationV
Performs an IO Operation which may throw, catching the exception and wrapping it in the type specified in the function.- Parameters:
action- the action to perfrom
-
doOperationV
public <ExceptionT extends InternalException> void doOperationV(UnixFSUtils.IOOperationV action, Function<Throwable, ExceptionT> exceptionTFunction) Performs an IO Operation which may throw, catching the exception and wrapping it in the type specified in the function.- Type Parameters:
ExceptionT- the specified exception type- Parameters:
action- the action to perfromexceptionTFunction- a supplier to constrcut the exception
-
getChecksumAlgorithm
Gets the configured and preferred checksum algorithm.- Returns:
- the
UnixFSChecksumAlgorithmto use
-
getStorageRoot
Gets the storage root directory.- Returns:
- the storage root
-
getNodeStorageRoot
Gets the storage root for node storage.- Returns:
- the
Path
-
getGarbageDirectory
Gets the directory for temporary storge of garbage data.- Returns:
- the garbage directory
-
getTransactionJournalFilePath
Returns the path to the journal file.- Returns:
- the path to the journal file.
-
getTransactionJournalDirectoryPath
Returns the path to the journal directory.- Returns:
- the path to the journal file.
-
getTombstone
Gets thePathto the tombstone marker file.- Returns:
- the
Pathto the tombstone file.
-
getLockFilePath
Gets thePathto the lock file.- Returns:
- the
Pathto the lock file.
-
getPathSeparator
Returns the path separator string associated with the filesystem used by the storage directory.- Returns:
- the path separator.
-
check
Checks that the suppliedPathis part of the datastore. -
lockStorageRoot
public void lockStorageRoot()Writes a lock file in the storage root, throwing aFatalExceptionif there is already a lock file. This uses theFile.deleteOnExit()facility to attempt to unlock the directoy regardless of exit, however this uses shutdown hooks and is not guaranteed. -
unlockStorageRoot
public void unlockStorageRoot()Deletes the lock file in the storage root, throwing aFatalExceptionif the was a problem unlocking. -
resolveNodeStorageRoot
-
resolvePathStorageRoot
-
resolveTaskStorageRoot
-
resolveResourceStorageRoot
-
resolveReversePathStorageRoot
Resolves the reverse paths storage directory.- Returns:
- the
Pathto the directory.
-
markTombstone
Marks the suppliedPathas a tombstone.- Parameters:
path- the path to mark
-
isRegularFile
Checks if the supplied FS Path is a regular file and not a tombstone.- Parameters:
hasFilesystemPath- if the path is a regular file.- Returns:
- true if regular file
-
isRegularFile
Checks if the suppliedPathis a regular file.- Parameters:
path- the path to check- Returns:
- true if the path is a tombstone, false otherwise
-
isTombstone
Checks if the suppliedPathis a tombstone.- Parameters:
path- the path to check- Returns:
- true if the path is a tombstone, false otherwise
-
rmrf
Recursively removes the object at the suppliedPath.- Parameters:
path- the path.
-
prune
Prune the suppliedPath. This will delete all empty directories and subdirectories of the path provided that they are empty.- Parameters:
path- the path to prune
-
getTransactionFilePath
Allocates a journal file.- Parameters:
transactionId- the transaction ID- Returns:
- the
Pathto the journal file
-
allocateGarbageDirectory
Allocates a directory in the garbage directory.- Returns:
- the
Pathto the file.
-
cleanupGarbage
public void cleanupGarbage()Cleans up any garbage in the garbage directory. -
cleanupGarbage
Cleans up the garbage in the suppliedPath.- Parameters:
garbageDirectory- the garbage to clean up
-
commit
public UnixFSUtils.CommitResult commit(UnixFSHasFilesystemPath hasFilesystemPath, String transactionId) Commits the supplied file, provided the transaction ID.- Parameters:
hasFilesystemPath- a mapping of a type which has a filesystem pathtransactionId- the transaction ID
-
cleanup
Cleans up the object with the transaction ID.- Parameters:
hasFilesystemPath- a mapping of a type which has a filesystem pathtransactionId- the transaction ID
-
appendExtension
Appends the file extension to the supplied path.- Parameters:
path- the base pathextension- the extension to append- Returns:
- the fully-formed path
-
isMatchingExtension
Checks if the path matches the supplied extension.- Parameters:
path- thePathextension- the extension- Returns:
- true if matches, otherwise false
-
stripExtension
Returns aPathwith the extension stripped. The extension must be one of the known extensions in this class, or else this will throw an instance ofIllegalArgumentException.- Parameters:
path- the path- Returns:
- the path, with file extension stripped.
-
appendTaskExtension
Appends theTASK_EXTENSIONextension to the supplied path.- Parameters:
path- the base path- Returns:
- the fully-formed path
-
appendResourceExtension
Appends theRESOURCE_EXTENSIONextension to the supplied path.- Parameters:
path- the base path- Returns:
- the fully-formed path
-
appendReversePathExtension
Appends theREVERSE_PATH_EXTENSIONextension to the supplied path.- Parameters:
path- the base path- Returns:
- the fully-formed path
-
list
Safely lists the contents of the supplied directory. If the list process encounters a missing file, for example if it had been deleted by the garbage collector, then the stream will simply skip that file. This ensures that it will be possible to work only with live fields when iterating the contents of a directory. Internally this uses a spliterator and lazily fetches as needed. Otherwise, this must behave in a manner identical toFiles.list(Path) -
walk
Safely lists the contents of the supplied directory as well as its children. If the walk process encounters a missing file, for example if it had been deleted by the garbage collector, then the stream will simply skip that file. This ensures that it will be possible to work only with live fields when iterating the contents of a directory. Internally this uses a spliterator and lazily fetches as needed. Otherwise this must behave in a manner identical toFiles.walk(Path, FileVisitOption...)
-