[infinispan-commits] Infinispan SVN: r221 - trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed May 6 18:36:05 EDT 2009


Author: adriancole
Date: 2009-05-06 18:36:05 -0400 (Wed, 06 May 2009)
New Revision: 221

Modified:
   trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsBucket.java
   trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java
Log:
latest jclouds

Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsBucket.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsBucket.java	2009-05-06 18:18:25 UTC (rev 220)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsBucket.java	2009-05-06 22:36:05 UTC (rev 221)
@@ -11,126 +11,140 @@
 import java.util.Set;
 
 /**
- * A {@link org.jclouds.aws.s3.S3Connection JClouds} implementation of {@link org.infinispan.loaders.s3.S3Bucket}.
+ * A {@link org.jclouds.aws.s3.S3Connection JClouds} implementation of
+ * {@link org.infinispan.loaders.s3.S3Bucket}.
  * <p/>
- * Tuning and configuration parameters can be overridden by creating <tt>jclouds.properties</tt> and adding it to your
- * classpath.
- *
+ * Tuning and configuration parameters can be overridden by creating
+ * <tt>jclouds.properties</tt> and adding it to your classpath.
+ * 
  * @author Adrian Cole
  * @link http://code.google.com/p/jclouds
  * @since 4.0
  */
-public class JCloudsBucket implements org.infinispan.loaders.s3.S3Bucket<S3Bucket, org.infinispan.loaders.s3.jclouds.JCloudsConnection> {
+public class JCloudsBucket
+	implements
+	org.infinispan.loaders.s3.S3Bucket<S3Bucket, org.infinispan.loaders.s3.jclouds.JCloudsConnection> {
 
-   private JCloudsConnection connection;
-   private String name;
-   private S3Bucket rootS3Bucket;
-   private Map<String, InputStream> map;
+    private JCloudsConnection connection;
+    private String name;
+    private S3Bucket rootS3Bucket;
+    private Map<String, InputStream> map;
 
-   public void init(JCloudsConnection connection, S3Bucket bucket) {
-      this.connection = connection;
-      this.rootS3Bucket = bucket;
-      this.name = bucket.getName();
-      this.map = connection.context.createInputStreamMap(rootS3Bucket);
-   }
+    public void init(JCloudsConnection connection, S3Bucket bucket) {
+	this.connection = connection;
+	this.rootS3Bucket = bucket;
+	this.name = bucket.getName();
+	this.map = connection.context.createInputStreamMap(rootS3Bucket
+		.getName());
+    }
 
-   public String getName() {
-      return name;
-   }
+    public String getName() {
+	return name;
+    }
 
+    /**
+     * {@inheritDoc}
+     */
+    public Bucket get(String key) throws S3ConnectionException {
+	InputStream input = null;
+	try {
+	    input = map.get(key);
+	    // it is possible that the object never existed. in this case, fall
+	    // out.
+	    if (input != null) {
+		return bucketFromStream(key, input);
+	    }
+	    return null;
+	} catch (Exception e) {
+	    throw connection.convertToS3ConnectionException(
+		    "Error while reading from object: " + key, e);
+	} finally {
+	    safeClose(input);
+	}
+    }
 
-   /**
-    * {@inheritDoc}
-    */
-   public Bucket get(String key) throws S3ConnectionException {
-      InputStream input = null;
-      try {
-         input = map.get(key);
-         // it is possible that the object never existed. in this case, fall out.
-         if (input != null) {
-            return bucketFromStream(key, input);
-         }
-         return null;
-      } catch (Exception e) {
-         throw connection.convertToS3ConnectionException("Error while reading from object: " + key, e);
-      } finally {
-         safeClose(input);
-      }
-   }
+    private Bucket bucketFromStream(String key, InputStream input)
+	    throws S3ConnectionException {
+	try {
+	    Bucket bucket = (Bucket) connection.marshaller
+		    .objectFromStream(input);
+	    // TODO hack until we are sure the bucket has an immutable name
+	    bucket.setBucketName(key);
+	    return bucket;
+	} catch (Exception e) {
+	    throw connection.convertToS3ConnectionException(
+		    "Error while reading from object: " + key, e);
+	} finally {
+	    safeClose(input);
+	}
+    }
 
-   private Bucket bucketFromStream(String key, InputStream input) throws S3ConnectionException {
-      try {
-         Bucket bucket = (Bucket) connection.marshaller.objectFromStream(input);
-         // TODO hack until we are sure the bucket has an immutable name
-         bucket.setBucketName(key);
-         return bucket;
-      } catch (Exception e) {
-         throw connection.convertToS3ConnectionException("Error while reading from object: " + key, e);
-      } finally {
-         safeClose(input);
-      }
-   }
+    /**
+     * {@inheritDoc}
+     */
 
-   /**
-    * {@inheritDoc}
-    */
+    public void remove(String key) throws S3ConnectionException {
+	try {
+	    map.remove(key);
+	} catch (Exception ex) {
+	    throw connection.convertToS3ConnectionException(
+		    "Exception removing key " + key, ex);
+	}
+    }
 
-   public void remove(String key) throws S3ConnectionException {
-      try {
-         map.remove(key);
-      } catch (Exception ex) {
-         throw connection.convertToS3ConnectionException("Exception removing key " + key, ex);
-      }
-   }
+    /**
+     * {@inheritDoc}
+     */
+    public Set<String> keySet() throws S3ConnectionException {
+	return connection.keysInBucket(rootS3Bucket);
+    }
 
-   /**
-    * {@inheritDoc}
-    */
-   public Set<String> keySet() throws S3ConnectionException {
-      return connection.keysInBucket(rootS3Bucket);
-   }
+    public Set<Bucket> values() throws S3ConnectionException {
+	Set<Bucket> buckets = new HashSet<Bucket>();
+	for (Map.Entry<String, InputStream> entry : map.entrySet()) {
+	    buckets.add(bucketFromStream(entry.getKey(), entry.getValue()));
+	}
+	return buckets;
+    }
 
-   public Set<Bucket> values() throws S3ConnectionException {
-      Set<Bucket> buckets = new HashSet<Bucket>();
-      for (Map.Entry<String, InputStream> entry : map.entrySet()) {
-         buckets.add(bucketFromStream(entry.getKey(), entry.getValue()));
-      }
-      return buckets;
-   }
+    /**
+     * {@inheritDoc}
+     */
+    public void clear() throws S3ConnectionException {
+	try {
+	    map.clear();
+	} catch (Exception ex) {
+	    throw connection.convertToS3ConnectionException(
+		    "Exception clearing store", ex);
+	}
+    }
 
-   /**
-    * {@inheritDoc}
-    */
-   public void clear() throws S3ConnectionException {
-      try {
-         map.clear();
-      } catch (Exception ex) {
-         throw connection.convertToS3ConnectionException("Exception clearing store", ex);
-      }
-   }
+    /**
+     * {@inheritDoc}
+     */
+    public void insert(Bucket b) throws S3ConnectionException {
+	try {
+	    if (b.getEntries().isEmpty()) {
+		map.remove(b.getBucketName());
+	    } else {
+		((S3InputStreamMap) map).putBytes(b.getBucketName(),
+			connection.marshaller.objectToByteBuffer(b));
+	    }
+	} catch (Exception ex) {
+	    throw connection.convertToS3ConnectionException(
+		    "Exception while saving bucket " + b, ex);
+	}
+    }
 
-   /**
-    * {@inheritDoc}
-    */
-   public void insert(Bucket b) throws S3ConnectionException {
-      try {
-         if (b.getEntries().isEmpty()) {
-            map.remove(b.getBucketName());
-         } else {
-            ((S3InputStreamMap) map).putBytes(b.getBucketName(), connection.marshaller.objectToByteBuffer(b));
-         }
-      } catch (Exception ex) {
-         throw connection.convertToS3ConnectionException("Exception while saving bucket " + b, ex);
-      }
-   }
+    protected final void safeClose(InputStream stream)
+	    throws S3ConnectionException {
+	if (stream == null)
+	    return;
+	try {
+	    stream.close();
+	} catch (Exception e) {
+	    throw new S3ConnectionException("Problems closing input stream", e);
+	}
+    }
 
-   protected final void safeClose(InputStream stream) throws S3ConnectionException {
-      if (stream == null) return;
-      try {
-         stream.close();
-      } catch (Exception e) {
-         throw new S3ConnectionException("Problems closing input stream", e);
-      }
-   }
-
 }
\ No newline at end of file

Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java	2009-05-06 18:18:25 UTC (rev 220)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java	2009-05-06 22:36:05 UTC (rev 221)
@@ -107,7 +107,7 @@
 	try {
 	    org.jclouds.aws.s3.domain.S3Bucket bucket = new org.jclouds.aws.s3.domain.S3Bucket(
 		    bucketName);
-	    s3Service.createBucketIfNotExists(bucket).get(
+	    s3Service.createBucketIfNotExists(bucketName).get(
 		    config.getRequestTimeout(), TimeUnit.MILLISECONDS);
 	    return bucket;
 	} catch (Exception ex) {
@@ -119,10 +119,8 @@
 
     public void destroyBucket(String name) throws S3ConnectionException {
 	try {
-	    org.jclouds.aws.s3.domain.S3Bucket bucket = new org.jclouds.aws.s3.domain.S3Bucket(
-		    name);
-	    context.createS3ObjectMap(bucket).clear();
-	    s3Service.deleteBucket(bucket);
+	    context.createS3ObjectMap(name).clear();
+	    s3Service.deleteBucketIfEmpty(name);
 	} catch (Exception ex) {
 	    throw convertToS3ConnectionException(
 		    "Exception removing s3 bucket " + name, ex);
@@ -130,7 +128,7 @@
     }
 
     Set<String> keysInBucket(S3Bucket bucket) throws S3ConnectionException {
-	return context.createS3ObjectMap(bucket).keySet();
+	return context.createS3ObjectMap(bucket.getName()).keySet();
     }
 
     /**
@@ -141,15 +139,13 @@
 	Set<String> sourceKeys;
 	try {
 	    S3Bucket source = new S3Bucket(sourceBucket);
-	    source = s3Service.getBucket(source).get(
+	    source = s3Service.getBucket(sourceBucket).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(sourceBucket, key, destinationBucket, key).get(
 			    config.getRequestTimeout(), TimeUnit.MILLISECONDS);
 		} catch (Exception ex) {
 		    throw convertToS3ConnectionException(




More information about the infinispan-commits mailing list