This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit be2ea2efe6f033bc6f411717ba11cc8ee789325a Author: Benoit Tellier <[email protected]> AuthorDate: Fri Mar 15 14:20:09 2019 +0700 JAMES-2687 Use InMemoryIntegrationResources for MPT search host systems --- .../host/ElasticSearchHostSystem.java | 83 +++++++--------------- mpt/impl/imap-mailbox/lucenesearch/pom.xml | 5 ++ .../lucenesearch/host/LuceneSearchHostSystem.java | 59 +++++---------- 3 files changed, 46 insertions(+), 101 deletions(-) diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java index 7dd9141..eafd2dc 100644 --- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java +++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java @@ -38,8 +38,6 @@ import org.apache.james.imap.encode.main.DefaultImapEncoderFactory; import org.apache.james.imap.main.DefaultImapDecoderFactory; import org.apache.james.imap.processor.main.DefaultImapProcessorFactory; import org.apache.james.mailbox.MailboxManager; -import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; -import org.apache.james.mailbox.acl.UnionMailboxACLResolver; import org.apache.james.mailbox.elasticsearch.IndexAttachments; import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants; import org.apache.james.mailbox.elasticsearch.MailboxIndexCreationUtil; @@ -48,26 +46,13 @@ import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson; import org.apache.james.mailbox.elasticsearch.query.CriterionConverter; import org.apache.james.mailbox.elasticsearch.query.QueryConverter; import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher; -import org.apache.james.mailbox.events.InVMEventBus; -import org.apache.james.mailbox.events.delivery.InVmEventDelivery; -import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.inmemory.InMemoryId; -import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; -import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory; import org.apache.james.mailbox.inmemory.InMemoryMessageId; -import org.apache.james.mailbox.store.JVMMailboxPathLocker; -import org.apache.james.mailbox.store.PreDeletionHooks; -import org.apache.james.mailbox.store.SessionProvider; -import org.apache.james.mailbox.store.StoreMailboxAnnotationManager; +import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.mailbox.store.StoreMailboxManager; -import org.apache.james.mailbox.store.StoreRightManager; import org.apache.james.mailbox.store.StoreSubscriptionManager; import org.apache.james.mailbox.store.extractor.DefaultTextExtractor; -import org.apache.james.mailbox.store.mail.model.impl.MessageParser; -import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver; import org.apache.james.mailbox.store.quota.NoQuotaManager; -import org.apache.james.mailbox.store.quota.QuotaComponents; -import org.apache.james.metrics.api.NoopMetricFactory; import org.apache.james.metrics.logger.DefaultMetricFactory; import org.apache.james.mpt.api.ImapFeatures; import org.apache.james.mpt.api.ImapFeatures.Feature; @@ -100,58 +85,38 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem { FileUtils.deleteDirectory(tempDirectory.toFile()); } - private void initFields() throws MailboxException { + private void initFields() { Client client = MailboxIndexCreationUtil.prepareDefaultClient( new TestingClientProvider(embeddedElasticSearch.getNode()).get(), - ElasticSearchConfiguration.DEFAULT_CONFIGURATION); - + ElasticSearchConfiguration.DEFAULT_CONFIGURATION); InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory(); - - InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory(); - InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory())); - StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), eventBus); - StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager); - - SessionProvider sessionProvider = new SessionProvider(authenticator, authorizator); - QuotaComponents quotaComponents = QuotaComponents.disabled(sessionProvider, mailboxSessionMapperFactory); - - ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass()); - ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex( - mailboxSessionMapperFactory, - new ElasticSearchIndexer(client, - Executors.newSingleThreadExecutor(threadFactory), - MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS, - MailboxElasticSearchConstants.MESSAGE_TYPE), - new ElasticSearchSearcher(client, - new QueryConverter(new CriterionConverter()), - ElasticSearchSearcher.DEFAULT_SEARCH_SIZE, - new InMemoryId.Factory(), messageIdFactory, - MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE), - new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES), - new SessionProvider(authenticator, authorizator)); - - mailboxManager = new InMemoryMailboxManager( - mailboxSessionMapperFactory, - sessionProvider, - new JVMMailboxPathLocker(), - new MessageParser(), - messageIdFactory, - eventBus, - annotationManager, - storeRightManager, - quotaComponents, - searchIndex, - PreDeletionHooks.NO_PRE_DELETION_HOOK); - - eventBus.register(searchIndex); + + InMemoryIntegrationResources resources = new InMemoryIntegrationResources.Factory() + .withAuthenticator(authenticator) + .withAuthorizator(authorizator) + .withSearchIndex(preInstanciationStage -> new ElasticSearchListeningMessageSearchIndex( + preInstanciationStage.getMapperFactory(), + new ElasticSearchIndexer(client, + Executors.newSingleThreadExecutor(threadFactory), + MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS, + MailboxElasticSearchConstants.MESSAGE_TYPE), + new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), ElasticSearchSearcher.DEFAULT_SEARCH_SIZE, + new InMemoryId.Factory(), messageIdFactory, + MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, + MailboxElasticSearchConstants.MESSAGE_TYPE), + new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES), + preInstanciationStage.getSessionProvider())) + .create(); + + mailboxManager = resources.getMailboxManager(); ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, - eventBus, + resources.getMailboxManager().getEventBus(), new StoreSubscriptionManager(mailboxManager.getMapperFactory()), new NoQuotaManager(), - new DefaultUserQuotaRootResolver(mailboxManager.getSessionProvider(), mailboxManager.getMapperFactory()), + resources.getDefaultUserQuotaRootResolver(), new DefaultMetricFactory()); configure(new DefaultImapDecoderFactory().buildImapDecoder(), new DefaultImapEncoderFactory().buildImapEncoder(), diff --git a/mpt/impl/imap-mailbox/lucenesearch/pom.xml b/mpt/impl/imap-mailbox/lucenesearch/pom.xml index 6db9320..befdd90 100644 --- a/mpt/impl/imap-mailbox/lucenesearch/pom.xml +++ b/mpt/impl/imap-mailbox/lucenesearch/pom.xml @@ -37,6 +37,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>apache-james-mailbox-api</artifactId> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>apache-james-mailbox-event-memory</artifactId> </dependency> <dependency> diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java index b6b24b2..a3bef4e 100644 --- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java +++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java @@ -33,33 +33,20 @@ import org.apache.james.imap.processor.main.DefaultImapProcessorFactory; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.SubscriptionManager; -import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; -import org.apache.james.mailbox.acl.UnionMailboxACLResolver; -import org.apache.james.mailbox.events.InVMEventBus; -import org.apache.james.mailbox.events.delivery.InVmEventDelivery; -import org.apache.james.mailbox.extension.PreDeletionHook; import org.apache.james.mailbox.inmemory.InMemoryId; import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; -import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory; import org.apache.james.mailbox.inmemory.InMemoryMessageId; +import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex; -import org.apache.james.mailbox.store.JVMMailboxPathLocker; -import org.apache.james.mailbox.store.PreDeletionHooks; -import org.apache.james.mailbox.store.SessionProvider; -import org.apache.james.mailbox.store.StoreMailboxAnnotationManager; -import org.apache.james.mailbox.store.StoreRightManager; import org.apache.james.mailbox.store.StoreSubscriptionManager; -import org.apache.james.mailbox.store.mail.model.impl.MessageParser; -import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver; import org.apache.james.mailbox.store.quota.NoQuotaManager; -import org.apache.james.mailbox.store.quota.QuotaComponents; -import org.apache.james.metrics.api.NoopMetricFactory; import org.apache.james.metrics.logger.DefaultMetricFactory; import org.apache.james.mpt.api.ImapFeatures; import org.apache.james.mpt.api.ImapFeatures.Feature; import org.apache.james.mpt.host.JamesImapHostSystem; import org.apache.lucene.store.FSDirectory; +import com.github.fge.lambdas.Throwing; import com.google.common.io.Files; public class LuceneSearchHostSystem extends JamesImapHostSystem { @@ -99,43 +86,31 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem { } private void initFields() { - try { - InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory())); - - InMemoryMailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory(); - StoreRightManager rightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), eventBus); - JVMMailboxPathLocker locker = new JVMMailboxPathLocker(); - InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory(); - SessionProvider sessionProvider = new SessionProvider(authenticator, authorizator); FSDirectory fsDirectory = FSDirectory.open(tempFile); - searchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(), fsDirectory, messageIdFactory, sessionProvider); - - mailboxManager = new InMemoryMailboxManager(mapperFactory, - sessionProvider, - locker, - new MessageParser(), - messageIdFactory, - eventBus, - new StoreMailboxAnnotationManager(mapperFactory, rightManager), - rightManager, - QuotaComponents.disabled(sessionProvider, mapperFactory), - searchIndex, - PreDeletionHooks.NO_PRE_DELETION_HOOK); - searchIndex.setEnableSuffixMatch(true); + InMemoryIntegrationResources resources = new InMemoryIntegrationResources.Factory() + .withAuthorizator(authorizator) + .withAuthenticator(authenticator) + .withSearchIndex(Throwing.function(preInstanciationStage -> new LuceneMessageSearchIndex( + preInstanciationStage.getMapperFactory(), new InMemoryId.Factory(), fsDirectory, + new InMemoryMessageId.Factory(), + preInstanciationStage.getSessionProvider()))) + .create(); - eventBus.register(searchIndex); + mailboxManager = resources.getMailboxManager(); - SubscriptionManager subscriptionManager = new StoreSubscriptionManager(mapperFactory); + searchIndex = (LuceneMessageSearchIndex) resources.getSearchIndex(); + searchIndex.setEnableSuffixMatch(true); + SubscriptionManager subscriptionManager = new StoreSubscriptionManager(mailboxManager.getMapperFactory()); ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor( mailboxManager, - eventBus, + resources.getMailboxManager().getEventBus(), subscriptionManager, new NoQuotaManager(), - new DefaultUserQuotaRootResolver(sessionProvider, mapperFactory), + resources.getDefaultUserQuotaRootResolver(), new DefaultMetricFactory()); configure(new DefaultImapDecoderFactory().buildImapDecoder(), @@ -158,7 +133,7 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem { } @Override - public void setQuotaLimits(QuotaCount maxMessageQuota, QuotaSize maxStorageQuota) throws Exception { + public void setQuotaLimits(QuotaCount maxMessageQuota, QuotaSize maxStorageQuota) { throw new NotImplementedException(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
