james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/2] james-project git commit: JAMES-1891 Make Spring also use embedded ActiveMQ
Date Thu, 23 Feb 2017 10:00:38 GMT
Repository: james-project
Updated Branches:
  refs/heads/master e25335842 -> 7ac76b489


JAMES-1891 Make Spring also use embedded ActiveMQ


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7ac76b48
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7ac76b48
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7ac76b48

Branch: refs/heads/master
Commit: 7ac76b48988c1f1c48332f2a8eaf391895fa6234
Parents: 27d91f0
Author: Matthieu Baechler <matthieu.baechler@gmail.com>
Authored: Mon Dec 26 18:06:59 2016 +0100
Committer: benwa <btellier@linagora.com>
Committed: Thu Feb 23 17:00:00 2017 +0700

----------------------------------------------------------------------
 .../james/JamesCapabilitiesServerTest.java      |   3 +
 .../modules/server/ActiveMQQueueModule.java     |   5 +
 .../james/modules/server/EmbeddedActiveMQ.java  | 105 ------------------
 .../org/apache/james/MemoryJmapTestRule.java    |   5 +-
 .../james/mailets/TemporaryJamesServer.java     |   3 +
 .../cassandra/cucumber/CassandraStepdefs.java   |   5 +-
 .../jmap/memory/cucumber/MemoryStepdefs.java    |   5 +-
 server/queue/queue-activemq/pom.xml             |   7 +-
 .../activemq/ActiveMQMailQueueFactory.java      |   6 +-
 .../james/queue/activemq/EmbeddedActiveMQ.java  | 107 +++++++++++++++++++
 .../META-INF/spring/activemq-queue-context.xml  |  71 ++----------
 11 files changed, 149 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 150308d..4fc103f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -24,6 +24,8 @@ import static org.mockito.Mockito.when;
 
 import java.util.EnumSet;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
@@ -64,6 +66,7 @@ public class JamesCapabilitiesServerTest {
         
         return new GuiceJamesServerImpl()
             .combineWith(CassandraJamesServerMain.cassandraServerModule)
+            .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
             .overrideWith(new TestElasticSearchModule(embeddedElasticSearch),
                 new TestFilesystemModule(temporaryFolder),
                 new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT),

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
index 1dae37f..1fe7018 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java
@@ -21,7 +21,10 @@ package org.apache.james.modules.server;
 
 import javax.jms.ConnectionFactory;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
 import org.apache.james.queue.activemq.ActiveMQMailQueueFactory;
+import org.apache.james.queue.activemq.EmbeddedActiveMQ;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,6 +40,8 @@ public class ActiveMQQueueModule extends AbstractModule {
     
     @Override
     protected void configure() {
+        bind(PersistenceAdapter.class).to(KahaDBPersistenceAdapter.class);
+        bind(KahaDBPersistenceAdapter.class).in(Scopes.SINGLETON);
         bind(EmbeddedActiveMQ.class).in(Scopes.SINGLETON);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java
deleted file mode 100644
index 51d72db..0000000
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java
+++ /dev/null
@@ -1,105 +0,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.                                           *
- ****************************************************************/
-
-package org.apache.james.modules.server;
-
-import javax.annotation.PreDestroy;
-import javax.jms.ConnectionFactory;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.ActiveMQPrefetchPolicy;
-import org.apache.activemq.blob.BlobTransferPolicy;
-import org.apache.activemq.broker.BrokerPlugin;
-import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.broker.jmx.ManagementContext;
-import org.apache.activemq.plugin.StatisticsBrokerPlugin;
-import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
-import org.apache.james.filesystem.api.FileSystem;
-import org.apache.james.queue.activemq.FileSystemBlobTransferPolicy;
-
-import com.google.common.base.Throwables;
-import com.google.inject.Inject;
-
-public class EmbeddedActiveMQ {
-
-    private final ActiveMQConnectionFactory activeMQConnectionFactory;
-    private BrokerService brokerService;
-
-    @Inject private EmbeddedActiveMQ(FileSystem fileSystem) {
-        try {
-            launchEmbeddedBroker(fileSystem);
-        } catch (Exception e) {
-            throw Throwables.propagate(e);
-        }
-        activeMQConnectionFactory = createActiveMQConnectionFactory(createBlobTransferPolicy(fileSystem));
-    }
-
-    public ConnectionFactory getConnectionFactory() {
-        return activeMQConnectionFactory;
-    }
-
-    @PreDestroy
-    public void stop() throws Exception {
-        brokerService.stop();
-    }
-
-    private ActiveMQConnectionFactory createActiveMQConnectionFactory(BlobTransferPolicy
blobTransferPolicy) {
-        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://james?create=false");
-        connectionFactory.setBlobTransferPolicy(blobTransferPolicy);
-        connectionFactory.setPrefetchPolicy(createActiveMQPrefetchPolicy());
-        return connectionFactory;
-    }
-
-    private ActiveMQPrefetchPolicy createActiveMQPrefetchPolicy() {
-        ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
-        prefetchPolicy.setQueuePrefetch(0);
-        prefetchPolicy.setTopicPrefetch(0);
-        return prefetchPolicy;
-    }
-
-    private BlobTransferPolicy createBlobTransferPolicy(FileSystem fileSystem) {
-        FileSystemBlobTransferPolicy blobTransferPolicy = new FileSystemBlobTransferPolicy();
-        blobTransferPolicy.setDefaultUploadUrl("file://var/store/activemq/blob-transfer");
-        blobTransferPolicy.setFileSystem(fileSystem);
-        return blobTransferPolicy;
-    }
-
-    private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception {
-        brokerService = new BrokerService();
-        brokerService.setBrokerName("james");
-        brokerService.setUseJmx(false);
-        brokerService.setPersistent(true);
-        brokerService.setDataDirectoryFile(fileSystem.getFile("file://var/store/activemq/brokers"));
-        brokerService.setUseShutdownHook(false);
-        brokerService.setSchedulerSupport(false);
-        brokerService.setBrokerId("broker");
-        String[] uris = {"tcp://localhost:0"};
-        brokerService.setTransportConnectorURIs(uris);
-        ManagementContext managementContext = new ManagementContext();
-        managementContext.setCreateConnector(false);
-        brokerService.setManagementContext(managementContext);
-        brokerService.setPersistenceAdapter(new KahaDBPersistenceAdapter());
-        BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()};
-        brokerService.setPlugins(brokerPlugins);
-        String[] transportConnectorsURIs = {"tcp://localhost:0"};
-        brokerService.setTransportConnectorURIs(transportConnectorsURIs);
-        brokerService.start();
-        System.out.println("Started : " + brokerService.isStarted());
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
index fb87792..6d48111 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
@@ -19,6 +19,8 @@
 
 package org.apache.james;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.james.modules.TestFilesystemModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.junit.rules.TemporaryFolder;
@@ -36,7 +38,8 @@ public class MemoryJmapTestRule implements TestRule {
         return new JmapJamesServer()
                 .combineWith(MemoryJamesServerMain.inMemoryServerModule)
                 .overrideWith(new TestFilesystemModule(temporaryFolder),
-                        new TestJMAPServerModule(LIMIT_TO_3_MESSAGES));
+                        new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
+                .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
index 146e4ba..9f7919e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
@@ -26,6 +26,8 @@ import java.io.OutputStream;
 import java.nio.file.Paths;
 import java.util.Arrays;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.JmapJamesServer;
@@ -52,6 +54,7 @@ public class TemporaryJamesServer {
 
         jamesServer = new JmapJamesServer()
             .combineWith(MemoryJamesServerMain.inMemoryServerModule)
+            .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
             .overrideWith(ImmutableList.<Module>builder().addAll(Arrays.asList(additionalModules))
                 .add(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
                 .add(new TemporaryFilesystemModule(temporaryFolder))

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index 79f5cfd..915f40c 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -23,6 +23,8 @@ import java.util.Arrays;
 
 import javax.inject.Inject;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.james.CassandraJamesServerMain;
 import org.apache.james.JmapJamesServer;
 import org.apache.james.backends.cassandra.EmbeddedCassandra;
@@ -59,7 +61,8 @@ public class CassandraStepdefs {
         mainStepdefs.messageIdFactory = new CassandraMessageId.Factory();
         mainStepdefs.jmapServer = new JmapJamesServer()
                 .combineWith(CassandraJamesServerMain.cassandraServerModule)
-                .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch,
cassandra));
+                .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch,
cassandra))
+                .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class));
         mainStepdefs.awaitMethod = () -> embeddedElasticSearch.awaitForElasticSearch();
         mainStepdefs.init();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
index fda8164..fc13c55 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
@@ -21,6 +21,8 @@ package org.apache.james.jmap.memory.cucumber;
 
 import javax.inject.Inject;
 
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.james.JmapJamesServer;
 import org.apache.james.MemoryJamesServerMain;
 import org.apache.james.jmap.methods.integration.cucumber.MainStepdefs;
@@ -52,7 +54,8 @@ public class MemoryStepdefs {
         mainStepdefs.jmapServer = new JmapJamesServer()
                 .combineWith(MemoryJamesServerMain.inMemoryServerModule)
                 .overrideWith(new MemoryJmapServerModule(temporaryFolder),
-                		(binder) -> binder.bind(MessageId.Factory.class).toInstance(mainStepdefs.messageIdFactory));
+                		(binder) -> binder.bind(MessageId.Factory.class).toInstance(mainStepdefs.messageIdFactory))
+                .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class));
         mainStepdefs.init();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/queue/queue-activemq/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/pom.xml b/server/queue/queue-activemq/pom.xml
index a6c164c..978e5bf 100644
--- a/server/queue/queue-activemq/pom.xml
+++ b/server/queue/queue-activemq/pom.xml
@@ -61,7 +61,12 @@
           <groupId>org.apache.activemq</groupId>
           <artifactId>activemq-kahadb-store</artifactId>
           <version>${activemq.version}</version>
-	</dependency>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.activemq</groupId>
+          <artifactId>activemq-spring</artifactId>
+          <version>${activemq.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jms</artifactId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
index 430222e..9646a29 100644
--- a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/ActiveMQMailQueueFactory.java
@@ -35,11 +35,15 @@ public class ActiveMQMailQueueFactory extends JMSMailQueueFactory {
 
     private boolean useBlob = true;
 
-    @Inject
     public ActiveMQMailQueueFactory(ConnectionFactory connectionFactory, MailQueueItemDecoratorFactory
mailQueueItemDecoratorFactory, MetricFactory metricFactory) {
         super(connectionFactory, mailQueueItemDecoratorFactory, metricFactory);
     }
 
+    @Inject
+    public ActiveMQMailQueueFactory(EmbeddedActiveMQ embeddedActiveMQ, MailQueueItemDecoratorFactory
mailQueueItemDecoratorFactory, MetricFactory metricFactory) {
+        this(embeddedActiveMQ.getConnectionFactory(), mailQueueItemDecoratorFactory, metricFactory);
+    }
+
     public void setUseBlobMessages(boolean useBlob) {
         this.useBlob = useBlob;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/EmbeddedActiveMQ.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/EmbeddedActiveMQ.java
b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/EmbeddedActiveMQ.java
new file mode 100644
index 0000000..f62108a
--- /dev/null
+++ b/server/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/EmbeddedActiveMQ.java
@@ -0,0 +1,107 @@
+/****************************************************************
+ * 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.queue.activemq;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQPrefetchPolicy;
+import org.apache.activemq.blob.BlobTransferPolicy;
+import org.apache.activemq.broker.BrokerPlugin;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.ManagementContext;
+import org.apache.activemq.plugin.StatisticsBrokerPlugin;
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.james.filesystem.api.FileSystem;
+
+import com.google.common.base.Throwables;
+
+public class EmbeddedActiveMQ {
+
+    private final ActiveMQConnectionFactory activeMQConnectionFactory;
+    private final PersistenceAdapter persistenceAdapter;
+    private BrokerService brokerService;
+
+    @Inject
+        private EmbeddedActiveMQ(FileSystem fileSystem, PersistenceAdapter persistenceAdapter)
{
+        this.persistenceAdapter = persistenceAdapter;
+        try {
+            launchEmbeddedBroker(fileSystem);
+        } catch (Exception e) {
+            throw Throwables.propagate(e);
+        }
+        activeMQConnectionFactory = createActiveMQConnectionFactory(createBlobTransferPolicy(fileSystem));
+    }
+
+    public ConnectionFactory getConnectionFactory() {
+        return activeMQConnectionFactory;
+    }
+
+    @PreDestroy
+    public void stop() throws Exception {
+        brokerService.stop();
+    }
+
+    private ActiveMQConnectionFactory createActiveMQConnectionFactory(BlobTransferPolicy
blobTransferPolicy) {
+        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://james?create=false");
+        connectionFactory.setBlobTransferPolicy(blobTransferPolicy);
+        connectionFactory.setPrefetchPolicy(createActiveMQPrefetchPolicy());
+        return connectionFactory;
+    }
+
+    private ActiveMQPrefetchPolicy createActiveMQPrefetchPolicy() {
+        ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
+        prefetchPolicy.setQueuePrefetch(0);
+        prefetchPolicy.setTopicPrefetch(0);
+        return prefetchPolicy;
+    }
+
+    private BlobTransferPolicy createBlobTransferPolicy(FileSystem fileSystem) {
+        FileSystemBlobTransferPolicy blobTransferPolicy = new FileSystemBlobTransferPolicy();
+        blobTransferPolicy.setDefaultUploadUrl("file://var/store/activemq/blob-transfer");
+        blobTransferPolicy.setFileSystem(fileSystem);
+        return blobTransferPolicy;
+    }
+
+    private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception {
+        brokerService = new BrokerService();
+        brokerService.setBrokerName("james");
+        brokerService.setUseJmx(false);
+        brokerService.setPersistent(true);
+        brokerService.setDataDirectoryFile(fileSystem.getFile("file://var/store/activemq/brokers"));
+        brokerService.setUseShutdownHook(false);
+        brokerService.setSchedulerSupport(false);
+        brokerService.setBrokerId("broker");
+        String[] uris = {"tcp://localhost:0"};
+        brokerService.setTransportConnectorURIs(uris);
+        ManagementContext managementContext = new ManagementContext();
+        managementContext.setCreateConnector(false);
+        brokerService.setManagementContext(managementContext);
+        brokerService.setPersistenceAdapter(persistenceAdapter);
+        BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()};
+        brokerService.setPlugins(brokerPlugins);
+        String[] transportConnectorsURIs = {"tcp://localhost:0"};
+        brokerService.setTransportConnectorURIs(transportConnectorsURIs);
+        brokerService.start();
+        System.out.println("Started : " + brokerService.isStarted());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac76b48/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
index 3903250..5f5f086 100644
--- a/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
+++ b/server/queue/queue-activemq/src/main/resources/META-INF/spring/activemq-queue-context.xml
@@ -17,77 +17,22 @@
 
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:amq="http://activemq.apache.org/schema/core"
-       xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
-         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-         http://activemq.apache.org/schema/core
-         http://activemq.apache.org/schema/core/activemq-core.xsd
-         http://www.springframework.org/schema/util
-         http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
     <!-- James Mail Queue Factory -->
-    <bean id="mailqueuefactory" class="org.apache.james.queue.activemq.ActiveMQMailQueueFactory"
depends-on="broker">
-        <constructor-arg index="0" ref="jmsConnectionFactory"/>
+    <bean id="mailqueuefactory" class="org.apache.james.queue.activemq.ActiveMQMailQueueFactory">
+        <constructor-arg index="0" ref="embeddedActiveMQ"/>
         <constructor-arg index="1" ref="rawMailQueueItemDecoratorFactory"/>
         <constructor-arg index="2" ref="metricFactory"/>
     </bean>
 
-    <!-- 
-      ActiveMQ Broker, Connections, Blob
-     -->
-    <amq:broker useJmx="true" persistent="true" brokerName="james"
-                dataDirectory="filesystem=file://var/store/activemq/brokers"
-                useShutdownHook="false" schedulerSupport="false" id="broker">
-        <amq:destinationPolicy>
-            <amq:policyMap>
-                <amq:policyEntries>
-                    <!-- Support priority handling of messages -->
-                    <!-- http://activemq.apache.org/how-can-i-support-priority-queues.html
-->
-                    <amq:policyEntry queue=">" prioritizedMessages="true"/>
-                </amq:policyEntries>
-            </amq:policyMap>
-        </amq:destinationPolicy>
-        <amq:managementContext>
-            <amq:managementContext createConnector="false"/>
-        </amq:managementContext>
-        <amq:persistenceAdapter>
-            <amq:kahaDB/>
-        </amq:persistenceAdapter>
-        <amq:plugins>
-            <amq:statisticsBrokerPlugin/>
-        </amq:plugins>
-        <amq:transportConnectors>
-            <amq:transportConnector uri="tcp://localhost:0"/>
-        </amq:transportConnectors>
-    </amq:broker>
+    <bean id="rawMailQueueItemDecoratorFactory" class="org.apache.james.queue.api.RawMailQueueItemDecoratorFactory"/>
 
-    <amq:connectionFactory id="amqConnectionFactory" brokerURL="vm://james?create=false">
-        <amq:prefetchPolicy>
-            <!-- Disable prefetch so slow consuming can not block other threads -->
-            <!-- See JAMES-1253 -->
-            <amq:prefetchPolicy queuePrefetch="0" topicPrefetch="0"/>
-        </amq:prefetchPolicy>
-        <property name="blobTransferPolicy" ref="blobTransferPolicy"/>
-    </amq:connectionFactory>
-
-    <bean id="blobTransferPolicy" class="org.apache.james.queue.activemq.FileSystemBlobTransferPolicy"
-          autowire="byName">
-        <property name="defaultUploadUrl" value="file://var/store/activemq/blob-transfer"/>
-    </bean>
-
-    <bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
-        <property name="targetConnectionFactory" ref="amqConnectionFactory"/>
-        <property name="sessionCacheSize" value="10"/>
-        <property name="cacheConsumers" value="false"/>
-        <property name="cacheProducers" value="true"/>
-    </bean>
-
-    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
-        <property name="connectionFactory" ref="jmsConnectionFactory"/>
-    </bean>
-
-    <bean id="rawMailQueueItemDecoratorFactory" class="org.apache.james.queue.api.RawMailQueueItemDecoratorFactory">
+    <bean id="embeddedActiveMQ" class="org.apache.james.queue.activemq.EmbeddedActiveMQ">
+        <constructor-arg index="0" ref="filesystem"/>
+        <constructor-arg index="1" ref="persistenceAdapter"/>
     </bean>
 
+    <bean id="persistenceAdapter" class="org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter"/>
 </beans>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message