ModuleRootResolver

abstract class ModuleRootResolver(val name: String, val uri: URI, val fileManager: FileManager)

ModuleRootResolver declares an interface for accessing Avail ModuleRoots given a URI. It is responsible for asynchronously retrieving, creating, deleting, and saving files and packages where the ModuleRoot is stored.

It is responsible for producing ResolverReferences, the object linking a resource in a module root to its actual file at the URI location of the module root.

All file actions are conducted via the ModuleRootResolver.fileManager. Given the files may originate anywhere from the local file system to a remote database accessed via network API, a REST-ful webserver, etc., all file requests must be handled asynchronously.

A ModuleRootResolver establishes access to a ModuleRoot based upon the URI.scheme given the appropriate ModuleRootResolver that supports the scheme. A ModuleRootResolver is created by a corresponding ModuleRootResolverFactory. For each ModuleRootResolver type implemented a ModuleRootResolverFactory must be implemented to enable resolver creation. The ModuleRootResolverFactory must be registered in the ModuleRootResolverRegistry. A ModuleRootResolver cannot be created if the factory has not been registered. Only one registered ModuleRootResolverFactory is allowed per URI scheme.

Author

Richard Arriaga

Inheritors

Constructors

Link copied to clipboard
constructor(name: String, uri: URI, fileManager: FileManager)

Construct a new ModuleRootResolver for some root.

Types

Link copied to clipboard

A WatchEventType indicates the types of events that can occur to resources at the represented ModuleRoot source location.

Properties

Link copied to clipboard

The qualified names of all the modules known by this resolver.

Link copied to clipboard
abstract val canSave: Boolean

Answer whether data can be written to modules under this resolver. Note that this may be further restricted by choosing to use the root as a read-only source. See AvailWorkbench.getProjectRoot.

Link copied to clipboard

The FileManager used for pooling I/O requests for this root.

Link copied to clipboard
Link copied to clipboard

The name of this root.

Link copied to clipboard
val uri: URI

The URI that identifies the location of the ModuleRoot.

Link copied to clipboard

The Map from a UUID that represents an interested party to a lambda that accepts a WatchEventType that describes the event that occurred at the source location and a ResolverReference that identifies to what the event occurred to.

Functions

Link copied to clipboard
open fun close()

Close this ModuleRootResolver. Should be called at shutdown to ensure proper clean up of any open resources.

Link copied to clipboard
abstract fun createDirectory(qualifiedName: String, completion: () -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Create a directory.

Link copied to clipboard
abstract fun createFile(qualifiedName: String, mimeType: String, completion: () -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Create a file.

Link copied to clipboard
abstract fun createPackage(qualifiedName: String, completion: () -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Create a package and its representative Avail module.

Link copied to clipboard
abstract fun deleteResource(qualifiedName: String, completion: () -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Delete the ResourceType linked to the qualified name. If the ResourceType is a ResourceType.PACKAGE or a ResourceType.DIRECTORY, all of its children should be deleted as well. All deleted references should be removed from the reference tree.

Link copied to clipboard
open fun executeTask(task: () -> Unit)

Asynchronously execute the provided task.

Link copied to clipboard

Answer a AbstractFileWrapper for the targeted file.

Link copied to clipboard
open fun find(qualifiedName: ModuleName, initialCanonicalName: ModuleName, moduleNameResolver: ModuleNameResolver): ModuleNameResolver.ModuleNameResolutionResult?

Answer a ModuleNameResolver.ModuleNameResolutionResult when attempting to locate a module in this ModuleRootResolver.

Link copied to clipboard
fun fullResourceURI(qualifiedName: String): URI

Answer the URI for a resource in the source moduleRoot given a qualified name. There is no guarantee the target exists.

Link copied to clipboard
fun getQualifiedName(targetURI: String): String

Answer a qualified name for the given URI that points to a file in the moduleRoot.

Link copied to clipboard
open fun getResolverReference(qualifiedName: String): ResolverReference?

Answer the ResolverReference for the given qualified file name for a a file in moduleRoot.

Link copied to clipboard
open fun provideModuleRootTree(successHandler: (ResolverReference) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Provide the non-null ResolverReference that represents the moduleRoot. There is no guarantee made by this interface as to how this should be run. It can be all executed on the calling thread or it can be executed on a separate thread.

Link copied to clipboard
open fun provideResolverReference(qualifiedName: String, withReference: (ResolverReference) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Provide the ResolverReference for the given qualified file name for a file in moduleRoot.

Link copied to clipboard
abstract fun readFile(bypassFileManager: Boolean, reference: ResolverReference, withContents: (ByteArray, UUID?) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Retrieve the resource and provide it with a request to obtain the raw file bytes.

Link copied to clipboard
fun referencesMatchingAbbreviation(abbreviation: String, ignoreCase: Boolean = false): List<ResolverReference>

Answer all the ResolverReferences known by this ModuleRootResolver that have a qualified name that matches the supplied abbreviation.

Link copied to clipboard
abstract fun refreshResolverMetaData(reference: ResolverReference, successHandler: (Long) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Specifically refresh the ResolverReference mutable state:

Link copied to clipboard
abstract fun refreshResolverReferenceDigest(reference: ResolverReference, successHandler: (ByteArray, Long) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Specifically refresh the ResolverReference.digest in the Repository.ModuleArchive for the most recent ResolverReference.lastModified timestamp. This also refreshes the metrics (mutable state) of the provided ResolverReference. It should refresh:

Link copied to clipboard
abstract fun resolve(successHandler: (ResolverReference) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Connect to the source of the moduleRoot and populate this resolver with all the ResolverReferences from the module root. This is not required nor expected to be executed in the calling thread.

Link copied to clipboard
Link copied to clipboard
abstract fun rootManifest(forceRefresh: Boolean, withList: (List<ResolverReference>) -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Provide the full list of all ResolverReferences in this ModuleRootResolver.

Link copied to clipboard
abstract fun saveFile(reference: ResolverReference, fileContents: ByteArray, successHandler: () -> Unit, failureHandler: (ErrorCode, Throwable?) -> Unit)

Save the file to where it is stored.

Link copied to clipboard

Subscribe to receive notifications of WatchEventTypes occurring to this ModuleRoot.

Link copied to clipboard

Remove a watch subscription.