public class S3ClientCache
extends java.lang.Object
AmazonS3
objects. S3ClientCache
keeps the
clients organized by region, and if provided AWSCredentials
will
create clients on the fly. Otherwise it just return clients given to it with
useClient(AmazonS3)
.Modifier and Type | Field and Description |
---|---|
private AWSCredentialsProvider |
awscredentialsProvider |
private java.util.concurrent.ConcurrentMap<Region,AmazonS3> |
clientsByRegion |
private java.util.Map<Region,TransferManager> |
transferManagersByRegion |
Constructor and Description |
---|
S3ClientCache(AWSCredentials credentials)
Deprecated.
|
S3ClientCache(AWSCredentialsProvider awsCredentialsProvider)
Create a client cache using the given AWSCredentialsProvider.
|
Modifier and Type | Method and Description |
---|---|
private AmazonS3 |
cacheClient(Region s3region)
Returns a new client with region configured to
s3region.
|
AmazonS3 |
getClient(Region s3region)
Returns a client for the requested region, or throws an exception when
unable.
|
TransferManager |
getTransferManager(Region region)
Returns a
TransferManager for the given region, or throws an
exception when unable. |
void |
useClient(AmazonS3 client)
Force the client cache to provide a certain client for the region which
that client is configured.
|
private final java.util.Map<Region,TransferManager> transferManagersByRegion
private final AWSCredentialsProvider awscredentialsProvider
@Deprecated S3ClientCache(AWSCredentials credentials)
S3ClientCache(AWSCredentialsProvider awsCredentialsProvider)
#getClient(Regions)
or #getTransferManager(Regions)
is
called and a client has not been provided for the region, the cache will
instantiate one from the provided AWSCredentialsProvider
.awsCredentialsProvider
- The credentials provider to use when creating new
AmazonS3
.public void useClient(AmazonS3 client)
S3ClientOptions
or use a
AmazonS3EncryptionClient
in place of a
regular client.
Using a new client will also forcibly shut down any
TransferManager
that has been instantiated with that client, with
the TransferManager.shutdownNow()
method.client
- An AmazonS3
to use in the cache. Its region will
be detected automatically.public AmazonS3 getClient(Region s3region)
s3region
- The region the returned AmazonS3
will be
configured to use.AWSCredentials
or
provided with useClient(AmazonS3)
.java.lang.IllegalArgumentException
- When a region is requested that has not been provided to the
cache with useClient(AmazonS3)
, and the cache
has no AWSCredentials
with which a client may be
instantiated.private AmazonS3 cacheClient(Region s3region)
public TransferManager getTransferManager(Region region)
TransferManager
for the given region, or throws an
exception when unable. The returned TransferManager
will always
be instantiated from whatever AmazonS3
is in the cache,
whether provided with useClient(AmazonS3)
or instantiated
automatically from AWSCredentials
.
Any TransferManager
returned could be shut down if a new
underlying AmazonS3
is provided with
useClient(AmazonS3)
.region
- The region the returned TransferManager
will be
configured to use.AmazonS3
,