Class WorkspaceImpl
java.lang.Object
org.opencastproject.workspace.impl.WorkspaceImpl
- All Implemented Interfaces:
StorageUsage,Workspace
Implements a simple cache for remote URIs. Delegates methods to
WorkingFileRepository wherever possible.
Note that if you are running the workspace on the same machine as the singleton working file repository, you can save a lot of space if you configure both root directories onto the same volume (that is, if your file system supports hard links). TODO Implement cache invalidation using the caching headers, if provided, from the remote server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration key for the storage directorystatic final StringConfiguration key for garbage collection max age.static final StringConfiguration key for garbage collection period.static final StringConfiguration key for the workspace root directory -
Constructor Summary
ConstructorsConstructorDescriptionWorkspaceImpl(String rootDirectory, boolean waitForResource) Creates a workspace implementation which is located at the given root directory. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) OSGi service activation callback.voidcleanup(int maxAgeInSeconds) Cleans up files not belonging to a mediapackage or a collection.voidClean up all elements of one media package from the local workspace, not touching the working file repository.voidClean up elements of one media package from the local workspace, not touching the working file repository.voidCallback from OSGi on service deactivation.voidDelete the file stored at the given media package and element IDs.voidDelete the file stored at the given uri.voiddeleteFromCollection(String collectionId, String fileName) Removes a file from a collectionGets a locally cachedFilefor the given URI.Get a locally cachedFilefor a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.Gets the base URI for files stored using this service.URI[]getCollectionContents(String collectionId) Gets the URIs of the members of this collectiongetCollectionURI(String collectionID, String fileName) Get the URL for a file stored under the given collection.Gets the total space of storage in BytesGet the URL for a file stored under the given media package and element IDs.Gets the available space of storage in Bytes This is free storage that is not reservedGets the used space of storage in Bytesprotected StringReturns the md5 of a fileMoves a file from a collection into a mediapackageput(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) Store the data stream under the given media package and element IDs, specifying a filename.putInCollection(String collectionId, String fileName, InputStream in) Stores the data stream in the given collection, overwriting any data with the same collection id and file name.Get theFilefor the given URI directly from the working file repository.Returns the workspace's root directoryvoidvoidsetSecurityService(SecurityService securityService) voidsetTrustedHttpClient(TrustedHttpClient trustedHttpClient) toSafeName(String fileName) Returns the filename translated into a version that can safely be used as part of a file system path.
-
Field Details
-
WORKSPACE_DIR_KEY
Configuration key for the workspace root directory- See Also:
-
STORAGE_DIR_KEY
Configuration key for the storage directory- See Also:
-
WORKSPACE_CLEANUP_PERIOD_KEY
Configuration key for garbage collection period.- See Also:
-
WORKSPACE_CLEANUP_MAX_AGE_KEY
Configuration key for garbage collection max age.- See Also:
-
-
Constructor Details
-
WorkspaceImpl
public WorkspaceImpl() -
WorkspaceImpl
Creates a workspace implementation which is located at the given root directory.Note that if you are running the workspace on the same machine as the singleton working file repository, you can save a lot of space if you configure both root directories onto the same volume (that is, if your file system supports hard links).
- Parameters:
rootDirectory- the repository root directory
-
-
Method Details
-
activate
public void activate(org.osgi.service.component.ComponentContext cc) OSGi service activation callback.- Parameters:
cc- the OSGi component context
-
deactivate
public void deactivate()Callback from OSGi on service deactivation. -
toSafeName
Returns the filename translated into a version that can safely be used as part of a file system path. The method shortens both the base file name and the extension to a maximum of 255 characters each, and replaces unsafe characters with <doce>_</doce>.- Specified by:
toSafeNamein interfaceWorkspace- Parameters:
fileName- The file name- Returns:
- the safe version
-
get
Description copied from interface:WorkspaceGets a locally cachedFilefor the given URI.- Specified by:
getin interfaceWorkspace- Parameters:
uri-- Returns:
- The locally cached file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
get
Description copied from interface:WorkspaceGet a locally cachedFilefor a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.- Specified by:
getin interfaceWorkspace- Parameters:
uri- URI to the resource to getuniqueFilename- If a unique path should be used- Returns:
- The locally cached file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
read
Description copied from interface:WorkspaceGet theFilefor the given URI directly from the working file repository. If shared storage is not available, then fall back to get(uri).- Specified by:
readin interfaceWorkspace- Parameters:
uri- URI identifying the resource to load- Returns:
- The file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the working file repository fails
-
md5
Returns the md5 of a file- Parameters:
file- the source file- Returns:
- the md5 hash
- Throws:
IOException- if the file cannot be accessedIllegalArgumentException- iffileisnullIllegalStateException- iffiledoes not exist or is not a regular file
-
delete
Description copied from interface:WorkspaceDelete the file stored at the given uri.- Specified by:
deletein interfaceWorkspace- Parameters:
uri- the uri- Throws:
NotFoundException- if there was not file stored under this combination of mediapackage and element IDs.IOException- if deleting the data from the workspace fails
-
delete
public void delete(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException Description copied from interface:WorkspaceDelete the file stored at the given media package and element IDs.- Specified by:
deletein interfaceWorkspace- Parameters:
mediaPackageID-mediaPackageElementID-- Throws:
NotFoundException- if there was not file stored under this combination of mediapackage and element IDs.IOException- if deleting the data from the workspace fails
-
put
public URI put(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) throws IOException Description copied from interface:WorkspaceStore the data stream under the given media package and element IDs, specifying a filename.- Specified by:
putin interfaceWorkspace- Parameters:
mediaPackageID-mediaPackageElementID-fileName-in-- Throws:
IOException- if writing the data to the workspace fails
-
putInCollection
Description copied from interface:WorkspaceStores the data stream in the given collection, overwriting any data with the same collection id and file name.- Specified by:
putInCollectionin interfaceWorkspace- Parameters:
collectionId- The collection to use for storing this datafileName- the filename to use in the collection.in- the inputstream- Returns:
- the URI of the stored data
- Throws:
IOException- if writing the data to the workspace fails
-
getURI
Description copied from interface:WorkspaceGet the URL for a file stored under the given media package and element IDs. MediaPackages may reference elements that are not yet stored in the working file repository, so this method will return a URI even if the file is not yet stored. -
getCollectionURI
Description copied from interface:WorkspaceGet the URL for a file stored under the given collection.- Specified by:
getCollectionURIin interfaceWorkspace- Parameters:
collectionID- the collection idfileName- the file name- Returns:
- the file's uri
-
moveTo
public URI moveTo(URI collectionURI, String toMediaPackage, String toMediaPackageElement, String toFileName) throws NotFoundException, IOException Description copied from interface:WorkspaceMoves a file from a collection into a mediapackage- Specified by:
moveToin interfaceWorkspace- Parameters:
collectionURI- the uri pointing to a workspace collectiontoMediaPackage- The media package ID to move the file intotoMediaPackageElement- the media package element ID of the filetoFileName- the name of the resulting file- Returns:
- the URI pointing to the file's new location
- Throws:
NotFoundException- if the element identified bycollectionURIcannot be foundIOException- if either the original element cannot be read or it cannot be moved to the new location
-
getCollectionContents
Description copied from interface:WorkspaceGets the URIs of the members of this collection- Specified by:
getCollectionContentsin interfaceWorkspace- Parameters:
collectionId- the collection identifier- Returns:
- the URIs for each member of the collection
- Throws:
NotFoundException- if the collection cannot be found
-
deleteFromCollection
public void deleteFromCollection(String collectionId, String fileName) throws NotFoundException, IOException Description copied from interface:WorkspaceRemoves a file from a collection- Specified by:
deleteFromCollectionin interfaceWorkspace- Parameters:
collectionId- the collection identifierfileName- the filename to remove- Throws:
NotFoundException- if there was no file with the provided name stored under this collection.IOException- if deleting the data from the workspace fails
-
getTotalSpace
Description copied from interface:StorageUsageGets the total space of storage in Bytes- Specified by:
getTotalSpacein interfaceStorageUsage- Returns:
- Number of all bytes in storage
-
getUsableSpace
Description copied from interface:StorageUsageGets the available space of storage in Bytes This is free storage that is not reserved- Specified by:
getUsableSpacein interfaceStorageUsage- Returns:
- Number of available bytes in storage
-
getUsedSpace
Description copied from interface:StorageUsageGets the used space of storage in Bytes- Specified by:
getUsedSpacein interfaceStorageUsage- Returns:
- Number of used bytes in storage
-
getBaseUri
Description copied from interface:WorkspaceGets the base URI for files stored using this service.- Specified by:
getBaseUriin interfaceWorkspace- Returns:
- The base URI
-
setRepository
-
setTrustedHttpClient
-
setSecurityService
-
cleanup
public void cleanup(int maxAgeInSeconds) Description copied from interface:WorkspaceCleans up files not belonging to a mediapackage or a collection. If the optional maxAge parameter is set, only files older than the maxAge are deleted. -
cleanup
Description copied from interface:WorkspaceClean up all elements of one media package from the local workspace, not touching the working file repository.- Specified by:
cleanupin interfaceWorkspace- Parameters:
mediaPackageId- Id specifying the media package to remove files for.- Throws:
IOException
-
cleanup
Description copied from interface:WorkspaceClean up elements of one media package from the local workspace, not touching the working file repository.- Specified by:
cleanupin interfaceWorkspace- Parameters:
mediaPackageId- Id specifying the media package to remove files for.filesOnly- Boolean specifying whether only files or also directories (including the root directory) are deleted.- Throws:
IOException
-
rootDirectory
Description copied from interface:WorkspaceReturns the workspace's root directory- Specified by:
rootDirectoryin interfaceWorkspace- Returns:
- Path to the workspace root directory
-