Author: btellier
Date: Mon Jun 29 08:51:55 2015
New Revision: 1688154

URL: http://svn.apache.org/r1688154
Log:
MAILBOX-155 Add indexer configuration - contributed by Antoine Duprat

Added:
    james/server/trunk/app/src/main/resources/elasticsearch-template.properties
    james/server/trunk/app/src/main/resources/indexer-template.xml
    
james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/IndexerConfigurationBeanFactoryPostProcessor.java
Modified:
    
james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml

Added: 
james/server/trunk/app/src/main/resources/elasticsearch-template.properties
URL: 
http://svn.apache.org/viewvc/james/server/trunk/app/src/main/resources/elasticsearch-template.properties?rev=1688154&view=auto
==============================================================================
--- james/server/trunk/app/src/main/resources/elasticsearch-template.properties 
(added)
+++ james/server/trunk/app/src/main/resources/elasticsearch-template.properties 
Mon Jun 29 08:51:55 2015
@@ -0,0 +1,24 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+#  This template file can be used as example for James Server configuration
+#  DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+
+# Configuration file for ElasticSearch
+
+elasticsearch.clusterName=elasticsearch
+elasticsearch.masterHost=127.0.0.1

Added: james/server/trunk/app/src/main/resources/indexer-template.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/app/src/main/resources/indexer-template.xml?rev=1688154&view=auto
==============================================================================
--- james/server/trunk/app/src/main/resources/indexer-template.xml (added)
+++ james/server/trunk/app/src/main/resources/indexer-template.xml Mon Jun 29 
08:51:55 2015
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one   
+  or more contributor license agreements.  See the NOTICE file 
+  distributed with this work for additional information        
+  regarding copyright ownership.  The ASF licenses this file   
+  to you under the Apache License, Version 2.0 (the            
+  "License"); you may not use this file except in compliance   
+  with the License.  You may obtain a copy of the License at   
+                                                               
+    http://www.apache.org/licenses/LICENSE-2.0                 
+                                                               
+  Unless required by applicable law or agreed to in writing,   
+  software distributed under the License is distributed on an  
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       
+  KIND, either express or implied.  See the License for the    
+  specific language governing permissions and limitations      
+  under the License.                                           
+ -->
+ 
+<!--
+   This template file can be used as example for James Server configuration
+   DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+-->
+ 
+<!-- See http://james.apache.org/server/3/config.html for usage -->
+ 
+<indexer>
+   <!-- supported providers are: -->
+   <!-- lazyIndex, elasticsearch -->
+   <!--  -->
+  <provider>lazyIndex</provider>
+</indexer>

Added: 
james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/IndexerConfigurationBeanFactoryPostProcessor.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/IndexerConfigurationBeanFactoryPostProcessor.java?rev=1688154&view=auto
==============================================================================
--- 
james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/IndexerConfigurationBeanFactoryPostProcessor.java
 (added)
+++ 
james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/IndexerConfigurationBeanFactoryPostProcessor.java
 Mon Jun 29 08:51:55 2015
@@ -0,0 +1,68 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.container.spring.bean.factorypostprocessor;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.container.spring.lifecycle.ConfigurationProvider;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+
+/**
+ * Read indexer.xml file and register the right bean alias in the
+ * {@link BeanDefinitionRegistry} depending on the configured provider. As
+ * default jpa is used!
+ * 
+ * It will register it with the alias mailboxmanager
+ */
+public class IndexerConfigurationBeanFactoryPostProcessor implements 
BeanFactoryPostProcessor {
+
+    /**
+     * @see 
org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory
+     * 
(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+     */
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory 
beanFactory) throws BeansException {
+        ConfigurationProvider confProvider = 
beanFactory.getBean(ConfigurationProvider.class);
+        try {
+            HierarchicalConfiguration config = 
confProvider.getConfiguration("indexer");
+            String provider = config.getString("provider", "lazyIndex");
+
+            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) 
beanFactory;
+            String indexer = null;
+            if (provider.equalsIgnoreCase("lazyIndex")) {
+                indexer = "lazyIndex";
+            } else if (provider.equalsIgnoreCase("elasticsearch")) {
+                indexer = "elasticsearch-listener";
+            }
+
+            if (indexer == null)
+                throw new ConfigurationException("Indexer provider " + 
provider + " not supported!");
+            registry.registerAlias(indexer, "indexer");
+
+        } catch (ConfigurationException e) {
+            throw new FatalBeanException("Unable to config the indexer", e);
+        }
+
+    }
+
+}

Modified: 
james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml?rev=1688154&r1=1688153&r2=1688154&view=diff
==============================================================================
--- 
james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
 (original)
+++ 
james/server/trunk/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
 Mon Jun 29 08:51:55 2015
@@ -98,6 +98,14 @@
 
     <!--
     ===========================================================================
+       Indexer
+    ===========================================================================
+    -->
+
+    <bean 
class="org.apache.james.container.spring.bean.factorypostprocessor.IndexerConfigurationBeanFactoryPostProcessor"/>
+
+    <!--
+    ===========================================================================
        Mailbox
     ===========================================================================
     -->



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to