Repository: james-project Updated Branches: refs/heads/master 844b9519c -> d0ba1776d
JAMES-1974 Remove useless dependencies Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8e08bb4f Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8e08bb4f Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8e08bb4f Branch: refs/heads/master Commit: 8e08bb4fa37bc1f7ca9ef7cd95055a20f1f663e7 Parents: 844b951 Author: Matthieu Baechler <matthieu.baech...@gmail.com> Authored: Wed Mar 22 21:03:46 2017 +0100 Committer: benwa <btell...@linagora.com> Committed: Fri Mar 24 08:29:49 2017 +0700 ---------------------------------------------------------------------- server/container/guice/cassandra-guice/pom.xml | 4 + server/container/guice/guice-common/pom.xml | 30 --- .../james/modules/CommonServicesModule.java | 3 +- .../james/modules/MissingArgumentException.java | 28 +++ .../modules/mailbox/DefaultEventModule.java | 40 ---- .../modules/mailbox/DefaultQuotaModule.java | 45 ---- .../apache/james/modules/server/JMXServer.java | 125 ----------- .../james/modules/server/JMXServerModule.java | 128 ----------- .../james/utils/FileConfigurationProvider.java | 3 +- .../utils/GuiceMailboxManagerResolver.java | 59 ------ .../utils/FileConfigurationProviderTest.java | 3 +- server/container/guice/jmx/pom.xml | 212 +++++++++++++++++++ .../apache/james/modules/server/JMXServer.java | 125 +++++++++++ .../james/modules/server/JMXServerModule.java | 128 +++++++++++ .../utils/GuiceMailboxManagerResolver.java | 59 ++++++ server/container/guice/jpa-common-guice/pom.xml | 58 ----- server/container/guice/jpa-guice/pom.xml | 4 + .../org/apache/james/JPAJamesServerMain.java | 3 +- .../modules/mailbox/DefaultEventModule.java | 40 ++++ .../modules/mailbox/DefaultQuotaModule.java | 45 ++++ server/container/guice/memory-guice/pom.xml | 4 + server/container/guice/pom.xml | 6 + 22 files changed, 659 insertions(+), 493 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/cassandra-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml index 191800b..348003e 100644 --- a/server/container/guice/cassandra-guice/pom.xml +++ b/server/container/guice/cassandra-guice/pom.xml @@ -269,6 +269,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-jmx</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-lmtp</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/pom.xml b/server/container/guice/guice-common/pom.xml index 3494397..e34c561 100644 --- a/server/container/guice/guice-common/pom.xml +++ b/server/container/guice/guice-common/pom.xml @@ -133,14 +133,6 @@ <dependencies> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>apache-james-mailbox-tool</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>james-server-cli</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>james-server-core</artifactId> </dependency> <dependency> @@ -197,20 +189,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>james-server-guice-mailbox</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-mailet</artifactId> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>james-server-guice-managedsieve</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-smtp</artifactId> <scope>test</scope> </dependency> @@ -237,18 +219,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>james-server-protocols-imap4</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>james-server-protocols-library</artifactId> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>james-server-protocols-pop3</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>james-server-protocols-smtp</artifactId> </dependency> <dependency> @@ -264,10 +238,6 @@ <artifactId>james-server-onami</artifactId> </dependency> <dependency> - <groupId>org.apache.james.protocols</groupId> - <artifactId>protocols-imap</artifactId> - </dependency> - <dependency> <groupId>com.github.steveash.guavate</groupId> <artifactId>guavate</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java index c06b7e5..cc308a2 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java @@ -24,7 +24,6 @@ import java.util.Optional; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.commons.cli.MissingArgumentException; import org.apache.james.core.JamesServerResourceLoader; import org.apache.james.core.filesystem.FileSystemImpl; import org.apache.james.filesystem.api.FileSystem; @@ -34,8 +33,8 @@ import org.apache.james.modules.server.ConfigurationProviderModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.DropWizardMetricsModule; import org.apache.james.onami.lifecycle.PreDestroyModule; -import org.apache.james.utils.GuiceProbe; import org.apache.james.utils.DataProbeImpl; +import org.apache.james.utils.GuiceProbe; import com.google.inject.AbstractModule; import com.google.inject.Provides; http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MissingArgumentException.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MissingArgumentException.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MissingArgumentException.java new file mode 100644 index 0000000..737ccc5 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MissingArgumentException.java @@ -0,0 +1,28 @@ +/**************************************************************** + * 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; + +public class MissingArgumentException extends RuntimeException { + + public MissingArgumentException(String message) { + super(message); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java deleted file mode 100644 index 9bb03f8..0000000 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java +++ /dev/null @@ -1,40 +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.mailbox; - -import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener; -import org.apache.james.mailbox.store.event.DelegatingMailboxListener; -import org.apache.james.mailbox.store.event.EventDelivery; -import org.apache.james.mailbox.store.event.SynchronousEventDelivery; - -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; - -public class DefaultEventModule extends AbstractModule { - - @Override - protected void configure() { - bind(DefaultDelegatingMailboxListener.class).in(Scopes.SINGLETON); - bind(DelegatingMailboxListener.class).to(DefaultDelegatingMailboxListener.class); - - bind(SynchronousEventDelivery.class).in(Scopes.SINGLETON); - bind(EventDelivery.class).to(SynchronousEventDelivery.class); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java deleted file mode 100644 index 41be7ea..0000000 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java +++ /dev/null @@ -1,45 +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.mailbox; - -import org.apache.james.mailbox.quota.MaxQuotaManager; -import org.apache.james.mailbox.quota.QuotaManager; -import org.apache.james.mailbox.quota.QuotaRootResolver; -import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver; -import org.apache.james.mailbox.store.quota.NoMaxQuotaManager; -import org.apache.james.mailbox.store.quota.NoQuotaManager; - -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; - -public class DefaultQuotaModule extends AbstractModule { - - @Override - protected void configure() { - bind(NoQuotaManager.class).in(Scopes.SINGLETON); - bind(DefaultQuotaRootResolver.class).in(Scopes.SINGLETON); - bind(NoMaxQuotaManager.class).in(Scopes.SINGLETON); - - bind(MaxQuotaManager.class).to(NoMaxQuotaManager.class); - bind(QuotaManager.class).to(NoQuotaManager.class); - bind(QuotaRootResolver.class).to(DefaultQuotaRootResolver.class); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServer.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServer.java deleted file mode 100644 index 4b4e63d..0000000 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServer.java +++ /dev/null @@ -1,125 +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 java.io.IOException; -import java.lang.management.ManagementFactory; -import java.rmi.registry.LocateRegistry; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import javax.management.remote.JMXConnectorServer; -import javax.management.remote.JMXConnectorServerFactory; -import javax.management.remote.JMXServiceURL; - -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.util.RestrictingRMISocketFactory; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; - -public class JMXServer { - - private final FileSystem fileSystem; - private final Set<String> registeredKeys; - private final Object lock; - private JMXConnectorServer jmxConnectorServer; - private boolean isStarted; - - @Inject - public JMXServer(FileSystem fileSystem) { - this.fileSystem = fileSystem; - isStarted = false; - registeredKeys = new HashSet<>(); - lock = new Object(); - } - - public void start() { - synchronized (lock) { - if (isStarted) { - return; - } - isStarted = true; - doStart(); - } - } - - @PreDestroy - public void stop() { - synchronized (lock) { - if (!isStarted) { - return; - } - isStarted = false; - doStop(); - } - } - - public void register(String key, Object remote) throws Exception { - ManagementFactory.getPlatformMBeanServer().registerMBean(remote, new ObjectName(key)); - synchronized (lock) { - registeredKeys.add(key); - } - } - - private void doStart() { - try { - PropertiesConfiguration configuration = new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties")); - String address = configuration.getString("jmx.address"); - int port = configuration.getInt("jmx.port"); - String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi"; - RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address); - LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory); - - Map<String, ?> environment = ImmutableMap.of(); - jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL), - environment, - ManagementFactory.getPlatformMBeanServer()); - - jmxConnectorServer.start(); - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - private void doStop() { - try { - MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); - registeredKeys.forEach(key -> { - try { - mBeanServer.unregisterMBean(new ObjectName(key)); - } catch (Exception e) { - throw Throwables.propagate(e); - } - }); - registeredKeys.clear(); - jmxConnectorServer.stop(); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServerModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServerModule.java deleted file mode 100644 index 9d66b8a..0000000 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/JMXServerModule.java +++ /dev/null @@ -1,128 +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 java.util.List; - -import org.apache.james.adapter.mailbox.MailboxCopierManagement; -import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; -import org.apache.james.adapter.mailbox.MailboxManagerManagement; -import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; -import org.apache.james.adapter.mailbox.MailboxManagerResolver; -import org.apache.james.adapter.mailbox.ReIndexerManagement; -import org.apache.james.adapter.mailbox.ReIndexerManagementMBean; -import org.apache.james.domainlist.api.DomainListManagementMBean; -import org.apache.james.domainlist.lib.DomainListManagement; -import org.apache.james.lifecycle.api.Configurable; -import org.apache.james.mailbox.copier.MailboxCopier; -import org.apache.james.mailbox.copier.MailboxCopierImpl; -import org.apache.james.mailbox.indexer.ReIndexer; -import org.apache.james.mailbox.indexer.ReIndexerImpl; -import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean; -import org.apache.james.mailetcontainer.impl.JamesMailSpooler; -import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; -import org.apache.james.rrt.lib.RecipientRewriteTableManagement; -import org.apache.james.user.api.UsersRepositoryManagementMBean; -import org.apache.james.user.lib.UsersRepositoryManagement; -import org.apache.james.utils.ConfigurationPerformer; -import org.apache.james.utils.GuiceMailboxManagerResolver; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.name.Names; - -public class JMXServerModule extends AbstractModule { - - private static final String JMX_COMPONENT_DOMAINLIST = "org.apache.james:type=component,name=domainlist"; - private static final String JMX_COMPONENT_USERS_REPOSITORY = "org.apache.james:type=component,name=usersrepository"; - private static final String JMX_COMPONENT_RECIPIENTREWRITETABLE = "org.apache.james:type=component,name=recipientrewritetable"; - private static final String JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN = "org.apache.james:type=component,name=mailboxmanagerbean"; - private static final String JMX_COMPONENT_MAILBOXCOPIER = "org.apache.james:type=component,name=mailboxcopier"; - private static final String JMX_COMPONENT_REINDEXER = "org.apache.james:type=component,name=reindexerbean"; - - @Override - protected void configure() { - bind(MailboxCopier.class).annotatedWith(Names.named("mailboxcopier")).to(MailboxCopierImpl.class); - bind(MailboxCopierManagementMBean.class).to(MailboxCopierManagement.class); - bind(MailboxManagerResolver.class).to(GuiceMailboxManagerResolver.class); - bind(DomainListManagementMBean.class).to(DomainListManagement.class); - bind(UsersRepositoryManagementMBean.class).to(UsersRepositoryManagement.class); - bind(MailboxManagerManagementMBean.class).to(MailboxManagerManagement.class); - bind(RecipientRewriteTableManagementMBean.class).to(RecipientRewriteTableManagement.class); - bind(MailSpoolerMBean.class).to(JamesMailSpooler.class); - bind(ReIndexer.class).annotatedWith(Names.named("reindexer")).to(ReIndexerImpl.class); - bind(ReIndexerManagementMBean.class).to(ReIndexerManagement.class); - Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JMXModuleConfigurationPerformer.class); - } - - @Singleton - public static class JMXModuleConfigurationPerformer implements ConfigurationPerformer { - - private final JMXServer jmxServer; - private final DomainListManagementMBean domainListManagementMBean; - private final UsersRepositoryManagementMBean usersRepositoryManagementMBean; - private final RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean; - private final MailboxManagerManagementMBean mailboxManagerManagementMBean; - private final MailboxCopierManagementMBean mailboxCopierManagementMBean; - private final ReIndexerManagementMBean reIndexerManagementMBean; - - @Inject - public JMXModuleConfigurationPerformer(JMXServer jmxServer, - DomainListManagementMBean domainListManagementMBean, - UsersRepositoryManagementMBean usersRepositoryManagementMBean, - RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean, - MailboxManagerManagementMBean mailboxManagerManagementMBean, - MailboxCopierManagementMBean mailboxCopierManagementMBean, - ReIndexerManagementMBean reIndexerManagementMBean) { - this.jmxServer = jmxServer; - this.domainListManagementMBean = domainListManagementMBean; - this.usersRepositoryManagementMBean = usersRepositoryManagementMBean; - this.recipientRewriteTableManagementMBean = recipientRewriteTableManagementMBean; - this.mailboxManagerManagementMBean = mailboxManagerManagementMBean; - this.mailboxCopierManagementMBean = mailboxCopierManagementMBean; - this.reIndexerManagementMBean = reIndexerManagementMBean; - } - - @Override - public void initModule() { - try { - jmxServer.start(); - jmxServer.register(JMX_COMPONENT_DOMAINLIST, domainListManagementMBean); - jmxServer.register(JMX_COMPONENT_USERS_REPOSITORY, usersRepositoryManagementMBean); - jmxServer.register(JMX_COMPONENT_RECIPIENTREWRITETABLE, recipientRewriteTableManagementMBean); - jmxServer.register(JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN, mailboxManagerManagementMBean); - jmxServer.register(JMX_COMPONENT_MAILBOXCOPIER, mailboxCopierManagementMBean); - jmxServer.register(JMX_COMPONENT_REINDEXER, reIndexerManagementMBean); - } catch (Exception e) { - Throwables.propagate(e); - } - } - - @Override - public List<Class<? extends Configurable>> forClasses() { - return ImmutableList.of(); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/utils/FileConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/FileConfigurationProvider.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/FileConfigurationProvider.java index 78144c6..6fa9090 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/FileConfigurationProvider.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/FileConfigurationProvider.java @@ -26,7 +26,6 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Named; -import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.XMLConfiguration; @@ -46,7 +45,7 @@ public class FileConfigurationProvider implements ConfigurationProvider { private final String configurationPrefix; @Inject - public FileConfigurationProvider(FileSystem fileSystem, @Named(CommonServicesModule.CONFIGURATION_PATH) String configurationPrefix) throws MissingArgumentException { + public FileConfigurationProvider(FileSystem fileSystem, @Named(CommonServicesModule.CONFIGURATION_PATH) String configurationPrefix) { this.fileSystem = fileSystem; this.configurationPrefix = configurationPrefix; } http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java deleted file mode 100644 index fe55c9c..0000000 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java +++ /dev/null @@ -1,59 +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.utils; - -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.james.adapter.mailbox.MailboxManagerResolver; -import org.apache.james.adapter.mailbox.MailboxManagerResolverException; -import org.apache.james.mailbox.MailboxManager; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Inject; - -public class GuiceMailboxManagerResolver implements MailboxManagerResolver { - - private final ImmutableMap<String, MailboxManager> managers; - - @Inject - private GuiceMailboxManagerResolver(Set<MailboxManagerDefinition> managers) { - this.managers = indexManagersByName(managers); - } - - private static ImmutableMap<String, MailboxManager> indexManagersByName(Set<MailboxManagerDefinition> managers) { - return ImmutableMap.copyOf(managers.stream().collect( - Collectors.toMap(MailboxManagerDefinition::getName, MailboxManagerDefinition::getManager))); - } - - @Override - public Map<String, MailboxManager> getMailboxManagerBeans() { - return managers; - } - - @Override - public MailboxManager resolveMailboxManager(String mailboxManagerClassName) { - return Optional.ofNullable(managers.get(mailboxManagerClassName)).orElseThrow( - () -> new MailboxManagerResolverException("Unable to find a mailbox manager with name " + mailboxManagerClassName)); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/guice-common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java index 4fe0360..0eeb88f 100644 --- a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java +++ b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java @@ -21,7 +21,6 @@ package org.apache.james.utils; import static org.assertj.core.api.Assertions.assertThat; -import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.james.core.JamesServerResourceLoader; @@ -46,7 +45,7 @@ public class FileConfigurationProviderTest { private FileConfigurationProvider configurationProvider; @Before - public void setUp() throws MissingArgumentException { + public void setUp() { FileSystemImpl fileSystem = new FileSystemImpl(new JamesServerResourceLoader("../")); configurationProvider = new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL); } http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jmx/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jmx/pom.xml b/server/container/guice/jmx/pom.xml new file mode 100644 index 0000000..5e520d2 --- /dev/null +++ b/server/container/guice/jmx/pom.xml @@ -0,0 +1,212 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>james-server-guice</artifactId> + <groupId>org.apache.james</groupId> + <version>3.0.0-beta6-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>james-server-guice-jmx</artifactId> + + <name>Apache James :: Server :: Guice :: JMX </name> + <description>JMX for Guice implementation of James server</description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>disable-build-for-older-jdk</id> + <activation> + <jdk>(,1.8)</jdk> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>default-jar</id> + <phase>none</phase> + </execution> + <execution> + <id>jar</id> + <phase>none</phase> + </execution> + <execution> + <id>test-jar</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <executions> + <execution> + <id>default-compile</id> + <phase>none</phase> + </execution> + <execution> + <id>default-testCompile</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>default-test</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <executions> + <execution> + <id>default-install</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>default-resources</id> + <phase>none</phase> + </execution> + <execution> + <id>default-testResources</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <executions> + <execution> + <id>attach-descriptor</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>build-for-jdk-8</id> + <activation> + <jdk>[1.8,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-data-api</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-data-library</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-configuration</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-common</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-mailbox-adapter</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-mailetcontainer-api</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-mailetcontainer-camel</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-util</artifactId> + </dependency> + <dependency> + <groupId>com.google.inject</groupId> + <artifactId>guice</artifactId> + </dependency> + <dependency> + <groupId>com.google.inject.extensions</groupId> + <artifactId>guice-multibindings</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>animal-sniffer-java-8</id> + <activation> + <jdk>[1.8,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>animal-sniffer-maven-plugin</artifactId> + <configuration> + <signature> + <groupId>org.codehaus.mojo.signature</groupId> + <artifactId>java18</artifactId> + <version>1.0</version> + </signature> + </configuration> + <executions> + <execution> + <id>check_java_8</id> + <phase>test</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java new file mode 100644 index 0000000..4b4e63d --- /dev/null +++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java @@ -0,0 +1,125 @@ +/**************************************************************** + * 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 java.io.IOException; +import java.lang.management.ManagementFactory; +import java.rmi.registry.LocateRegistry; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXServiceURL; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.util.RestrictingRMISocketFactory; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; + +public class JMXServer { + + private final FileSystem fileSystem; + private final Set<String> registeredKeys; + private final Object lock; + private JMXConnectorServer jmxConnectorServer; + private boolean isStarted; + + @Inject + public JMXServer(FileSystem fileSystem) { + this.fileSystem = fileSystem; + isStarted = false; + registeredKeys = new HashSet<>(); + lock = new Object(); + } + + public void start() { + synchronized (lock) { + if (isStarted) { + return; + } + isStarted = true; + doStart(); + } + } + + @PreDestroy + public void stop() { + synchronized (lock) { + if (!isStarted) { + return; + } + isStarted = false; + doStop(); + } + } + + public void register(String key, Object remote) throws Exception { + ManagementFactory.getPlatformMBeanServer().registerMBean(remote, new ObjectName(key)); + synchronized (lock) { + registeredKeys.add(key); + } + } + + private void doStart() { + try { + PropertiesConfiguration configuration = new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties")); + String address = configuration.getString("jmx.address"); + int port = configuration.getInt("jmx.port"); + String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi"; + RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address); + LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory); + + Map<String, ?> environment = ImmutableMap.of(); + jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL), + environment, + ManagementFactory.getPlatformMBeanServer()); + + jmxConnectorServer.start(); + } catch (Exception e) { + throw Throwables.propagate(e); + } + } + + private void doStop() { + try { + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + registeredKeys.forEach(key -> { + try { + mBeanServer.unregisterMBean(new ObjectName(key)); + } catch (Exception e) { + throw Throwables.propagate(e); + } + }); + registeredKeys.clear(); + jmxConnectorServer.stop(); + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java new file mode 100644 index 0000000..9d66b8a --- /dev/null +++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java @@ -0,0 +1,128 @@ +/**************************************************************** + * 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 java.util.List; + +import org.apache.james.adapter.mailbox.MailboxCopierManagement; +import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerManagement; +import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerResolver; +import org.apache.james.adapter.mailbox.ReIndexerManagement; +import org.apache.james.adapter.mailbox.ReIndexerManagementMBean; +import org.apache.james.domainlist.api.DomainListManagementMBean; +import org.apache.james.domainlist.lib.DomainListManagement; +import org.apache.james.lifecycle.api.Configurable; +import org.apache.james.mailbox.copier.MailboxCopier; +import org.apache.james.mailbox.copier.MailboxCopierImpl; +import org.apache.james.mailbox.indexer.ReIndexer; +import org.apache.james.mailbox.indexer.ReIndexerImpl; +import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean; +import org.apache.james.mailetcontainer.impl.JamesMailSpooler; +import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; +import org.apache.james.rrt.lib.RecipientRewriteTableManagement; +import org.apache.james.user.api.UsersRepositoryManagementMBean; +import org.apache.james.user.lib.UsersRepositoryManagement; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.GuiceMailboxManagerResolver; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Names; + +public class JMXServerModule extends AbstractModule { + + private static final String JMX_COMPONENT_DOMAINLIST = "org.apache.james:type=component,name=domainlist"; + private static final String JMX_COMPONENT_USERS_REPOSITORY = "org.apache.james:type=component,name=usersrepository"; + private static final String JMX_COMPONENT_RECIPIENTREWRITETABLE = "org.apache.james:type=component,name=recipientrewritetable"; + private static final String JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN = "org.apache.james:type=component,name=mailboxmanagerbean"; + private static final String JMX_COMPONENT_MAILBOXCOPIER = "org.apache.james:type=component,name=mailboxcopier"; + private static final String JMX_COMPONENT_REINDEXER = "org.apache.james:type=component,name=reindexerbean"; + + @Override + protected void configure() { + bind(MailboxCopier.class).annotatedWith(Names.named("mailboxcopier")).to(MailboxCopierImpl.class); + bind(MailboxCopierManagementMBean.class).to(MailboxCopierManagement.class); + bind(MailboxManagerResolver.class).to(GuiceMailboxManagerResolver.class); + bind(DomainListManagementMBean.class).to(DomainListManagement.class); + bind(UsersRepositoryManagementMBean.class).to(UsersRepositoryManagement.class); + bind(MailboxManagerManagementMBean.class).to(MailboxManagerManagement.class); + bind(RecipientRewriteTableManagementMBean.class).to(RecipientRewriteTableManagement.class); + bind(MailSpoolerMBean.class).to(JamesMailSpooler.class); + bind(ReIndexer.class).annotatedWith(Names.named("reindexer")).to(ReIndexerImpl.class); + bind(ReIndexerManagementMBean.class).to(ReIndexerManagement.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JMXModuleConfigurationPerformer.class); + } + + @Singleton + public static class JMXModuleConfigurationPerformer implements ConfigurationPerformer { + + private final JMXServer jmxServer; + private final DomainListManagementMBean domainListManagementMBean; + private final UsersRepositoryManagementMBean usersRepositoryManagementMBean; + private final RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean; + private final MailboxManagerManagementMBean mailboxManagerManagementMBean; + private final MailboxCopierManagementMBean mailboxCopierManagementMBean; + private final ReIndexerManagementMBean reIndexerManagementMBean; + + @Inject + public JMXModuleConfigurationPerformer(JMXServer jmxServer, + DomainListManagementMBean domainListManagementMBean, + UsersRepositoryManagementMBean usersRepositoryManagementMBean, + RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean, + MailboxManagerManagementMBean mailboxManagerManagementMBean, + MailboxCopierManagementMBean mailboxCopierManagementMBean, + ReIndexerManagementMBean reIndexerManagementMBean) { + this.jmxServer = jmxServer; + this.domainListManagementMBean = domainListManagementMBean; + this.usersRepositoryManagementMBean = usersRepositoryManagementMBean; + this.recipientRewriteTableManagementMBean = recipientRewriteTableManagementMBean; + this.mailboxManagerManagementMBean = mailboxManagerManagementMBean; + this.mailboxCopierManagementMBean = mailboxCopierManagementMBean; + this.reIndexerManagementMBean = reIndexerManagementMBean; + } + + @Override + public void initModule() { + try { + jmxServer.start(); + jmxServer.register(JMX_COMPONENT_DOMAINLIST, domainListManagementMBean); + jmxServer.register(JMX_COMPONENT_USERS_REPOSITORY, usersRepositoryManagementMBean); + jmxServer.register(JMX_COMPONENT_RECIPIENTREWRITETABLE, recipientRewriteTableManagementMBean); + jmxServer.register(JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN, mailboxManagerManagementMBean); + jmxServer.register(JMX_COMPONENT_MAILBOXCOPIER, mailboxCopierManagementMBean); + jmxServer.register(JMX_COMPONENT_REINDEXER, reIndexerManagementMBean); + } catch (Exception e) { + Throwables.propagate(e); + } + } + + @Override + public List<Class<? extends Configurable>> forClasses() { + return ImmutableList.of(); + } + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jmx/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java b/server/container/guice/jmx/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java new file mode 100644 index 0000000..fe55c9c --- /dev/null +++ b/server/container/guice/jmx/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java @@ -0,0 +1,59 @@ +/**************************************************************** + * 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.utils; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.james.adapter.mailbox.MailboxManagerResolver; +import org.apache.james.adapter.mailbox.MailboxManagerResolverException; +import org.apache.james.mailbox.MailboxManager; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; + +public class GuiceMailboxManagerResolver implements MailboxManagerResolver { + + private final ImmutableMap<String, MailboxManager> managers; + + @Inject + private GuiceMailboxManagerResolver(Set<MailboxManagerDefinition> managers) { + this.managers = indexManagersByName(managers); + } + + private static ImmutableMap<String, MailboxManager> indexManagersByName(Set<MailboxManagerDefinition> managers) { + return ImmutableMap.copyOf(managers.stream().collect( + Collectors.toMap(MailboxManagerDefinition::getName, MailboxManagerDefinition::getManager))); + } + + @Override + public Map<String, MailboxManager> getMailboxManagerBeans() { + return managers; + } + + @Override + public MailboxManager resolveMailboxManager(String mailboxManagerClassName) { + return Optional.ofNullable(managers.get(mailboxManagerClassName)).orElseThrow( + () -> new MailboxManagerResolverException("Unable to find a mailbox manager with name " + mailboxManagerClassName)); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jpa-common-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-common-guice/pom.xml b/server/container/guice/jpa-common-guice/pom.xml index fb83a19..4006d66 100644 --- a/server/container/guice/jpa-common-guice/pom.xml +++ b/server/container/guice/jpa-common-guice/pom.xml @@ -191,25 +191,6 @@ </plugins> </build> <dependencies> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>apache-james-mailbox-jpa</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>apache-james-mailbox-jpa</artifactId> - <scope>test</scope> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>apache-james-mailbox-lucene</artifactId> - </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>james-server-data-jpa</artifactId> @@ -218,45 +199,6 @@ <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-common</artifactId> </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>james-server-guice-common</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>james-server-guice-configuration</artifactId> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>1.1.7</version> - </dependency> - <dependency> - <groupId>com.jayway.awaitility</groupId> - <artifactId>awaitility</artifactId> - </dependency> - <dependency> - <groupId>com.jayway.restassured</groupId> - <artifactId>rest-assured</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.nurkiewicz.asyncretry</groupId> - <artifactId>asyncretry</artifactId> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <version>${assertj-3.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> </dependencies> </profile> <profile> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jpa-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml index a3a9766..e70712e 100644 --- a/server/container/guice/jpa-guice/pom.xml +++ b/server/container/guice/jpa-guice/pom.xml @@ -235,6 +235,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-jmx</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-lmtp</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java index ce01b8d..51174c6 100644 --- a/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java +++ b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java @@ -25,7 +25,6 @@ import org.apache.james.modules.data.JPADataModule; import org.apache.james.modules.protocols.ProtocolHandlerModule; import org.apache.james.modules.protocols.SMTPServerModule; import org.apache.james.modules.server.ActiveMQQueueModule; -import org.apache.james.modules.server.JMXServerModule; import org.apache.james.modules.server.RawPostDequeueDecoratorModule; import org.apache.openjpa.persistence.OpenJPAPersistence; @@ -46,7 +45,7 @@ public class JPAJamesServerMain { public static void main(String[] args) throws Exception { GuiceJamesServer server = new GuiceJamesServer() - .combineWith(jpaServerModule, protocols, new JMXServerModule()); + .combineWith(jpaServerModule, protocols); server.start(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java new file mode 100644 index 0000000..9bb03f8 --- /dev/null +++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java @@ -0,0 +1,40 @@ +/**************************************************************** + * 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.mailbox; + +import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener; +import org.apache.james.mailbox.store.event.DelegatingMailboxListener; +import org.apache.james.mailbox.store.event.EventDelivery; +import org.apache.james.mailbox.store.event.SynchronousEventDelivery; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; + +public class DefaultEventModule extends AbstractModule { + + @Override + protected void configure() { + bind(DefaultDelegatingMailboxListener.class).in(Scopes.SINGLETON); + bind(DelegatingMailboxListener.class).to(DefaultDelegatingMailboxListener.class); + + bind(SynchronousEventDelivery.class).in(Scopes.SINGLETON); + bind(EventDelivery.class).to(SynchronousEventDelivery.class); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java new file mode 100644 index 0000000..41be7ea --- /dev/null +++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultQuotaModule.java @@ -0,0 +1,45 @@ +/**************************************************************** + * 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.mailbox; + +import org.apache.james.mailbox.quota.MaxQuotaManager; +import org.apache.james.mailbox.quota.QuotaManager; +import org.apache.james.mailbox.quota.QuotaRootResolver; +import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver; +import org.apache.james.mailbox.store.quota.NoMaxQuotaManager; +import org.apache.james.mailbox.store.quota.NoQuotaManager; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; + +public class DefaultQuotaModule extends AbstractModule { + + @Override + protected void configure() { + bind(NoQuotaManager.class).in(Scopes.SINGLETON); + bind(DefaultQuotaRootResolver.class).in(Scopes.SINGLETON); + bind(NoMaxQuotaManager.class).in(Scopes.SINGLETON); + + bind(MaxQuotaManager.class).to(NoMaxQuotaManager.class); + bind(QuotaManager.class).to(NoQuotaManager.class); + bind(QuotaRootResolver.class).to(DefaultQuotaRootResolver.class); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/memory-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml index 9575cd0..8496189 100644 --- a/server/container/guice/memory-guice/pom.xml +++ b/server/container/guice/memory-guice/pom.xml @@ -230,6 +230,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-jmx</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-lmtp</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/8e08bb4f/server/container/guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml index 76fd74e..bc00fd7 100644 --- a/server/container/guice/pom.xml +++ b/server/container/guice/pom.xml @@ -57,6 +57,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-jmx</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-lmtp</artifactId> <version>${project.version}</version> </dependency> @@ -109,6 +114,7 @@ <module>jpa-common-guice</module> <module>jpa-guice</module> <module>jpa-smtp</module> + <module>jmx</module> <module>onami</module> <module>protocols/imap</module> <module>protocols/jmap</module> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org