Author: matthieu
Date: Tue Nov 3 16:51:16 2015
New Revision: 1712342
URL: http://svn.apache.org/viewvc?rev=1712342&view=rev
Log:
JAMES-1626 use Filesystem to resolve configuration properties files
Modified:
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
Modified:
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java?rev=1712342&r1=1712341&r2=1712342&view=diff
==============================================================================
---
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
(original)
+++
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
Tue Nov 3 16:51:16 2015
@@ -18,35 +18,28 @@
****************************************************************/
package org.apache.james.modules.mailbox;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
-
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.google.inject.AbstractModule;
-
+import java.io.FileNotFoundException;
import java.util.Set;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.james.backends.cassandra.components.CassandraModule;
import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
import org.apache.james.backends.cassandra.init.ClusterFactory;
import
org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory;
import
org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
-import org.apache.james.utils.PropertiesReader;
+import org.apache.james.filesystem.api.FileSystem;
-public class CassandraSessionModule extends AbstractModule {
-
- private final PropertiesReader propertiesReader;
- private final String keyspace;
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
- public CassandraSessionModule() {
- propertiesReader = new PropertiesReader("cassandra.properties");
- keyspace = propertiesReader.getProperty("cassandra.keyspace");
- }
+public class CassandraSessionModule extends AbstractModule {
@Override
protected void configure() {
-
}
@Provides
@@ -57,19 +50,28 @@ public class CassandraSessionModule exte
@Provides
@Singleton
- Session provideSession(Cluster cluster, CassandraModule cassandraModule) {
+ Session provideSession(FileSystem fileSystem, Cluster cluster,
CassandraModule cassandraModule)
+ throws FileNotFoundException, ConfigurationException{
+ PropertiesConfiguration configuration = getConfiguration(fileSystem);
+ String keyspace = configuration.getString("cassandra.keyspace");
return new
SessionWithInitializedTablesFactory(cassandraModule).createSession(cluster,
keyspace);
}
@Provides
@Singleton
- Cluster provideCluster() {
+ Cluster provideCluster(FileSystem fileSystem) throws
FileNotFoundException, ConfigurationException {
+ PropertiesConfiguration configuration = getConfiguration(fileSystem);
+
return
ClusterWithKeyspaceCreatedFactory.clusterWithInitializedKeyspace(
ClusterFactory.createClusterForSingleServerWithoutPassWord(
- propertiesReader.getProperty("cassandra.ip"),
-
Integer.parseInt(propertiesReader.getProperty("cassandra.port"))),
- keyspace,
-
Integer.parseInt(propertiesReader.getProperty("cassandra.replication.factor")));
+ configuration.getString("cassandra.ip"),
+ configuration.getInt("cassandra.port")),
+ configuration.getString("cassandra.keyspace"),
+ configuration.getInt("cassandra.replication.factor"));
}
+ private PropertiesConfiguration getConfiguration(FileSystem fileSystem)
throws FileNotFoundException, ConfigurationException {
+ return new
PropertiesConfiguration(fileSystem.getFile("cassandra.properties"));
+ }
+
}
\ No newline at end of file
Modified:
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java?rev=1712342&r1=1712341&r2=1712342&view=diff
==============================================================================
---
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
(original)
+++
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
Tue Nov 3 16:51:16 2015
@@ -19,18 +19,26 @@
package org.apache.james.modules.mailbox;
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.TypeLiteral;
+import java.io.FileNotFoundException;
+
+import javax.inject.Singleton;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.mailbox.cassandra.CassandraId;
-import org.apache.james.mailbox.elasticsearch.*;
+import org.apache.james.mailbox.elasticsearch.ClientProvider;
+import org.apache.james.mailbox.elasticsearch.ClientProviderImpl;
+import org.apache.james.mailbox.elasticsearch.IndexCreationFactory;
+import org.apache.james.mailbox.elasticsearch.NodeMappingFactory;
import
org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
import org.apache.james.mailbox.store.extractor.TextExtractor;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
import org.apache.james.mailbox.tika.extractor.TikaTextExtractor;
-import org.apache.james.utils.PropertiesReader;
-import javax.inject.Singleton;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.TypeLiteral;
public class ElasticSearchMailboxModule extends AbstractModule {
@@ -44,13 +52,13 @@ public class ElasticSearchMailboxModule
@Provides
@Singleton
- protected ClientProvider provideClientProvider() {
- PropertiesReader propertiesReader = new
PropertiesReader("elasticsearch.properties");
- ClientProvider clientProvider = new
ClientProviderImpl(propertiesReader.getProperty("elasticsearch.masterHost"),
-
Integer.parseInt(propertiesReader.getProperty("elasticsearch.port")));
+ protected ClientProvider provideClientProvider(FileSystem fileSystem)
throws ConfigurationException, FileNotFoundException {
+ PropertiesConfiguration propertiesReader = new
PropertiesConfiguration(fileSystem.getFile("elasticsearch.properties"));
+ ClientProvider clientProvider = new
ClientProviderImpl(propertiesReader.getString("elasticsearch.masterHost"),
+ propertiesReader.getInt("elasticsearch.port"));
IndexCreationFactory.createIndex(clientProvider,
-
Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.shards")),
-
Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.replica")));
+ propertiesReader.getInt("elasticsearch.nb.shards"),
+ propertiesReader.getInt("elasticsearch.nb.replica"));
NodeMappingFactory.applyMapping(clientProvider);
return clientProvider;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]