Package gov.usgs.earthquake.distribution
Class FileProductStorage
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.distribution.FileProductStorage
- All Implemented Interfaces:
ProductStorage,Configurable
- Direct Known Subclasses:
ConsolidatedFileProductStorage,DYFILegacyStorage,HashFileProductStorage,URLProductStorage
Store products in the file system.
This implementation of ProductStorage extracts products into directories.
The FileProductStorage implements the Configurable interface and can use the
following configuration parameters:
- directory
- (Optional, default = storage) The base directory where products are stored. Each product is stored in a separate directory within this directory.
- verifySignatures
- (Optional, default = off) Whether or not to verify signatures:
- off
- no verification
- test
- test but accept invalid signatures
- anything else
- reject invalid signatures.
- keychain
- (Optional) List of key section names to load for signature verification.
String getProductPath(ProductId) ProductSource getProductSourceFormat(File) ProductOutput getProductHandlerFormat(File)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault storage path if none is provided.static final intThis is chosen because 16^3 = 4096 < 32000, which is the ext3 subdirectory limit.static final StringStorage path property name used by Configurable interface.static final StringProperty for legacyStorages.static final StringProperty for configured listenersstatic final booleanstatic final Stringstatic final booleanDo not use hashes (Default).static final StringProperty for whether or not to hash file paths. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new FileProductStorage using the default storage path.FileProductStorage(File baseDirectory) Create a new FileProductStorage. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStorageListener(StorageListener listener) Adds aStorageListenerto be notified when a change occurs in thisProductStorage.voidConfigure this object.protected StringGet a product from storage, loading all file contents into memory.getProduct(ProductId id) Get a product from storage.Get the file or directory used to store a specific product.protected ProductHandlergetProductHandlerFormat(File file) A method for subclasses to override the storage format.A method for subclasses to override the storage path.Get a ProductSource from storage.protected ProductSourcegetProductSourceFormat(File file) A method for subclasses to override the storage format.Get the temp file or directory used to store a specific product.booleanhasProduct(ProductId id) Check whether a product exists in storage.booleanbooleanvoidnotifyListeners(StorageEvent event) NotifiesStorageListeners of the change to theProductStorage.voidRemove a product from storage.voidremoveStorageListener(StorageListener listener) Removes aStorageListenerfrom being notified when a change occurs in thisProductStorage.voidsetBaseDirectory(File baseDirectory) voidsetKeychain(ProductKeyChain keychain) voidsetRejectInvalidSignatures(boolean rejectInvalidSignatures) voidsetTestSignatures(boolean testSignatures) voidshutdown()Called at client shutdown to free resources.voidstartup()Called after client configuration to begin processing.storeProduct(Product product) Store a product in storage.storeProductSource(ProductSource source) Store a ProductSource to storage.Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface gov.usgs.util.Configurable
getName, setName
-
Field Details
-
STORAGE_LISTENER_PROPERTY
Property for configured listeners- See Also:
-
DIRECTORY_PROPERTY_NAME
Storage path property name used by Configurable interface.- See Also:
-
DEFAULT_DIRECTORY
Default storage path if none is provided.- See Also:
-
USE_ATOMIC_DOWNLOAD_PROPERTY
- See Also:
-
USE_ATOMIC_DOWNLOAD_DEFAULT
public static final boolean USE_ATOMIC_DOWNLOAD_DEFAULT- See Also:
-
USE_HASH_PATHS_PROPERTY
Property for whether or not to hash file paths.- See Also:
-
USE_HASH_PATHS_DEFAULT
public static final boolean USE_HASH_PATHS_DEFAULTDo not use hashes (Default).- See Also:
-
LEGACY_STORAGES_PROPERTY
Property for legacyStorages.- See Also:
-
DIRECTORY_NAME_LENGTH
public static final int DIRECTORY_NAME_LENGTHThis is chosen because 16^3 = 4096 < 32000, which is the ext3 subdirectory limit.- See Also:
-
-
Constructor Details
-
FileProductStorage
public FileProductStorage()Create a new FileProductStorage using the default storage path. -
FileProductStorage
Create a new FileProductStorage.- Parameters:
baseDirectory- the base directory for all products being stored.
-
-
Method Details
-
getStorageLocks
- Returns:
- the storageLocks
-
configure
Configure this object. Expects a key named "directory".- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultConfigurable- Parameters:
config- the Config object with settings.- Throws:
Exception- if configuration exceptions occur.
-
notifyListeners
Description copied from interface:ProductStorageNotifiesStorageListeners of the change to theProductStorage.- Specified by:
notifyListenersin interfaceProductStorage- Parameters:
event- StorageEvent
-
addStorageListener
Description copied from interface:ProductStorageAdds aStorageListenerto be notified when a change occurs in thisProductStorage.- Specified by:
addStorageListenerin interfaceProductStorage- Parameters:
listener- The listener to notify of changes.
-
removeStorageListener
Description copied from interface:ProductStorageRemoves aStorageListenerfrom being notified when a change occurs in thisProductStorage.- Specified by:
removeStorageListenerin interfaceProductStorage- Parameters:
listener- The listener to remove
-
getProductPath
A method for subclasses to override the storage path. The returned path is appended to the base directory when storing and retrieving products.- Parameters:
id- the product id to convert.- Returns:
- the directory used to store id.
-
getHashedProductPath
- Parameters:
id- Specific productID- Returns:
- string buffer of hashed product path
-
getNormalProductPath
- Parameters:
id- ProductId- Returns:
- string buffer of normal product path
-
getProductHandlerFormat
A method for subclasses to override the storage format. When overriding this method, the method getProductSourceFormat should also be overridden.- Parameters:
file- a file that should be converted into a ProductHandler.- Returns:
- the ProductHandler.
- Throws:
Exception- if error occurs
-
getProductSourceFormat
A method for subclasses to override the storage format. When overriding this method, the method getProductHandlerFormat should also be overridden.- Parameters:
file- a file that should be converted into a ProductSource.- Returns:
- the ProductSource.
- Throws:
Exception- if error occurs
-
getProductFile
Get the file or directory used to store a specific product.- Parameters:
id- which product.- Returns:
- a file or directory where the product would be stored.
-
getTempProductFile
Get the temp file or directory used to store a specific product.- Parameters:
id- which product.- Returns:
- a file or directory where the product would be stored.
-
getProduct
Get a product from storage. Calls the getProductSource method, and uses ObjectProductHandler to convert the ProductSource into a Product.- Specified by:
getProductin interfaceProductStorage- Parameters:
id- the product to retrieve.- Returns:
- the product, or null if not in this storage.
- Throws:
Exception- if errors occur while retrieving product.
-
getInMemoryProduct
Get a product from storage, loading all file contents into memory. This method may cause memory problems if product contents are large.- Parameters:
id- the product to retrieve.- Returns:
- the loaded product.
- Throws:
Exception- if error occurs
-
getProductSource
Get a ProductSource from storage.- Specified by:
getProductSourcein interfaceProductStorage- Parameters:
id- the product to retrieve.- Returns:
- a ProductSource for the product, or null if not in this storage.
- Throws:
Exception- if any errors occur while getting the ProductInput.
-
hasProduct
Check whether a product exists in storage.- Specified by:
hasProductin interfaceProductStorage- Parameters:
id- the product to check.- Returns:
- true if the product exists, false otherwise.
- Throws:
Exception- if an error occurs while checking.
-
removeProduct
Remove a product from storage.- Specified by:
removeProductin interfaceProductStorage- Parameters:
id- product to remove.- Throws:
Exception- if errors occur while removing product.
-
storeProduct
Store a product in storage. Same as storeProductSource(new ObjectProductSource(product)).- Specified by:
storeProductin interfaceProductStorage- Parameters:
product- the product to store.- Returns:
- the id of the stored product.
- Throws:
Exception- if errors occur while storing product.
-
storeProductSource
Store a ProductSource to storage. If any exceptions occur while storing a product (other than the product already existing in storage) the incompletely stored product is removed.- Specified by:
storeProductSourcein interfaceProductStorage- Parameters:
source- the ProductSource to store.- Returns:
- the id of the stored product.
- Throws:
Exception- if errors occur while storing product.
-
shutdown
Called at client shutdown to free resources.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultConfigurable- Throws:
Exception- if exceptions occur while starting.
-
startup
Called after client configuration to begin processing.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultConfigurable- Throws:
Exception- if exceptions occur while starting.
-
getBaseDirectory
- Returns:
- the baseDirectory
-
setBaseDirectory
- Parameters:
baseDirectory- the baseDirectory to set
-
isRejectInvalidSignatures
public boolean isRejectInvalidSignatures()- Returns:
- the rejectInvalidSignatures
-
setRejectInvalidSignatures
public void setRejectInvalidSignatures(boolean rejectInvalidSignatures) - Parameters:
rejectInvalidSignatures- the rejectInvalidSignatures to set
-
isTestSignatures
public boolean isTestSignatures()- Returns:
- the testSignatures
-
setTestSignatures
public void setTestSignatures(boolean testSignatures) - Parameters:
testSignatures- the testSignatures to set
-
getKeychain
- Returns:
- the keychain
-
setKeychain
- Parameters:
keychain- the keychain to set
-
getLegacyStorages
- Returns:
- the legacyStorages.
-