Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED3E01094D for ; Fri, 14 Mar 2014 11:16:27 +0000 (UTC) Received: (qmail 49784 invoked by uid 500); 14 Mar 2014 11:16:27 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 49680 invoked by uid 500); 14 Mar 2014 11:16:25 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 49671 invoked by uid 99); 14 Mar 2014 11:16:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Mar 2014 11:16:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Mar 2014 11:16:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A618F238883D; Fri, 14 Mar 2014 11:15:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: chetanm@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140314111558.A618F238883D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 deleteList = new ArrayList(); - 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; + } }