Package thredds.crawlabledataset.s3
Class CachingThreddsS3Client
- java.lang.Object
-
- thredds.crawlabledataset.s3.CachingThreddsS3Client
-
- All Implemented Interfaces:
ThreddsS3Client
public class CachingThreddsS3Client extends Object implements ThreddsS3Client
A ThreddsS3Client that wraps another ThreddsS3Client and caches its methods' return values for efficiency.- Since:
- 2015/08/22
-
-
Constructor Summary
Constructors Constructor Description CachingThreddsS3Client(ThreddsS3Client threddsS3Client)
CachingThreddsS3Client(ThreddsS3Client threddsS3Client, com.google.common.cache.RemovalListener<S3URI,com.google.common.base.Optional<File>> removalListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Discards all entries from all caches.com.amazonaws.services.s3.model.ObjectMetadata
getObjectMetadata(S3URI s3uri)
Gets the metadata for the specified Amazon S3 object without actually fetching the object itself.com.amazonaws.services.s3.model.ObjectListing
listObjects(S3URI s3uri)
Returns a listing of the objects located in the "virtual filesystem" at the specified URI.File
saveObjectToFile(S3URI s3uri, File file)
Gets the object metadata for the object stored in Amazon S3 under the specified bucket and key, and saves the object contents to the specified file.
-
-
-
Constructor Detail
-
CachingThreddsS3Client
public CachingThreddsS3Client(ThreddsS3Client threddsS3Client)
-
CachingThreddsS3Client
public CachingThreddsS3Client(ThreddsS3Client threddsS3Client, com.google.common.cache.RemovalListener<S3URI,com.google.common.base.Optional<File>> removalListener)
-
-
Method Detail
-
getObjectMetadata
public com.amazonaws.services.s3.model.ObjectMetadata getObjectMetadata(S3URI s3uri)
Description copied from interface:ThreddsS3Client
Gets the metadata for the specified Amazon S3 object without actually fetching the object itself. The object metadata contains information such as content type, content disposition, etc., as well as custom user metadata that can be associated with an object in Amazon S3.- Specified by:
getObjectMetadata
in interfaceThreddsS3Client
- Parameters:
s3uri
- the Amazon S3 URI of the object whose metadata is being retrieved.- Returns:
- all Amazon S3 object metadata for the specified object.
Will be
null
if there is no S3 bucket with the specified name that has the specified key.
-
listObjects
public com.amazonaws.services.s3.model.ObjectListing listObjects(S3URI s3uri)
Description copied from interface:ThreddsS3Client
Returns a listing of the objects located in the "virtual filesystem" at the specified URI.s3uri.getKey()
is interpreted as a path, and only objects (accessible viaObjectListing.getObjectSummaries()
) or "directories" (accessible viaObjectListing.getCommonPrefixes()
) that have that prefix will be part of the returned listing.NOTE: To manage large result sets, Amazon S3 uses pagination to split them into multiple responses. As a consequence, this listing will only include the first 1000-or-so results.
TODO: Extend this API so that it allows the retrieval of more than 1000 results.
- Specified by:
listObjects
in interfaceThreddsS3Client
- Parameters:
s3uri
- the Amazon S3 URI of the "virtual directory" whose objects are being retrieved.- Returns:
- a listing of objects. Will be
null
if the specified URI does not denote an existing virtual directory. Otherwise, the result will be non-null and non-empty. That is, it will have at least one object summary or at least one common prefix. - See Also:
AmazonS3.listObjects(String)
-
saveObjectToFile
public File saveObjectToFile(S3URI s3uri, File file) throws IOException
Gets the object metadata for the object stored in Amazon S3 under the specified bucket and key, and saves the object contents to the specified file.WARNING: If the content at
s3uri
was previously saved using this method, and the old file to which it was saved is not the same asfile
, the object content will be copied to the new file and the old file will be deleted.- Specified by:
saveObjectToFile
in interfaceThreddsS3Client
- Parameters:
s3uri
- the Amazon S3 URI of the object whose content is being saved.file
- indicates the file (which might already exist) where to save the object content being downloading from Amazon S3.- Returns:
- the file in which the Amazon S3 object's content was saved.
Returns
null
if there is no S3 bucket with the specified name that has the specified key. - Throws:
IOException
- if some I/O error occurred on the local filesystem while writing to file.
-
clear
public void clear()
Discards all entries from all caches. Any files created bysaveObjectToFile(thredds.crawlabledataset.s3.S3URI, java.io.File)
will be deleted.
-
-