jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1577481 - in /jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds: S3Backend.java S3DataStore.java
Date Fri, 14 Mar 2014 11:15:58 GMT
Author: chetanm
Date: Fri Mar 14 11:15:58 2014
New Revision: 1577481

URL: http://svn.apache.org/r1577481
Log:
JCR-3748 - Allow configuring S3Backend programatically

As CachingDataStore invokes init directly its not possible to use the other init method. Added
another way where clients can provide the required properties while creating S3DataStore

Modified:
    jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3DataStore.java

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java?rev=1577481&r1=1577480&r2=1577481&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
Fri Mar 14 11:15:58 2014
@@ -96,7 +96,7 @@ public class S3Backend implements Backen
 
     private CachingDataStore store;
 
-    private Properties prop;
+    private Properties properties;
 
     private Date startTime;
 
@@ -107,17 +107,22 @@ public class S3Backend implements Backen
     @Override
     public void init(CachingDataStore store, String homeDir, String config)
             throws DataStoreException {
-        if (config == null) {
+        Properties initProps = null;
+        //Check is configuration is already provided. That takes precedence
+        //over config provided via file based config
+        if(this.properties != null){
+            initProps = this.properties;
+        } else if (config == null) {
             config = Utils.DEFAULT_CONFIG_FILE;
+            try{
+                initProps = Utils.readConfig(config);
+            }catch(IOException e){
+                throw new DataStoreException("Could not initialize S3 from "
+                        + config, e);
+            }
+            this.properties = initProps;
         }
-        Properties properties = null;
-        try{
-            properties = Utils.readConfig(config);
-        }catch(IOException e){
-            throw new DataStoreException("Could not initialize S3 from "
-                    + config, e);
-        }
-        init(store, homeDir, properties);
+        init(store, homeDir, initProps);
     }
 
     public void init(CachingDataStore store, String homeDir, Properties prop)
@@ -128,7 +133,6 @@ public class S3Backend implements Backen
             startTime = new Date();
             Thread.currentThread().setContextClassLoader(
                 getClass().getClassLoader());
-            this.prop = prop;
             if (LOG.isDebugEnabled()) {
                 LOG.debug("init");
             }
@@ -548,6 +552,16 @@ public class S3Backend implements Backen
         this.bucket = bucket;
     }
 
+    /**
+     * Properties used to configure the backend. If provided explicitly
+     * before init is invoked then these take precedence
+     *
+     * @param properties  to configure S3Backend
+     */
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+
     private void write(DataIdentifier identifier, File file,
             boolean asyncUpload, AsyncUploadCallback callback)
             throws DataStoreException {
@@ -650,7 +664,7 @@ public class S3Backend implements Backen
             ObjectListing prevObjectListing = s3service.listObjects(bucket,
                 KEY_PREFIX);
             List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
-            int nThreads = Integer.parseInt(prop.getProperty("maxConnections"));
+            int nThreads = Integer.parseInt(properties.getProperty("maxConnections"));
             ExecutorService executor = Executors.newFixedThreadPool(nThreads,
                 new NamedThreadFactory("s3-object-rename-worker"));
             boolean taskAdded = false;

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3DataStore.java?rev=1577481&r1=1577480&r2=1577481&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3DataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3DataStore.java
Fri Mar 14 11:15:58 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.util.Properties;
+
 import org.apache.jackrabbit.core.data.Backend;
 import org.apache.jackrabbit.core.data.CachingDataStore;
 
@@ -23,10 +25,15 @@ import org.apache.jackrabbit.core.data.C
  * An Amazon S3 data store.
  */
 public class S3DataStore extends CachingDataStore {
+    private Properties properties;
 
     @Override
     protected Backend createBackend() {
-        return new S3Backend();
+        S3Backend backend = new S3Backend();
+        if(properties != null){
+            backend.setProperties(properties);
+        }
+        return backend;
     }
 
     @Override
@@ -34,4 +41,10 @@ public class S3DataStore extends Caching
         return "s3.init.done";
     }
 
+    /**
+     * Properties required to configure the S3Backend
+     */
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
 }



Mime
View raw message