Package org.hl7.fhir.utilities.npm
Class FilesystemPackageCacheManager
- java.lang.Object
-
- org.hl7.fhir.utilities.npm.BasePackageCacheManager
-
- org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager
-
- All Implemented Interfaces:
IPackageCacheManager
public class FilesystemPackageCacheManager extends BasePackageCacheManager implements IPackageCacheManager
This is a package cache manager implementation that uses a local disk cacheAPI:
constructor getPackageUrl getPackageId findPackageCache addPackageToCache
- Author:
- Grahame Grieve
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFilesystemPackageCacheManager.BuilderclassFilesystemPackageCacheManager.BuildRecordclassFilesystemPackageCacheManager.BuildRecordSorterstatic interfaceFilesystemPackageCacheManager.CacheLockFunction<T>static interfaceFilesystemPackageCacheManager.IPackageProvider-
Nested classes/interfaces inherited from class org.hl7.fhir.utilities.npm.BasePackageCacheManager
BasePackageCacheManager.InputStreamWithSrc
-
-
Field Summary
Fields Modifier and Type Field Description static StringPACKAGE_REGEXstatic StringPACKAGE_VERSION_REGEXstatic StringPACKAGE_VERSION_REGEX_OPT-
Fields inherited from class org.hl7.fhir.utilities.npm.BasePackageCacheManager
myPackageServers, silent
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NpmPackageaddPackageToCache(String id, String version, InputStream packageTgzInputStream, String sourceDesc)Add an already fetched package to the cacheprotected voidcleanUpCorruptPackages()voidclear()Clear the cacheStringfindCanonicalInLocalCache(String canonicalUrl)protected List<PackageServer>getConfiguredServers()protected List<PackageServer>getDefaultServers()StringgetFolder()StringgetLatestVersion(String id)StringgetLatestVersionFromCache(String id)StringgetPackageId(String canonicalUrl)static FilesystemPackageCacheManager.IPackageProvidergetPackageProvider()StringgetPackageUrl(String packageId)protected booleanisIgnoreDefaultPackageServers()booleanisSuppressErrors()List<String>listPackages()voidloadFromFolder(String packagesFolder)do not use this in minimal memory modeprotected BasePackageCacheManager.InputStreamWithSrcloadFromPackageServer(String id, String version)Try to load a package from all registered package servers, and returnnullif it can not be found at any of them.NpmPackageloadPackage(String id, String version)NpmPackageloadPackageFromCacheOnly(String id, String version)Load the identified package from the cache - if it existsbooleanpackageExists(String id, String ver)booleanpackageInstalled(String id, String version)protected voidprepareCacheFolder()Check if the cache folder exists and is valid.voidremovePackage(String id, String version)Remove a particular package from the cachestatic voidsetPackageProvider(FilesystemPackageCacheManager.IPackageProvider packageProvider)voidsetSuppressErrors(boolean suppressErrors)-
Methods inherited from class org.hl7.fhir.utilities.npm.BasePackageCacheManager
addPackageServer, getPackageServers, loadPackage, loadPackageFromCacheOnly, setClientFactory, setSilent
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hl7.fhir.utilities.npm.IPackageCacheManager
loadPackage
-
-
-
-
Field Detail
-
PACKAGE_REGEX
public static final String PACKAGE_REGEX
- See Also:
- Constant Field Values
-
PACKAGE_VERSION_REGEX
public static final String PACKAGE_VERSION_REGEX
- See Also:
- Constant Field Values
-
PACKAGE_VERSION_REGEX_OPT
public static final String PACKAGE_VERSION_REGEX_OPT
- See Also:
- Constant Field Values
-
-
Method Detail
-
prepareCacheFolder
protected void prepareCacheFolder() throws IOException
Check if the cache folder exists and is valid.If it doesn't exist, create it.
If it does exist and isn't valid, delete it and create a new one.
If it does exist and is valid, just do some cleanup (delete temp download directories, etc.)
- Throws:
IOException- if the cache folder can't be created
-
cleanUpCorruptPackages
protected void cleanUpCorruptPackages() throws IOException
- Throws:
IOException
-
isIgnoreDefaultPackageServers
protected boolean isIgnoreDefaultPackageServers()
-
getDefaultServers
@Nonnull protected List<PackageServer> getDefaultServers()
-
getConfiguredServers
protected List<PackageServer> getConfiguredServers()
-
loadFromPackageServer
protected BasePackageCacheManager.InputStreamWithSrc loadFromPackageServer(String id, String version)
Description copied from class:BasePackageCacheManagerTry to load a package from all registered package servers, and returnnullif it can not be found at any of them.- Overrides:
loadFromPackageServerin classBasePackageCacheManager
-
getLatestVersion
public String getLatestVersion(String id) throws IOException
- Throws:
IOException
-
getLatestVersionFromCache
public String getLatestVersionFromCache(String id) throws IOException
- Throws:
IOException
-
clear
public void clear() throws IOException
Clear the cache- Throws:
IOException- If the cache cannot be cleared
-
removePackage
public void removePackage(String id, String version) throws IOException
Remove a particular package from the cache- Parameters:
id- The id of the package to removeversion- The literal version of the package to remove. Values such as 'current' and 'dev' are not allowed.- Throws:
IOException- If the package cannot be removed
-
loadPackageFromCacheOnly
public NpmPackage loadPackageFromCacheOnly(String id, @Nullable String version) throws IOException
Load the identified package from the cache - if it exists This is for special purpose only (testing, control over speed of loading). Generally, use the loadPackage method- Specified by:
loadPackageFromCacheOnlyin classBasePackageCacheManager- Parameters:
id- The id of the package to loadversion- The version of the package to load. Values such as 'current' and 'dev' are allowed.- Returns:
- The package, or null if it is not found
- Throws:
IOException- If the package cannot be loaded
-
addPackageToCache
public NpmPackage addPackageToCache(String id, String version, InputStream packageTgzInputStream, String sourceDesc) throws IOException
Add an already fetched package to the cache- Specified by:
addPackageToCachein interfaceIPackageCacheManager- Throws:
IOException
-
getPackageUrl
public String getPackageUrl(String packageId) throws IOException
- Specified by:
getPackageUrlin interfaceIPackageCacheManager- Overrides:
getPackageUrlin classBasePackageCacheManager- Throws:
IOException
-
loadFromFolder
public void loadFromFolder(String packagesFolder) throws IOException
do not use this in minimal memory mode- Parameters:
packagesFolder-- Throws:
IOException
-
loadPackage
public NpmPackage loadPackage(String id, String version) throws FHIRException, IOException
- Specified by:
loadPackagein interfaceIPackageCacheManager- Throws:
FHIRExceptionIOException
-
getPackageId
public String getPackageId(String canonicalUrl) throws IOException
- Specified by:
getPackageIdin interfaceIPackageCacheManager- Overrides:
getPackageIdin classBasePackageCacheManager- Throws:
IOException
-
findCanonicalInLocalCache
public String findCanonicalInLocalCache(String canonicalUrl)
-
listPackages
public List<String> listPackages()
-
packageExists
public boolean packageExists(String id, String ver) throws IOException
- Throws:
IOException
-
packageInstalled
public boolean packageInstalled(String id, String version)
-
isSuppressErrors
public boolean isSuppressErrors()
-
setSuppressErrors
public void setSuppressErrors(boolean suppressErrors)
-
getPackageProvider
public static FilesystemPackageCacheManager.IPackageProvider getPackageProvider()
-
setPackageProvider
public static void setPackageProvider(FilesystemPackageCacheManager.IPackageProvider packageProvider)
-
-