
org.jclouds.aws.s3.config.S3RestClientModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jclouds-aws Show documentation
Show all versions of jclouds-aws Show documentation
jclouds Core components to access Amazon AWS
The newest version!
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC.
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.s3.config;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.config.AWSRestClientModule;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.filters.RequestAuthorizeSignature;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
* Configures the S3 connection, including logging and http transport.
*
* @author Adrian Cole
*/
@ConfiguresRestClient
@RequiresHttp
public class S3RestClientModule extends AWSRestClientModule {
public S3RestClientModule() {
super(S3Client.class, S3AsyncClient.class);
}
@Override
protected void configure() {
install(new S3ObjectModule());
install(new S3ParserModule());
bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
super.configure();
}
@Provides
@Singleton
protected RequestSigner provideRequestSigner(RequestAuthorizeSignature in) {
return in;
}
@Provides
@TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier cache) {
return cache.get();
}
/**
* borrowing concurrency code to ensure that caching takes place properly
*/
@Provides
@TimeStamp
@Singleton
protected Supplier provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) {
return Suppliers.memoizeWithExpiration(new Supplier() {
public String get() {
return dateService.rfc822DateFormat();
}
}, seconds, TimeUnit.SECONDS);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy