public abstract class DirectoryListCache extends Object
Depending on the extent to which the underlying data structures accessed by implementations of this class are shared, callers can guarantee varying levels of immediate list consistency between file-creation and a subsequent "list" request.
Implementations of this class must be thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
DirectoryListCache.Config
Container for various cache-configuration parameters used by a DirectoryListCache when
managing expiration/retention policies, etc.
|
static class |
DirectoryListCache.Type
Known types of DirectoryListCache implementations.
|
Modifier and Type | Field and Description |
---|---|
protected DirectoryListCache.Config |
cacheConfig |
protected com.google.api.client.util.Clock |
clock |
Constructor and Description |
---|
DirectoryListCache() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
containsEntriesForImplicitDirectories()
Implementations should indicate whether implicit directories are automatically detected and
added as CacheEntry items when putResourceId is called without first adding explicit
directory objects for the implied parent directories of the added object.
|
abstract List<CacheEntry> |
getBucketList() |
abstract CacheEntry |
getCacheEntry(StorageResourceId resourceId)
Returns the CacheEntry associated with
resourceId , or null if it doesn't exist. |
abstract int |
getInternalNumBuckets()
Gets the internal number of CachedBucket entries, which may not be equal to the size of
getBucketList() if there are expired entries.
|
abstract int |
getInternalNumObjects()
Gets the internal total count of cached StorageObject entries.
|
DirectoryListCache.Config |
getMutableConfig()
Returns the
Config instance used by this DirectoryListCache instance to determine
expiration ages, etc. |
abstract List<CacheEntry> |
getObjectList(String bucketName,
String objectNamePrefix,
String delimiter,
Set<String> returnedPrefixes) |
abstract List<CacheEntry> |
getRawBucketList() |
protected boolean |
isCacheEntryExpired(CacheEntry entry)
Helper for determining whether a CacheEntry is entirely expired and should be removed
from the cache.
|
protected void |
maybeInvalidateExpiredInfo(CacheEntry entry)
Helper for possibly clearing the GoogleCloudStorageItemInfo stored in
entry based
on cacheConfig settings. |
abstract CacheEntry |
putResourceId(StorageResourceId resourceId)
Adds the names of the Bucket or StorageObject referenced by
resourceId to the cache,
with no attached metadata. |
abstract void |
removeResourceId(StorageResourceId resourceId)
Removes CacheEntry associated with
resourceId , if it exists. |
void |
setClock(com.google.api.client.util.Clock clock)
Sets the static Clock instance used for calculating expiration times.
|
abstract boolean |
supportsCacheEntryByReference()
Implementations should indicate whether or not CacheEntry objects returned from methods are
intended to be shared references which are authoritative cache state regarding metadata
like cached GoogleCloudStorageItemInfo, etc.
|
protected static void |
validateResourceId(StorageResourceId resourceId)
Helper to validate
resourceId which may be a Bucket or StorageObject. |
protected com.google.api.client.util.Clock clock
protected DirectoryListCache.Config cacheConfig
public abstract boolean supportsCacheEntryByReference()
public abstract boolean containsEntriesForImplicitDirectories()
public abstract CacheEntry putResourceId(StorageResourceId resourceId) throws IOException
resourceId
to the cache,
with no attached metadata. If the entry already exists, then nothing is modified. If resourceId
is a StorageObject, the parent Bucket name is also added to the cache, if it doesn't already
exist.
TODO(user): Even if the entry exists, it might be correct to invalidate any existing metadata
and force a refresh next time it is fetched.IOException
public abstract CacheEntry getCacheEntry(StorageResourceId resourceId) throws IOException
resourceId
, or null if it doesn't exist.
This returns the real mutable CacheEntry (rather than a copy of the data) so that the
caller may efficiently update the info stored in the CacheEntry if necessary.IOException
public abstract void removeResourceId(StorageResourceId resourceId) throws IOException
resourceId
, if it exists. Cached
GoogleCloudStorageItemInfo associated with the resourceId is also removed, if it exists.
If resourceId
denotes a non-empty bucket, then all the cached StorageObject children
of that bucket will also be removed from the cache; it is the caller's responsibility to
ensure that the bucket should really be removed. Note that normal expiration of a CachedBucket
will *not* remove the actual CachedBucket, even though the bucketName will stop appearing
in calls to getBucketList().IOException
public abstract List<CacheEntry> getBucketList() throws IOException
IOException
public abstract List<CacheEntry> getRawBucketList() throws IOException
IOException
public abstract List<CacheEntry> getObjectList(String bucketName, String objectNamePrefix, String delimiter, Set<String> returnedPrefixes) throws IOException
bucketName
- The bucket inside of which to list objects.objectNamePrefix
- The prefix to be used to match object names to return.delimiter
- The character for specifying 'directory' boundaries, or null.returnedPrefixes
- A container to be populated with implied "directory objects" that
come from some object which includes the prefix, followed by some string, then followed
by the 'delimiter'. This may or may not be a duplicate of one of the actual returned
directory objects. For example, if gs://foo/bar/baz.txt exists and we query with parameters
("foo", "ba", "/", {}) then the returnedPrefixes will be populated with the string
"bar/" by virtue of existence of the "bar/baz.txt" file. May be null if the caller doesn't
desire fetching such returnedPrefixes.bucketName
which
match the provided objectNamePrefix and delimiter, or possibly null if no such objects
are present. May also return an empty list.IOException
public abstract int getInternalNumBuckets() throws IOException
IOException
public abstract int getInternalNumObjects() throws IOException
IOException
public DirectoryListCache.Config getMutableConfig()
Config
instance used by this DirectoryListCache instance to determine
expiration ages, etc. It is the actual mutable Config object, such that modifications in-place
made to the returned Config will immediately be reflected in the behavior of the
DirectoryListCache.public void setClock(com.google.api.client.util.Clock clock)
protected boolean isCacheEntryExpired(CacheEntry entry)
protected static void validateResourceId(StorageResourceId resourceId)
resourceId
which may be a Bucket or StorageObject.protected void maybeInvalidateExpiredInfo(CacheEntry entry)
entry
based
on cacheConfig settings.Copyright © 2015. All rights reserved.