[infinispan-commits] Infinispan SVN: r213 - in trunk/cachestore/s3: src/main/java/org/infinispan/loaders/s3/jclouds and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue May 5 16:20:47 EDT 2009
Author: adriancole
Date: 2009-05-05 16:20:47 -0400 (Tue, 05 May 2009)
New Revision: 213
Added:
trunk/cachestore/s3/src/test/resources/
trunk/cachestore/s3/src/test/resources/log4j.xml
Modified:
trunk/cachestore/s3/pom.xml
trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java
Log:
updated with log4j compability
Modified: trunk/cachestore/s3/pom.xml
===================================================================
--- trunk/cachestore/s3/pom.xml 2009-05-05 17:26:13 UTC (rev 212)
+++ trunk/cachestore/s3/pom.xml 2009-05-05 20:20:47 UTC (rev 213)
@@ -36,16 +36,36 @@
<dependency>
<groupId>org.jclouds</groupId>
+ <artifactId>jclouds-s3</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jclouds</groupId>
<artifactId>jclouds-s3nio</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.jclouds</groupId>
+ <artifactId>jclouds-log4j</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<repositories>
<repository>
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-05 17:26:13 UTC (rev 212)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loaders/s3/jclouds/JCloudsConnection.java 2009-05-05 20:20:47 UTC (rev 213)
@@ -1,6 +1,5 @@
package org.infinispan.loaders.s3.jclouds;
-import static com.google.common.base.Preconditions.checkNotNull;
import org.infinispan.loaders.s3.S3CacheStoreConfig;
import org.infinispan.loaders.s3.S3Connection;
import org.infinispan.loaders.s3.S3ConnectionException;
@@ -11,129 +10,170 @@
import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.nio.config.S3HttpNioConnectionPoolClientModule;
+import org.jclouds.logging.jdk.config.JDKLoggingModule;
+import org.jclouds.logging.log4j.config.Log4JLoggingModule;
+import com.google.inject.Module;
+
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.
- *
+ * An JClouds implementation of {@link S3Connection}. This implementation uses
+ * the threadsafe {@link S3HttpNioConnectionPoolClientModule} transport.
+ *
* @author Adrian Cole
* @link http://code.google.com/p/jclouds
*/
-public class JCloudsConnection implements S3Connection<org.jclouds.aws.s3.S3Connection, org.jclouds.aws.s3.domain.S3Bucket> {
- protected org.jclouds.aws.s3.S3Connection s3Service;
- protected S3Context context;
- protected Marshaller marshaller;
- protected S3CacheStoreConfig config;
+public class JCloudsConnection
+ implements
+ S3Connection<org.jclouds.aws.s3.S3Connection, org.jclouds.aws.s3.domain.S3Bucket> {
+ 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.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.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID, checkNotNull(config.getAwsAccessKey(), "config.getAwsAccessKey()"));
- if (!properties.containsKey(S3Constants.PROPERTY_AWS_SECRETACCESSKEY))
- properties.setProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(config.getAwsSecretKey(), "config.getAwsSecretKey()"));
- if (!properties.containsKey(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS))
- properties.setProperty(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS, config.getMaxConnections() + "");
- //TODO proxy host/port
- this.context = S3ContextFactory.createS3Context(properties, new S3HttpNioConnectionPoolClientModule());
- this.s3Service = context.getConnection();
- if (this.s3Service == null) {
- throw new S3ConnectionException("Could not connect");
- }
+ /**
+ * {@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.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.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID,
+ checkNotNull(config.getAwsAccessKey(),
+ "config.getAwsAccessKey()"));
+ if (!properties
+ .containsKey(S3Constants.PROPERTY_AWS_SECRETACCESSKEY))
+ properties.setProperty(
+ S3Constants.PROPERTY_AWS_SECRETACCESSKEY, checkNotNull(
+ config.getAwsSecretKey(),
+ "config.getAwsSecretKey()"));
+ if (!properties
+ .containsKey(S3Constants.PROPERTY_POOL_MAX_CONNECTIONS))
+ properties.setProperty(
+ S3Constants.PROPERTY_POOL_MAX_CONNECTIONS, config
+ .getMaxConnections()
+ + "");
+ // TODO proxy host/port
+ Module loggingModule = org.infinispan.logging.LogFactory.IS_LOG4J_AVAILABLE ? new Log4JLoggingModule()
+ : new JDKLoggingModule();
+ this.context = S3ContextFactory.createS3Context(properties,
+ new S3HttpNioConnectionPoolClientModule(), loggingModule);
+ this.s3Service = context.getConnection();
+ if (this.s3Service == null) {
+ throw new S3ConnectionException("Could not connect");
+ }
- } catch (Exception ex) {
- throw convertToS3ConnectionException("Exception connecting to s3", ex);
- }
- this.marshaller = m;
- }
+ } catch (Exception ex) {
+ throw convertToS3ConnectionException("Exception connecting to s3",
+ ex);
+ }
+ this.marshaller = m;
+ }
- public org.jclouds.aws.s3.S3Connection getConnection() throws S3ConnectionException {
- return s3Service;
- }
+ public org.jclouds.aws.s3.S3Connection getConnection()
+ throws S3ConnectionException {
+ return s3Service;
+ }
- /**
- * @see
- */
- 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(config.getRequestTimeout(), TimeUnit.MILLISECONDS);
- return bucket;
- } catch (Exception ex) {
- throw convertToS3ConnectionException("Exception retrieving or creating s3 bucket " + bucketName, ex);
- }
- }
+ /**
+ * @see
+ */
+ 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(
+ config.getRequestTimeout(), TimeUnit.MILLISECONDS);
+ return bucket;
+ } catch (Exception ex) {
+ throw convertToS3ConnectionException(
+ "Exception retrieving or creating s3 bucket " + bucketName,
+ ex);
+ }
+ }
- 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);
- } catch (Exception ex) {
- throw convertToS3ConnectionException("Exception removing s3 bucket " + name, ex);
- }
- }
+ 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);
+ } catch (Exception ex) {
+ throw convertToS3ConnectionException(
+ "Exception removing s3 bucket " + name, ex);
+ }
+ }
+ Set<String> keysInBucket(S3Bucket bucket) throws S3ConnectionException {
+ return context.createS3ObjectMap(bucket).keySet();
+ }
- Set<String> keysInBucket(S3Bucket bucket) throws S3ConnectionException {
- return context.createS3ObjectMap(bucket).keySet();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void copyBucket(String sourceBucket, String destinationBucket)
+ throws S3ConnectionException {
+ Set<String> sourceKeys;
+ try {
+ S3Bucket source = new S3Bucket(sourceBucket);
+ source = s3Service.getBucket(source).get(
+ config.getRequestTimeout(), TimeUnit.MILLISECONDS);
+ sourceKeys = keysInBucket(source);
+ S3Bucket dest = new S3Bucket(destinationBucket);
- /**
- * {@inheritDoc}
- */
- public void copyBucket(String sourceBucket, String destinationBucket) throws S3ConnectionException {
- Set<String> sourceKeys;
- try {
- S3Bucket source = new S3Bucket(sourceBucket);
- 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(
+ config.getRequestTimeout(), TimeUnit.MILLISECONDS);
+ } catch (Exception ex) {
+ throw convertToS3ConnectionException(
+ "Exception while copying key " + key
+ + " from bucket " + sourceBucket, ex);
+ }
+ }
+ } catch (Exception ex) {
+ throw convertToS3ConnectionException("Cannot access bucket "
+ + sourceBucket, ex);
+ }
- for (String key : sourceKeys) {
- try {
- S3Object object = new S3Object(key);
- 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);
- }
- }
- } catch (Exception ex) {
- throw convertToS3ConnectionException("Cannot access bucket " + sourceBucket, ex);
- }
+ }
- }
+ /**
+ * @see S3Context#close
+ */
+ public void disconnect() {
+ context.close();
+ }
- /**
- * @see S3Context#close
- */
- public void disconnect() {
- context.close();
- }
-
- S3ConnectionException convertToS3ConnectionException(String message, Exception caught) {
- return (caught instanceof S3ConnectionException) ? (S3ConnectionException) caught :
- new S3ConnectionException(message, caught);
- }
+ S3ConnectionException convertToS3ConnectionException(String message,
+ Exception caught) {
+ return (caught instanceof S3ConnectionException) ? (S3ConnectionException) caught
+ : new S3ConnectionException(message, caught);
+ }
}
Added: trunk/cachestore/s3/src/test/resources/log4j.xml
===================================================================
--- trunk/cachestore/s3/src/test/resources/log4j.xml (rev 0)
+++ trunk/cachestore/s3/src/test/resources/log4j.xml 2009-05-05 20:20:47 UTC (rev 213)
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!--
+ For more configuration infromation and examples see the Apache Log4j website: http://logging.apache.org/log4j/
+ -->
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- A time/date based rolling appender -->
+ <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
+ <param name="File" value="target/test-data/infinispan.log"/>
+ <param name="Append" value="false"/>
+
+ <!-- Rollover at midnight each day -->
+ <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+ <!-- Rollover at the top of each hour
+ <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+ -->
+ <param name="Threshold" value="TRACE"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
+
+ <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+ <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+ -->
+ </layout>
+ </appender>
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Threshold" value="TRACE"/>
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c{1}] (%t) %m%n"/>
+ </layout>
+ </appender>
+
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <category name="org.jclouds">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.infinispan">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.infinispan.profiling">
+ <priority value="WARN"/>
+ </category>
+
+ <category name="org.infinispan.jmx">
+ <priority value="WARN"/>
+ </category>
+
+ <category name="org.infinispan.factories">
+ <priority value="WARN"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <priority value="WARN"/>
+ <!--<appender-ref ref="CONSOLE"/>-->
+ <appender-ref ref="FILE"/>
+ </root>
+
+</log4j:configuration>
More information about the infinispan-commits
mailing list