public class ThrottledGoogleCloudStorage extends Object implements GoogleCloudStorage
Modifier and Type | Class and Description |
---|---|
static class |
ThrottledGoogleCloudStorage.StorageOperation
Operations that may be throttled.
|
GoogleCloudStorage.ListPage<T>
MAX_COMPOSE_OBJECTS, MAX_RESULTS_UNLIMITED, PATH_DELIMITER
Constructor and Description |
---|
ThrottledGoogleCloudStorage(double operationsPerSecond,
GoogleCloudStorage wrappedGcs,
EnumSet<ThrottledGoogleCloudStorage.StorageOperation> throttledOperations) |
ThrottledGoogleCloudStorage(GoogleCloudStorage wrappedGcs,
com.google.common.util.concurrent.RateLimiter rateLimiter)
Construct a ThrottledGoogleCloudStorage object that throttles all operations.
|
ThrottledGoogleCloudStorage(com.google.common.util.concurrent.RateLimiter rateLimiter,
GoogleCloudStorage wrappedGcs,
EnumSet<ThrottledGoogleCloudStorage.StorageOperation> throttledOperations) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Releases resources used by this instance.
|
void |
compose(String bucketName,
List<String> sources,
String destination,
String contentType)
Composes inputs into a single GCS object.
|
GoogleCloudStorageItemInfo |
composeObjects(List<StorageResourceId> sources,
StorageResourceId destination,
CreateObjectOptions options)
Composes inputs into a single GCS object.
|
void |
copy(String srcBucketName,
List<String> srcObjectNames,
String dstBucketName,
List<String> dstObjectNames)
Copies metadata of the given objects.
|
WritableByteChannel |
create(StorageResourceId resourceId)
Creates and opens an object for writing.
|
WritableByteChannel |
create(StorageResourceId resourceId,
CreateObjectOptions options)
Creates and opens an object for writing.
|
void |
create(String bucketName)
Creates a bucket.
|
void |
create(String bucketName,
CreateBucketOptions options)
Creates a bucket.
|
void |
createEmptyObject(StorageResourceId resourceId)
Creates an empty object, useful for placeholders representing, for example, directories.
|
void |
createEmptyObject(StorageResourceId resourceId,
CreateObjectOptions options)
Creates an empty object, useful for placeholders representing, for example, directories.
|
void |
createEmptyObjects(List<StorageResourceId> resourceIds)
Creates a list of empty objects; see
GoogleCloudStorage.createEmptyObject(StorageResourceId) for
the single-item version of this method. |
void |
createEmptyObjects(List<StorageResourceId> resourceIds,
CreateObjectOptions options)
Creates a list of empty objects; see
GoogleCloudStorage.createEmptyObject(StorageResourceId) for
the single-item version of this method. |
void |
deleteBuckets(List<String> bucketNames)
Deletes a list of buckets.
|
void |
deleteObjects(List<StorageResourceId> fullObjectNames)
Deletes the given objects.
|
GoogleCloudStorageItemInfo |
getItemInfo(StorageResourceId resourceId)
Gets information about an object or a bucket.
|
List<GoogleCloudStorageItemInfo> |
getItemInfos(List<StorageResourceId> resourceIds)
Gets information about multiple objects and/or buckets.
|
GoogleCloudStorageOptions |
getOptions()
Retrieve the options that were used to create this GoogleCloudStorage.
|
List<GoogleCloudStorageItemInfo> |
listBucketInfo()
Gets a list of GoogleCloudStorageItemInfo for all buckets of this project.
|
List<String> |
listBucketNames()
Gets a list of names of buckets in this project.
|
List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix,
String delimiter)
Same name-matching semantics as
GoogleCloudStorage.listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well. |
List<GoogleCloudStorageItemInfo> |
listObjectInfo(String bucketName,
String objectNamePrefix,
String delimiter,
long maxResults)
Same name-matching semantics as
GoogleCloudStorage.listObjectNames(java.lang.String, java.lang.String, java.lang.String) except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well. |
GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> |
listObjectInfoPage(String bucketName,
String objectNamePrefix,
String delimiter,
String pageToken)
The same semantics as
GoogleCloudStorage.listObjectInfo(java.lang.String, java.lang.String, java.lang.String) , but returns only result of single list request
(1 page). |
List<String> |
listObjectNames(String bucketName,
String objectNamePrefix,
String delimiter)
Gets names of objects contained in the given bucket and whose names begin with
the given prefix.
|
List<String> |
listObjectNames(String bucketName,
String objectNamePrefix,
String delimiter,
long maxResults)
Gets names of objects contained in the given bucket and whose names begin with
the given prefix.
|
SeekableByteChannel |
open(StorageResourceId resourceId)
Opens an object for reading.
|
SeekableByteChannel |
open(StorageResourceId resourceId,
GoogleCloudStorageReadOptions readOptions)
Opens an object for reading.
|
List<GoogleCloudStorageItemInfo> |
updateItems(List<UpdatableItemInfo> itemInfoList)
Attempt to update metadata of the objects referenced within the passed itemInfo objects.
|
public ThrottledGoogleCloudStorage(GoogleCloudStorage wrappedGcs, com.google.common.util.concurrent.RateLimiter rateLimiter)
wrappedGcs
- The GCS to wrap withrateLimiter
- The RateLimiter to control operations permitted per timespan.public ThrottledGoogleCloudStorage(double operationsPerSecond, GoogleCloudStorage wrappedGcs, EnumSet<ThrottledGoogleCloudStorage.StorageOperation> throttledOperations)
operationsPerSecond
- Operations per second to allow.wrappedGcs
- The GoogleCloudStorage that we should delegate operations to.throttledOperations
- The operations that should be throttled.public ThrottledGoogleCloudStorage(com.google.common.util.concurrent.RateLimiter rateLimiter, GoogleCloudStorage wrappedGcs, EnumSet<ThrottledGoogleCloudStorage.StorageOperation> throttledOperations)
rateLimiter
- The RateLimiter to control operations permitted per timespan.wrappedGcs
- The GoogleCloudStorage that we should delegate operations to.throttledOperations
- The operations that should be throttled.public GoogleCloudStorageOptions getOptions()
GoogleCloudStorage
getOptions
in interface GoogleCloudStorage
public WritableByteChannel create(StorageResourceId resourceId) throws IOException
GoogleCloudStorage
resourceId
doesn't have a explicit generationId set, it is deleted. If a
generationId is provided in resourceId
, that is used in place of normal overwrite
semantics (overwrite will only succeed if the provided generationId matches the existing
object, where a generationId of 0 indicates no existing object expected).create
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectIOException
- on IO errorpublic WritableByteChannel create(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
GoogleCloudStorage
resourceId
contains a known generationId or a generationId of 0, it is used instead of any "overwrite"
settings in the provided CreateObjectOptions
(overwrite will only succeed if the
provided generationId matches the existing object, where a generationId of 0 indicates no
existing object expected).create
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectoptions
- Options to use when creating the objectIOException
- on IO errorpublic void create(String bucketName) throws IOException
GoogleCloudStorage
create
in interface GoogleCloudStorage
bucketName
- name of the bucket to createIOException
- on IO errorpublic void create(String bucketName, CreateBucketOptions options) throws IOException
GoogleCloudStorage
create
in interface GoogleCloudStorage
bucketName
- name of the bucket to createoptions
- options to use when creating bucketIOException
- on IO errorpublic void createEmptyObject(StorageResourceId resourceId) throws IOException
GoogleCloudStorage
GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId() is
explicitly set.createEmptyObject
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectIOException
- on IO errorpublic void createEmptyObject(StorageResourceId resourceId, CreateObjectOptions options) throws IOException
GoogleCloudStorage
GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set.createEmptyObject
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectoptions
- options to use when creating the objectIOException
- on IO errorpublic void createEmptyObjects(List<StorageResourceId> resourceIds) throws IOException
GoogleCloudStorage
GoogleCloudStorage.createEmptyObject(StorageResourceId)
for
the single-item version of this method. Implementations may use different flow than the
single-item version for greater efficiency.
See GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set.createEmptyObjects
in interface GoogleCloudStorage
IOException
public void createEmptyObjects(List<StorageResourceId> resourceIds, CreateObjectOptions options) throws IOException
GoogleCloudStorage
GoogleCloudStorage.createEmptyObject(StorageResourceId)
for
the single-item version of this method. Implementations may use different flow than the
single-item version for greater efficiency.
See GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set.createEmptyObjects
in interface GoogleCloudStorage
IOException
public SeekableByteChannel open(StorageResourceId resourceId) throws IOException
GoogleCloudStorage
open
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectFileNotFoundException
- if the given object does not existIOException
- if object exists but cannot be openedpublic SeekableByteChannel open(StorageResourceId resourceId, GoogleCloudStorageReadOptions readOptions) throws IOException
GoogleCloudStorage
open
in interface GoogleCloudStorage
resourceId
- identifies a StorageObjectreadOptions
- Fine-grained options for behaviors of retries, buffering, etc.FileNotFoundException
- if the given object does not existIOException
- if object exists but cannot be openedpublic void deleteBuckets(List<String> bucketNames) throws IOException
GoogleCloudStorage
deleteBuckets
in interface GoogleCloudStorage
bucketNames
- name of the buckets to deleteFileNotFoundException
- if the given bucket does not existIOException
- on IO errorpublic void deleteObjects(List<StorageResourceId> fullObjectNames) throws IOException
GoogleCloudStorage
deleteObjects
in interface GoogleCloudStorage
fullObjectNames
- names of objects to delete with their respective bucketNames.FileNotFoundException
- if the given object does not existIOException
- if object exists but cannot be deletedpublic void copy(String srcBucketName, List<String> srcObjectNames, String dstBucketName, List<String> dstObjectNames) throws IOException
GoogleCloudStorage
copy
in interface GoogleCloudStorage
srcBucketName
- name of the bucket containing the objects to copysrcObjectNames
- names of the objects to copydstBucketName
- name of the bucket to copy todstObjectNames
- names of the objects after copyFileNotFoundException
- if the source object or the destination bucket does not
existIOException
- in all other error casespublic List<String> listBucketNames() throws IOException
GoogleCloudStorage
listBucketNames
in interface GoogleCloudStorage
IOException
public List<GoogleCloudStorageItemInfo> listBucketInfo() throws IOException
GoogleCloudStorage
listBucketInfo
in interface GoogleCloudStorage
IOException
public List<String> listObjectNames(String bucketName, String objectNamePrefix, String delimiter) throws IOException
GoogleCloudStorage
Note: Although GCS does not implement a file system, it treats objects that contain a delimiter as different from other objects when listing objects. This will be clearer with an example.
Consider a bucket with objects: o1, d1/, d1/o1, d1/o2 With prefix == null and delimiter == /, we get: d1/, o1 With prefix == null and delimiter == null, we get: o1, d1/, d1/o1, d1/o2
Thus when delimiter is null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.
The default implementation of this method should turn around and call
the version that takes maxResults
so that inheriting classes
need only implement that version.
listObjectNames
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullIOException
- on IO errorpublic List<String> listObjectNames(String bucketName, String objectNamePrefix, String delimiter, long maxResults) throws IOException
GoogleCloudStorage
Note: Although GCS does not implement a file system, it treats objects that contain a delimiter as different from other objects when listing objects. This will be clearer with an example.
Consider a bucket with objects: o1, d1/, d1/o1, d1/o2 With prefix == null and delimiter == /, we get: d1/, o1 With prefix == null and delimiter == null, we get: o1, d1/, d1/o1, d1/o2
Thus when delimiter is null, the entire key name is considered an opaque string, otherwise only the part up to the first delimiter is considered.
listObjectNames
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullmaxResults
- maximum number of results to return,
unlimited if negative or zeroIOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, String delimiter) throws IOException
GoogleCloudStorage
GoogleCloudStorage.listObjectNames(java.lang.String, java.lang.String, java.lang.String)
except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well.
Generally the info is already available from the same "list()" calls, so the only additional cost is dispatching an extra batch request to retrieve object metadata for all listed directories, since these are originally listed as String prefixes without attached metadata.
The default implementation of this method should turn around and call the version that takes
maxResults
so that inheriting classes need only implement that version.
listObjectInfo
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullIOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix, String delimiter, long maxResults) throws IOException
GoogleCloudStorage
GoogleCloudStorage.listObjectNames(java.lang.String, java.lang.String, java.lang.String)
except this method retrieves the full
GoogleCloudStorageFileInfo for each item as well.
Generally the info is already available from the same "list()" calls, so the only additional cost is dispatching an extra batch request to retrieve object metadata for all listed directories, since these are originally listed as String prefixes without attached metadata.
listObjectInfo
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullmaxResults
- maximum number of results to return, unlimited if negative or zeroIOException
- on IO errorpublic GoogleCloudStorage.ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(String bucketName, String objectNamePrefix, String delimiter, String pageToken) throws IOException
GoogleCloudStorage
GoogleCloudStorage.listObjectInfo(java.lang.String, java.lang.String, java.lang.String)
, but returns only result of single list request
(1 page).listObjectInfoPage
in interface GoogleCloudStorage
bucketName
- bucket nameobjectNamePrefix
- object name prefix or null if all objects in the bucket are desireddelimiter
- delimiter to use (typically "/"), otherwise nullpageToken
- the page tokenGoogleCloudStorage.ListPage
object with listed GoogleCloudStorageItemInfo
s and next page
token if anyIOException
- on IO errorpublic GoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId) throws IOException
GoogleCloudStorage
getItemInfo
in interface GoogleCloudStorage
resourceId
- identifies either root, a Bucket, or a StorageObjectIOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds) throws IOException
GoogleCloudStorage
getItemInfos
in interface GoogleCloudStorage
resourceIds
- names of the GCS StorageObjects or Buckets for which to retrieve info.IOException
- on IO errorpublic List<GoogleCloudStorageItemInfo> updateItems(List<UpdatableItemInfo> itemInfoList) throws IOException
GoogleCloudStorage
updateItems
in interface GoogleCloudStorage
IOException
- on IO errorpublic void close()
GoogleCloudStorage
close
in interface GoogleCloudStorage
public void compose(String bucketName, List<String> sources, String destination, String contentType) throws IOException
GoogleCloudStorage
compose
in interface GoogleCloudStorage
bucketName
- name of the bucket containing the sources and the destinationsources
- names of the objects to be composeddestination
- name of the resulting objectcontentType
- content-type of composed objectIOException
- if the Compose operation was unsuccessfulpublic GoogleCloudStorageItemInfo composeObjects(List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options) throws IOException
GoogleCloudStorage
options
. Overwrite semantics for the destination object will follow the
same semantics as GoogleCloudStorage.create(StorageResourceId, CreateObjectOptions)
.
See GoogleCloudStorage.create(StorageResourceId)
for the behavior if StorageResourceId.getGenerationId()
is explicitly set. The bucket must be the same for all sources and the destination.composeObjects
in interface GoogleCloudStorage
IOException
Copyright © 2019. All rights reserved.