[infinispan-commits] Infinispan SVN: r208 - in trunk/cachestore/s3/src: main/java/org/infinispan/loader/s3/jclouds and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Sat May 2 16:45:30 EDT 2009
Author: adriancole
Date: 2009-05-02 16:45:30 -0400 (Sat, 02 May 2009)
New Revision: 208
Modified:
trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStoreConfig.java
trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsBucket.java
trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsConnection.java
trunk/cachestore/s3/src/main/resources/jclouds.properties
trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java
Log:
hardened S3, allowing configurable time-outs avoiding hung requests
Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStoreConfig.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStoreConfig.java 2009-05-02 10:18:28 UTC (rev 207)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStoreConfig.java 2009-05-02 20:45:30 UTC (rev 208)
@@ -9,7 +9,8 @@
* <ul> <li><tt>awsAccessKey</tt> - identifies you as the party responsible for s3 requests. This is required and there
* is no default.</li> <li><tt>awsSecretKey</tt> - used to authenticate you as the owner of <tt>awsAccessKey</tt>. This
* is required and there is no default.</li> <li><tt>bucket</tt> - the name of the s3 bucket used to store cache data.
- * This is required and there is no default.</li> </ul>
+ * This is required and there is no default.</li>
+ * <li><tt>requestTimeout</tt> - The maximum amount of milliseconds a single S3 request can take before throwing an exception. Default is 10000</li></ul>
*
* @author Adrian Cole
* @since 4.0
@@ -20,7 +21,18 @@
private String bucket;
private String proxyHost;
private int proxyPort;
+ private long requestTimeout = 10000;
+
+ public long getRequestTimeout() {
+ return requestTimeout;
+ }
+
+ public void setRequestTimeout(long requestTimeout) {
+ this.requestTimeout = requestTimeout;
+ }
+
+
public int getMaxConnections() {
return maxConnections;
}
Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsBucket.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsBucket.java 2009-05-02 10:18:28 UTC (rev 207)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsBucket.java 2009-05-02 20:45:30 UTC (rev 208)
@@ -3,8 +3,6 @@
import org.infinispan.loader.bucket.Bucket;
import org.infinispan.loader.s3.S3ConnectionException;
import org.jclouds.aws.s3.domain.S3Bucket;
-import org.jclouds.aws.s3.domain.S3Object;
-import org.jclouds.aws.s3.S3ObjectMap;
import org.jclouds.aws.s3.S3InputStreamMap;
import java.io.InputStream;
Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsConnection.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsConnection.java 2009-05-02 10:18:28 UTC (rev 207)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/jclouds/JCloudsConnection.java 2009-05-02 20:45:30 UTC (rev 208)
@@ -14,7 +14,10 @@
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* An JClouds implementation of {@link S3Connection}. This implementation uses the threadsafe {@link S3HttpNioConnectionPoolClientModule} transport.
*
@@ -25,26 +28,33 @@
protected org.jclouds.aws.s3.S3Connection s3Service;
protected S3Context context;
protected Marshaller marshaller;
+ protected S3CacheStoreConfig config;
/**
* {@inheritDoc}
*/
public void connect(S3CacheStoreConfig config, Marshaller m) throws S3ConnectionException {
+ this.config = config;
InputStream propertiesIS;
try {
propertiesIS = JCloudsConnection.class.getResourceAsStream("/jclouds.properties");
Properties properties = new Properties();
properties.load(propertiesIS);
if (!config.isSecure()) {
- properties.put(S3Constants.PROPERTY_HTTP_PORT, "80");
- properties.put(S3Constants.PROPERTY_HTTP_SECURE, "false");
+ properties.setProperty(S3Constants.PROPERTY_HTTP_PORT, "80");
+ properties.setProperty(S3Constants.PROPERTY_HTTP_SECURE, "false");
}
+ if (properties.containsKey(S3Constants.PROPERTY_AWS_MAP_TIMEOUT)) {
+ config.setRequestTimeout(Long.parseLong(properties.getProperty(S3Constants.PROPERTY_AWS_MAP_TIMEOUT)));
+ } else {
+ properties.setProperty(S3Constants.PROPERTY_AWS_MAP_TIMEOUT, config.getRequestTimeout()+"");
+ }
if (!properties.containsKey(S3Constants.PROPERTY_AWS_ACCESSKEYID))
- properties.put(S3Constants.PROPERTY_AWS_ACCESSKEYID, config.getAwsAccessKey());
+ properties.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID, checkNotNull(config.getAwsAccessKey(),"config.getAwsAccessKey()"));
if (!properties.containsKey(S3Constants.PROPERTY_AWS_SECRETACCESSKEY))
- properties.put(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, config.getAwsSecretKey());
+ properties.setProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(config.getAwsSecretKey(),"config.getAwsSecretKey()"));
if (!properties.containsKey(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS))
- properties.put(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS, config.getMaxConnections());
+ properties.setProperty(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS, config.getMaxConnections()+"");
//TODO proxy host/port
this.context = S3ContextFactory.createS3Context(properties, new S3HttpNioConnectionPoolClientModule());
this.s3Service = context.getConnection();
@@ -68,7 +78,7 @@
public org.jclouds.aws.s3.domain.S3Bucket verifyOrCreateBucket(String bucketName) throws S3ConnectionException {
try {
org.jclouds.aws.s3.domain.S3Bucket bucket = new org.jclouds.aws.s3.domain.S3Bucket(bucketName);
- s3Service.createBucketIfNotExists(bucket).get();
+ s3Service.createBucketIfNotExists(bucket).get(config.getRequestTimeout(), TimeUnit.MILLISECONDS);
return bucket;
} catch (Exception ex) {
throw convertToS3ConnectionException("Exception retrieving or creating s3 bucket " + bucketName, ex);
@@ -97,14 +107,14 @@
Set<String> sourceKeys;
try {
S3Bucket source = new S3Bucket(sourceBucket);
- source = s3Service.getBucket(source).get();
+ source = s3Service.getBucket(source).get(config.getRequestTimeout(), TimeUnit.MILLISECONDS);
sourceKeys = keysInBucket(source);
S3Bucket dest = new S3Bucket(destinationBucket);
for (String key : sourceKeys) {
try {
S3Object object = new S3Object(key);
- s3Service.copyObject(source, object, dest, object).get();
+ s3Service.copyObject(source, object, dest, object).get(config.getRequestTimeout(), TimeUnit.MILLISECONDS);
} catch (Exception ex) {
throw convertToS3ConnectionException("Exception while copying key " + key + " from bucket " + sourceBucket, ex);
}
Modified: trunk/cachestore/s3/src/main/resources/jclouds.properties
===================================================================
--- trunk/cachestore/s3/src/main/resources/jclouds.properties 2009-05-02 10:18:28 UTC (rev 207)
+++ trunk/cachestore/s3/src/main/resources/jclouds.properties 2009-05-02 20:45:30 UTC (rev 208)
@@ -6,8 +6,3 @@
jclouds.http.pool.request_invoker_threads=1
jclouds.http.pool.io_worker_threads=2
jclouds.pool.max_connections=12
-jclouds.http.pool.max_connection_reuse=75
-jclouds.http.pool.max_session_failures=2
-jclouds.http.pool.request_invoker_threads=1
-jclouds.http.pool.io_worker_threads=2
-jclouds.pool.max_connections=12
\ No newline at end of file
Modified: trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java
===================================================================
--- trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java 2009-05-02 10:18:28 UTC (rev 207)
+++ trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java 2009-05-02 20:45:30 UTC (rev 208)
@@ -13,8 +13,10 @@
import org.testng.annotations.*;
import java.io.*;
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
+import java.util.logging.*;
/**
* @author Adrian Cole
@@ -23,6 +25,7 @@
*/
@Test(groups = "unit", sequential = true, testName = "loader.s3.S3CacheStoreIntegrationTest")
public class S3CacheStoreIntegrationTest extends BaseCacheStoreTest {
+
private String proxyHost;
private int proxyPort = -1;
private int maxConnections = 20;
More information about the infinispan-commits
mailing list