JAMES-2521 Limit CLI mailbox dependencies mailbox-adapter is mixing: - adapters between mailbox and server concepts - JMX apis
This mix was harmfull, as we ended up binding server and mailbox implementation in the CLI Splitting both concepts in different modules solves the issue. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1be65de5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1be65de5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1be65de5 Branch: refs/heads/master Commit: 1be65de590cb9a991a54cd94ae4436c5ed2b427c Parents: eabfa17 Author: Benoit Tellier <[email protected]> Authored: Tue Aug 14 11:44:04 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Wed Aug 29 10:11:46 2018 +0700 ---------------------------------------------------------------------- dockerfiles/run/guice/jpa/Dockerfile | 2 +- .../apache/james/mailbox/indexer/ReIndexer.java | 31 ++ .../james/mailbox/model/SerializableQuota.java | 83 +++++ .../mailbox/model/SerializableQuotaValue.java | 91 ++++++ .../store/mail/model/SerializableQuota.java | 84 ----- .../mail/model/SerializableQuotaValue.java | 91 ------ .../james/mailbox/store/probe/QuotaProbe.java | 4 +- .../apache/james/mailbox/indexer/ReIndexer.java | 31 -- pom.xml | 5 + server/container/cli/pom.xml | 6 +- .../java/org/apache/james/cli/ServerCmd.java | 16 +- .../james/cli/probe/impl/JmxMailboxProbe.java | 8 +- .../james/cli/probe/impl/JmxQuotaProbe.java | 4 +- .../org/apache/james/cli/ServerCmdTest.java | 4 +- server/container/guice/jmx/pom.xml | 2 +- .../org/apache/james/JPAJamesServerTest.java | 2 +- server/container/guice/mailbox/pom.xml | 4 + .../apache/james/modules/QuotaProbesImpl.java | 4 +- .../mailbox/MailboxCopierManagement.java | 83 ----- .../mailbox/MailboxCopierManagementMBean.java | 47 --- .../mailbox/MailboxManagerManagement.java | 221 ------------- .../mailbox/MailboxManagerManagementMBean.java | 76 ----- .../adapter/mailbox/MailboxManagerResolver.java | 31 -- .../MailboxManagerResolverException.java | 35 --- .../james/adapter/mailbox/QuotaManagement.java | 207 ------------- .../adapter/mailbox/QuotaManagementMBean.java | 50 --- .../adapter/mailbox/ReIndexerManagement.java | 67 ---- .../mailbox/ReIndexerManagementMBean.java | 30 -- .../adapter/mailbox/MailboxManagementTest.java | 308 ------------------- .../src/test/resources/eml/frnog.eml | 17 - server/container/mailbox-jmx/pom.xml | 93 ++++++ .../mailbox/MailboxCopierManagement.java | 83 +++++ .../mailbox/MailboxCopierManagementMBean.java | 47 +++ .../mailbox/MailboxManagerManagement.java | 221 +++++++++++++ .../mailbox/MailboxManagerManagementMBean.java | 76 +++++ .../adapter/mailbox/MailboxManagerResolver.java | 31 ++ .../MailboxManagerResolverException.java | 35 +++ .../james/adapter/mailbox/QuotaManagement.java | 207 +++++++++++++ .../adapter/mailbox/QuotaManagementMBean.java | 50 +++ .../adapter/mailbox/ReIndexerManagement.java | 67 ++++ .../mailbox/ReIndexerManagementMBean.java | 30 ++ .../adapter/mailbox/MailboxManagementTest.java | 308 +++++++++++++++++++ .../src/test/resources/eml/frnog.eml | 17 + server/container/spring/pom.xml | 4 + server/pom.xml | 1 + .../integration/GetMailboxesMethodTest.java | 3 +- .../methods/integration/QuotaMailingTest.java | 3 +- .../methods/integration/SendMDNMethodTest.java | 3 +- .../integration/SetMessagesMethodTest.java | 2 +- 49 files changed, 1518 insertions(+), 1407 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/dockerfiles/run/guice/jpa/Dockerfile ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/jpa/Dockerfile b/dockerfiles/run/guice/jpa/Dockerfile index 913cfa9..b1dae96 100644 --- a/dockerfiles/run/guice/jpa/Dockerfile +++ b/dockerfiles/run/guice/jpa/Dockerfile @@ -27,4 +27,4 @@ ADD destination/conf /root/conf VOLUME /logs -ENTRYPOINT java -classpath '/root/james-server.jar:/root/james-server-jpa-guice.lib/*' -javaagent:/root/james-server-cli.lib/openjpa-3.0.0.jar -Dlogback.configurationFile=/root/conf/logback.xml -Dworking.directory=/root/ org.apache.james.JPAJamesServerMain +ENTRYPOINT java -classpath '/root/james-server.jar:/root/james-server-jpa-guice.lib/*' -javaagent:/root/james-server-jpa-guice.lib/openjpa-3.0.0.jar -Dlogback.configurationFile=/root/conf/logback.xml -Dworking.directory=/root/ org.apache.james.JPAJamesServerMain http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java new file mode 100644 index 0000000..302e01c --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java @@ -0,0 +1,31 @@ +/**************************************************************** + * 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.mailbox.indexer; + +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxPath; + +public interface ReIndexer { + + void reIndex(MailboxPath path) throws MailboxException; + + void reIndex() throws MailboxException; + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuota.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuota.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuota.java new file mode 100644 index 0000000..4e1ff1d --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuota.java @@ -0,0 +1,83 @@ +/**************************************************************** + * 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.mailbox.model; + +import java.io.Serializable; +import java.util.Objects; +import java.util.Optional; + +import org.apache.james.core.quota.QuotaValue; + +import com.google.common.base.MoreObjects; + +public class SerializableQuota<T extends QuotaValue<T>> implements Serializable { + + public static final long UNLIMITED = -1; + + public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(Quota<U> quota) { + return newInstance(quota.getUsed(), quota.getLimit()); + } + + public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(U used, U max) { + return new SerializableQuota<>( + new SerializableQuotaValue<>(used), + new SerializableQuotaValue<>(max) + ); + } + + private final SerializableQuotaValue<T> max; + private final SerializableQuotaValue<T> used; + + private SerializableQuota(SerializableQuotaValue<T> used, SerializableQuotaValue<T> max) { + this.max = max; + this.used = used; + } + + public Long encodeAsLong() { + return max.encodeAsLong(); + } + + public Long getUsed() { + return Optional.ofNullable(used).map(SerializableQuotaValue::encodeAsLong).orElse(null); + } + + @Override + public boolean equals(Object o) { + if (o instanceof SerializableQuota<?>) { + SerializableQuota<?> that = (SerializableQuota<?>) o; + return Objects.equals(max, that.max) && + Objects.equals(used, that.used); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(max, used); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("max", max) + .add("used", used) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuotaValue.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuotaValue.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuotaValue.java new file mode 100644 index 0000000..20689f9 --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SerializableQuotaValue.java @@ -0,0 +1,91 @@ +/**************************************************************** + * 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.mailbox.model; + +import java.io.Serializable; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +import org.apache.james.core.quota.QuotaValue; + +import com.google.common.base.MoreObjects; + +public class SerializableQuotaValue<T extends QuotaValue<T>> implements Serializable { + + public static <U extends QuotaValue<U>> SerializableQuotaValue<U> valueOf(Optional<U> input) { + return new SerializableQuotaValue<>(input.orElse(null)); + } + + public static final long UNLIMITED = -1; + + private final Long value; + + public SerializableQuotaValue(T value) { + this(encodeAsLong(value)); + } + + SerializableQuotaValue(Long value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (o instanceof SerializableQuotaValue<?>) { + SerializableQuotaValue<?> that = (SerializableQuotaValue<?>) o; + return Objects.equals(value, that.value); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("value", value) + .toString(); + } + + private static <U extends QuotaValue<U>> Long encodeAsLong(U quota) { + if (quota.isLimited()) { + return quota.asLong(); + } + return UNLIMITED; + } + + public Long encodeAsLong() { + return value; + } + + public Optional<T> toValue(Function<Long, T> factory, T unlimited) { + Long longValue = encodeAsLong(); + if (longValue == null) { + return Optional.empty(); + } + if (longValue == UNLIMITED) { + return Optional.of(unlimited); + } + return Optional.of(factory.apply(longValue)); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java deleted file mode 100644 index 486aef3..0000000 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuota.java +++ /dev/null @@ -1,84 +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.mailbox.store.mail.model; - -import java.io.Serializable; -import java.util.Objects; -import java.util.Optional; - -import org.apache.james.core.quota.QuotaValue; -import org.apache.james.mailbox.model.Quota; - -import com.google.common.base.MoreObjects; - -public class SerializableQuota<T extends QuotaValue<T>> implements Serializable { - - public static final long UNLIMITED = -1; - - public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(Quota<U> quota) { - return newInstance(quota.getUsed(), quota.getLimit()); - } - - public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(U used, U max) { - return new SerializableQuota<>( - new SerializableQuotaValue<>(used), - new SerializableQuotaValue<>(max) - ); - } - - private final SerializableQuotaValue<T> max; - private final SerializableQuotaValue<T> used; - - private SerializableQuota(SerializableQuotaValue<T> used, SerializableQuotaValue<T> max) { - this.max = max; - this.used = used; - } - - public Long encodeAsLong() { - return max.encodeAsLong(); - } - - public Long getUsed() { - return Optional.ofNullable(used).map(SerializableQuotaValue::encodeAsLong).orElse(null); - } - - @Override - public boolean equals(Object o) { - if (o instanceof SerializableQuota<?>) { - SerializableQuota<?> that = (SerializableQuota<?>) o; - return Objects.equals(max, that.max) && - Objects.equals(used, that.used); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(max, used); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("max", max) - .add("used", used) - .toString(); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuotaValue.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuotaValue.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuotaValue.java deleted file mode 100644 index bec5271..0000000 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/SerializableQuotaValue.java +++ /dev/null @@ -1,91 +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.mailbox.store.mail.model; - -import java.io.Serializable; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Function; - -import org.apache.james.core.quota.QuotaValue; - -import com.google.common.base.MoreObjects; - -public class SerializableQuotaValue<T extends QuotaValue<T>> implements Serializable { - - public static <U extends QuotaValue<U>> SerializableQuotaValue<U> valueOf(Optional<U> input) { - return new SerializableQuotaValue<>(input.orElse(null)); - } - - public static final long UNLIMITED = -1; - - private final Long value; - - public SerializableQuotaValue(T value) { - this(encodeAsLong(value)); - } - - SerializableQuotaValue(Long value) { - this.value = value; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SerializableQuotaValue<?>) { - SerializableQuotaValue<?> that = (SerializableQuotaValue<?>) o; - return Objects.equals(value, that.value); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("value", value) - .toString(); - } - - private static <U extends QuotaValue<U>> Long encodeAsLong(U quota) { - if (quota.isLimited()) { - return quota.asLong(); - } - return UNLIMITED; - } - - public Long encodeAsLong() { - return value; - } - - public Optional<T> toValue(Function<Long, T> factory, T unlimited) { - Long longValue = encodeAsLong(); - if (longValue == null) { - return Optional.empty(); - } - if (longValue == UNLIMITED) { - return Optional.of(unlimited); - } - return Optional.of(factory.apply(longValue)); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java index 451ee0e..36cdcf2 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/probe/QuotaProbe.java @@ -22,8 +22,8 @@ package org.apache.james.mailbox.store.probe; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.store.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; +import org.apache.james.mailbox.model.SerializableQuota; +import org.apache.james.mailbox.model.SerializableQuotaValue; public interface QuotaProbe { http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java ---------------------------------------------------------------------- diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java deleted file mode 100644 index 302e01c..0000000 --- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java +++ /dev/null @@ -1,31 +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.mailbox.indexer; - -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.MailboxPath; - -public interface ReIndexer { - - void reIndex(MailboxPath path) throws MailboxException; - - void reIndex() throws MailboxException; - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 87575e5..6672d97 100644 --- a/pom.xml +++ b/pom.xml @@ -1349,6 +1349,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-server-mailbox-jmx</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-mailetcontainer-api</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/cli/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/cli/pom.xml b/server/container/cli/pom.xml index b5ba568..2b18274 100644 --- a/server/container/cli/pom.xml +++ b/server/container/cli/pom.xml @@ -39,7 +39,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-mailbox-adapter</artifactId> + <artifactId>james-server-mailbox-jmx</artifactId> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>apache-james-mailbox-store</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java index bd9526a..d757ea6 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import org.apache.commons.cli.CommandLine; @@ -33,7 +34,6 @@ import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.apache.commons.lang.time.StopWatch; import org.apache.james.cli.exceptions.InvalidArgumentNumberException; import org.apache.james.cli.exceptions.JamesCliException; import org.apache.james.cli.exceptions.MissingCommandException; @@ -47,8 +47,8 @@ import org.apache.james.cli.type.CmdType; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; import org.apache.james.core.quota.QuotaValue; -import org.apache.james.mailbox.store.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; +import org.apache.james.mailbox.model.SerializableQuota; +import org.apache.james.mailbox.model.SerializableQuotaValue; import org.apache.james.mailbox.store.probe.MailboxProbe; import org.apache.james.mailbox.store.probe.QuotaProbe; import org.apache.james.probe.DataProbe; @@ -62,6 +62,7 @@ import org.slf4j.LoggerFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; +import com.google.common.base.Stopwatch; import com.google.common.base.Strings; /** @@ -110,20 +111,17 @@ public class ServerCmd { } public static void executeAndOutputToStream(String[] args, PrintStream printStream) throws Exception { - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); + Stopwatch stopWatch = Stopwatch.createStarted(); CommandLine cmd = parseCommandLine(args); JmxConnection jmxConnection = new JmxConnection(getHost(cmd), getPort(cmd)); CmdType cmdType = new ServerCmd( new JmxDataProbe().connect(jmxConnection), new JmxMailboxProbe().connect(jmxConnection), new JmxQuotaProbe().connect(jmxConnection), - new JmxSieveProbe().connect(jmxConnection) - ) + new JmxSieveProbe().connect(jmxConnection)) .executeCommandLine(cmd, printStream); - stopWatch.split(); print(new String[] { Joiner.on(' ') - .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")}, + .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.elapsed(TimeUnit.MILLISECONDS), "ms.")}, printStream); stopWatch.stop(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java index 5003645..9e0d11f 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxMailboxProbe.java @@ -27,7 +27,7 @@ import java.util.Date; import javax.mail.Flags; import javax.management.MalformedObjectNameException; -import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang3.NotImplementedException; import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; import org.apache.james.adapter.mailbox.ReIndexerManagementMBean; @@ -103,18 +103,18 @@ public class JmxMailboxProbe implements MailboxProbe, JmxProbe { @Override public Mailbox getMailbox(String namespace, String user, String name) { - throw new NotImplementedException(); + throw new NotImplementedException("Not implemented"); } @Override public ComposedMessageId appendMessage(String username, MailboxPath mailboxPath, InputStream message, Date internalDate, boolean isRecent, Flags flags) throws MailboxException { - throw new NotImplementedException(); + throw new NotImplementedException("Not implemented"); } @Override public Collection<String> listSubscriptions(String user) throws Exception { - throw new NotImplementedException(); + throw new NotImplementedException("Not implemented"); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java index fd82f8c..5bcb8e9 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxQuotaProbe.java @@ -27,8 +27,8 @@ import org.apache.james.adapter.mailbox.QuotaManagementMBean; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.store.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; +import org.apache.james.mailbox.model.SerializableQuota; +import org.apache.james.mailbox.model.SerializableQuotaValue; import org.apache.james.mailbox.store.probe.QuotaProbe; public class JmxQuotaProbe implements QuotaProbe, JmxProbe { http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java index 49119a0..b806e3b 100644 --- a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java +++ b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java @@ -37,8 +37,8 @@ import org.apache.james.cli.type.CmdType; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.model.MailboxId; -import org.apache.james.mailbox.store.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; +import org.apache.james.mailbox.model.SerializableQuota; +import org.apache.james.mailbox.model.SerializableQuotaValue; import org.apache.james.mailbox.store.probe.MailboxProbe; import org.apache.james.mailbox.store.probe.QuotaProbe; import org.apache.james.probe.DataProbe; http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/guice/jmx/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jmx/pom.xml b/server/container/guice/jmx/pom.xml index 5dd7791..5487e34 100644 --- a/server/container/guice/jmx/pom.xml +++ b/server/container/guice/jmx/pom.xml @@ -50,7 +50,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-mailbox-adapter</artifactId> + <artifactId>james-server-mailbox-jmx</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java index 40c48c6..f428c51 100644 --- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java +++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java @@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import org.apache.james.core.quota.QuotaSize; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; +import org.apache.james.mailbox.model.SerializableQuotaValue; import org.apache.james.modules.QuotaProbesImpl; import org.apache.james.modules.protocols.ImapGuiceProbe; import org.apache.james.modules.protocols.SmtpGuiceProbe; http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/guice/mailbox/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox/pom.xml b/server/container/guice/mailbox/pom.xml index b340af6..86a49aa 100644 --- a/server/container/guice/mailbox/pom.xml +++ b/server/container/guice/mailbox/pom.xml @@ -49,6 +49,10 @@ <artifactId>james-server-guice-utils</artifactId> </dependency> <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>james-server-mailbox-adapter</artifactId> + </dependency> + <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java index 18d1cfb..0ac0d9e 100644 --- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java +++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java @@ -25,11 +25,11 @@ import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.SerializableQuota; +import org.apache.james.mailbox.model.SerializableQuotaValue; 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.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; import org.apache.james.mailbox.store.probe.QuotaProbe; import org.apache.james.utils.GuiceProbe; http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java deleted file mode 100644 index 7769bc3..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java +++ /dev/null @@ -1,83 +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.adapter.mailbox; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.james.mailbox.MailboxManager; -import org.apache.james.mailbox.copier.MailboxCopier; -import org.apache.james.mailbox.exception.MailboxException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * {@link MailboxCopier} support via JMX - */ -public class MailboxCopierManagement implements MailboxCopierManagementMBean { - - /** - * The Logger. - */ - private static final Logger log = LoggerFactory.getLogger(MailboxCopierManagement.class.getName()); - - private MailboxCopier copier; - private MailboxManagerResolver resolver; - - @Inject - public void setMailboxCopier(@Named("mailboxcopier") MailboxCopier copier) { - this.copier = copier; - } - - @Inject - public void setMailboxManagerResolver(MailboxManagerResolver resolver) { - this.resolver = resolver; - } - - @Override - public Map<String, String> getMailboxManagerBeans() { - Map<String, String> bMap = new HashMap<>(); - Map<String, MailboxManager> beans = resolver.getMailboxManagerBeans(); - - for (Map.Entry<String, MailboxManager> entry : beans.entrySet()) { - String name = entry.getValue().getClass().getName(); - bMap.put(entry.getKey(), name); - } - - return bMap; - } - - @Override - public void copy(String srcBean, String dstBean) throws Exception { - if (srcBean.equals(dstBean)) { - throw new IllegalArgumentException("srcBean and dstBean can not have the same name!"); - } - try { - copier.copyMailboxes(resolver.resolveMailboxManager(srcBean), resolver.resolveMailboxManager(dstBean)); - } catch (MailboxManagerResolverException | MailboxException | IOException e) { - log.error("An exception occured during the copy process", e); - throw new Exception(e.getMessage()); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java deleted file mode 100644 index e60e78d..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java +++ /dev/null @@ -1,47 +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.adapter.mailbox; - -import java.util.Map; - -/** - * Allow to copy {@link MailboxManager} contents from one to the other via JMX - */ -public interface MailboxCopierManagementMBean { - - /** - * Return a {@link Map} which contains the bean name of the registered - * {@link MailboxManager} instances as keys and the classname of them as - * values - * - * @return managers - */ - Map<String, String> getMailboxManagerBeans(); - - /** - * Copy from srcBean to dstBean all messages - * - * @param srcBean - * @param dstBean - * @throws Exception - * if copying failed - */ - void copy(String srcBean, String dstBean) throws Exception; - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java deleted file mode 100644 index 79d68db..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java +++ /dev/null @@ -1,221 +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.adapter.mailbox; - -import java.io.Closeable; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.management.NotCompliantMBeanException; -import javax.management.StandardMBean; - -import org.apache.james.mailbox.MailboxManager; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.MessageManager; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.MailboxId; -import org.apache.james.mailbox.model.MailboxMetaData; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.model.search.MailboxQuery; -import org.apache.james.util.MDCBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.github.steveash.guavate.Guavate; -import com.google.common.base.Preconditions; - -/** - * JMX managmenent for Mailboxes - */ -public class MailboxManagerManagement extends StandardMBean implements MailboxManagerManagementMBean { - private static final Logger LOGGER = LoggerFactory.getLogger(MailboxManagerManagement.class); - - private MailboxManager mailboxManager; - - @Inject - public void setMailboxManager(@Named("mailboxmanager") MailboxManager mailboxManager) { - this.mailboxManager = mailboxManager; - } - - public MailboxManagerManagement() throws NotCompliantMBeanException { - super(MailboxManagerManagementMBean.class); - } - - @Override - public boolean deleteMailboxes(String username) { - checkString(username, "Username"); - MailboxSession session = null; - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "deleteMailboxes") - .addContext("concernedUser", username) - .build()) { - session = mailboxManager.createSystemSession(username); - mailboxManager.startProcessingRequest(session); - List<MailboxMetaData> mList = retrieveAllUserMailboxes(session); - for (MailboxMetaData aMList : mList) { - mailboxManager.deleteMailbox(aMList.getPath(), session); - } - return true; - } catch (MailboxException e) { - LOGGER.error("Error while remove mailboxes for user {}", username, e); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - closeSession(session); - } - return false; - } - - @Override - public List<String> listMailboxes(String username) { - checkString(username, "Username"); - List<String> boxes = new ArrayList<>(); - MailboxSession session = null; - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "listMailboxes") - .addContext("concernedUser", username) - .build()) { - session = mailboxManager.createSystemSession(username); - mailboxManager.startProcessingRequest(session); - List<MailboxMetaData> mList = retrieveAllUserMailboxes(session); - boxes = mList.stream() - .map(aMList -> aMList.getPath().getName()) - .sorted() - .collect(Guavate.toImmutableList()); - } catch (MailboxException e) { - LOGGER.error("Error list mailboxes for user {}", username, e); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - closeSession(session); - } - return boxes; - } - - @Override - public MailboxId createMailbox(String namespace, String user, String name) { - checkMailboxArguments(namespace, user, name); - MailboxSession session = null; - MailboxPath mailboxPath = new MailboxPath(namespace, user, name); - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "createMailbox") - .addContext("mailboxPath", mailboxPath.asString()) - .build()) { - session = mailboxManager.createSystemSession(user); - mailboxManager.startProcessingRequest(session); - return mailboxManager.createMailbox(mailboxPath, session) - .orElseThrow(() -> new MailboxException("mailbox name is probably empty")); - } catch (Exception e) { - LOGGER.error("Unable to create mailbox", e); - throw new RuntimeException(e); - } finally { - closeSession(session); - } - } - - @Override - public void deleteMailbox(String namespace, String user, String name) { - checkMailboxArguments(namespace, user, name); - MailboxSession session = null; - MailboxPath mailboxPath = new MailboxPath(namespace, user, name); - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "deleteMailbox") - .addContext("mailboxPath", mailboxPath.asString()) - .build()) { - session = mailboxManager.createSystemSession(user); - mailboxManager.startProcessingRequest(session); - mailboxManager.deleteMailbox(mailboxPath, session); - } catch (Exception e) { - LOGGER.error("Unable to create mailbox", e); - } finally { - closeSession(session); - } - } - - @Override - public void importEmlFileToMailbox(String namespace, String user, String name, String emlPath) { - checkMailboxArguments(namespace, user, name); - checkString(emlPath, "email file path name"); - - MailboxSession session = null; - MailboxPath mailboxPath = new MailboxPath(namespace, user, name); - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "importEmlFileToMailbox") - .addContext("mailboxPath", mailboxPath.asString()) - .addContext("emlPath", emlPath) - .build()) { - session = mailboxManager.createSystemSession(user); - mailboxManager.startProcessingRequest(session); - MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, session); - InputStream emlFileAsStream = new FileInputStream(emlPath); - messageManager.appendMessage(MessageManager.AppendCommand.builder() - .recent() - .build(emlFileAsStream), session); - } catch (Exception e) { - LOGGER.error("Unable to create mailbox", e); - } finally { - closeSession(session); - } - } - - private void closeSession(MailboxSession session) { - if (session != null) { - mailboxManager.endProcessingRequest(session); - try { - mailboxManager.logout(session, true); - } catch (MailboxException e) { - LOGGER.error("Can not log session out", e); - } - } - } - - private List<MailboxMetaData> retrieveAllUserMailboxes(MailboxSession session) throws MailboxException { - return mailboxManager.search( - MailboxQuery.privateMailboxesBuilder(session) - .matchesAllMailboxNames() - .build(), - session); - } - - private void checkMailboxArguments(String namespace, String user, String name) { - checkString(namespace, "mailbox path namespace"); - checkString(user, "mailbox path user"); - checkString(name, "mailbox name"); - } - - private void checkString(String argument, String role) { - Preconditions.checkNotNull(argument, "Provided " + role + " should not be null."); - Preconditions.checkArgument(!argument.equals(""), "Provided " + role + " should not be empty."); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java deleted file mode 100644 index ca96dca..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java +++ /dev/null @@ -1,76 +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.adapter.mailbox; - -import java.util.List; - -import org.apache.james.mailbox.model.MailboxId; - -/** - * JMX MBean for Mailbox management - */ -public interface MailboxManagerManagementMBean { - - /** - * Delete all Mailboxes which belong to the user - * - * @param username - * @return successful - */ - boolean deleteMailboxes(String username); - - /** - * List all mailboxes for a user - * - * @param username - * @return mailboxes - */ - List<String> listMailboxes(String username); - - /** - * Create a mailbox - * @param namespace Namespace of the created mailbox - * @param user User of the created mailbox - * @param name Name of the created mailbox - */ - MailboxId createMailbox(String namespace, String user, String name); - - /** - * Delete the given mailbox - * - * @param namespace Namespace of the mailbox to delete - * @param user User the mailbox to delete belongs to - * @param name Name of the mailbox to delete - */ - void deleteMailbox(String namespace, String user, String name); - - /** - * Import Eml File to the given mailbox - * - * @param namespace - * Namespace of the mailbox to import email file - * @param user - * User the mailbox to import email file belongs to - * @param name - * Name of the mailbox to import email file - * @param emlpath - * Name of the email file of this URL - */ - void importEmlFileToMailbox(String namespace, String user, String name, String emlpath); -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java deleted file mode 100644 index 46c2088..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java +++ /dev/null @@ -1,31 +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.adapter.mailbox; - -import java.util.Map; - -import org.apache.james.mailbox.MailboxManager; - -public interface MailboxManagerResolver { - - MailboxManager resolveMailboxManager(String mailboxManagerClassName); - - Map<String, MailboxManager> getMailboxManagerBeans(); - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java deleted file mode 100644 index d80f3ca..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java +++ /dev/null @@ -1,35 +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.adapter.mailbox; - -public class MailboxManagerResolverException extends RuntimeException { - - public MailboxManagerResolverException() { - super(); - } - - public MailboxManagerResolverException(Throwable cause) { - super(cause); - } - - public MailboxManagerResolverException(String message) { - super(message); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java deleted file mode 100644 index 25fef15..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java +++ /dev/null @@ -1,207 +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.adapter.mailbox; - -import java.io.Closeable; -import java.io.IOException; - -import javax.inject.Inject; - -import org.apache.james.core.quota.QuotaCount; -import org.apache.james.core.quota.QuotaSize; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.MailboxPath; -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.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; -import org.apache.james.util.MDCBuilder; - -import com.github.fge.lambdas.Throwing; - -public class QuotaManagement implements QuotaManagementMBean { - - private final QuotaManager quotaManager; - private final MaxQuotaManager maxQuotaManager; - private final QuotaRootResolver quotaRootResolver; - - @Inject - public QuotaManagement(QuotaManager quotaManager, MaxQuotaManager maxQuotaManager, QuotaRootResolver quotaRootResolver) { - this.quotaManager = quotaManager; - this.maxQuotaManager = maxQuotaManager; - this.quotaRootResolver = quotaRootResolver; - } - - @Override - public String getQuotaRoot(String namespace, String user, String name) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getQuotaRoot") - .build()) { - return quotaRootResolver.getQuotaRoot(new MailboxPath(namespace, user, name)).getValue(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getMaxMessageCount") - .build()) { - return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxMessage(quotaRootResolver.fromString(quotaRoot))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getMaxStorage") - .build()) { - return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxStorage(quotaRootResolver.fromString(quotaRoot))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuotaValue<QuotaCount> getGlobalMaxMessageCount() throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getGlobalMaxMessageCount") - .build()) { - return SerializableQuotaValue.valueOf(maxQuotaManager.getGlobalMaxMessage()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuotaValue<QuotaSize> getGlobalMaxStorage() throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getGlobalMaxStorage") - .build()) { - return SerializableQuotaValue.valueOf(maxQuotaManager.getGlobalMaxStorage()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "setMaxMessageCount") - .build()) { - maxMessageCount.toValue(QuotaCount::count, QuotaCount.unlimited()) - .ifPresent( - Throwing.consumer((QuotaCount value) -> - maxQuotaManager.setMaxMessage(quotaRootResolver.fromString(quotaRoot), value)) - .sneakyThrow()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "setMaxStorage") - .build()) { - maxSize.toValue(QuotaSize::size, QuotaSize.unlimited()) - .ifPresent( - Throwing.consumer((QuotaSize value) -> - maxQuotaManager.setMaxStorage(quotaRootResolver.fromString(quotaRoot), value)) - .sneakyThrow()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setGlobalMaxMessageCount(SerializableQuotaValue<QuotaCount> maxGlobalMessageCount) { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "setGlobalMaxMessageCount") - .build()) { - maxGlobalMessageCount - .toValue(QuotaCount::count, QuotaCount.unlimited()) - .ifPresent(Throwing.consumer(maxQuotaManager::setGlobalMaxMessage).sneakyThrow()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void setGlobalMaxStorage(SerializableQuotaValue<QuotaSize> maxGlobalSize) { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "setGlobalMaxStorage") - .build()) { - maxGlobalSize - .toValue(QuotaSize::size, QuotaSize.unlimited()) - .ifPresent(Throwing.consumer(maxQuotaManager::setGlobalMaxStorage).sneakyThrow()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuota<QuotaCount> getMessageCountQuota(String quotaRoot) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getMessageCountQuota") - .build()) { - return SerializableQuota.newInstance(quotaManager.getMessageQuota(quotaRootResolver.fromString(quotaRoot))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "getStorageQuota") - .build()) { - return SerializableQuota.newInstance(quotaManager.getStorageQuota(quotaRootResolver.fromString(quotaRoot))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java deleted file mode 100644 index 5263988..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java +++ /dev/null @@ -1,50 +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.adapter.mailbox; - -import org.apache.james.core.quota.QuotaCount; -import org.apache.james.core.quota.QuotaSize; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.store.mail.model.SerializableQuota; -import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; - -public interface QuotaManagementMBean { - String getQuotaRoot(String namespace, String user, String name) throws MailboxException; - - SerializableQuota<QuotaCount> getMessageCountQuota(String quotaRoot) throws MailboxException; - - SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException; - - SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException; - - SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException; - - SerializableQuotaValue<QuotaCount> getGlobalMaxMessageCount() throws MailboxException; - - SerializableQuotaValue<QuotaSize> getGlobalMaxStorage() throws MailboxException; - - void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException; - - void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException; - - void setGlobalMaxMessageCount(SerializableQuotaValue<QuotaCount> maxGlobalMessageCount) throws MailboxException; - - void setGlobalMaxStorage(SerializableQuotaValue<QuotaSize> maxGlobalSize) throws MailboxException; -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java deleted file mode 100644 index c5110a8..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java +++ /dev/null @@ -1,67 +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.adapter.mailbox; - -import java.io.Closeable; -import java.io.IOException; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.indexer.ReIndexer; -import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.util.MDCBuilder; - -public class ReIndexerManagement implements ReIndexerManagementMBean { - - private ReIndexer reIndexer; - - @Inject - public void setReIndexer(@Named("reindexer") ReIndexer reIndexer) { - this.reIndexer = reIndexer; - } - - @Override - public void reIndex(String namespace, String user, String name) throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "reIndex") - .build()) { - reIndexer.reIndex(new MailboxPath(namespace, user, name)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void reIndex() throws MailboxException { - try (Closeable closeable = - MDCBuilder.create() - .addContext(MDCBuilder.PROTOCOL, "CLI") - .addContext(MDCBuilder.ACTION, "reIndex") - .build()) { - reIndexer.reIndex(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java deleted file mode 100644 index ec923ae..0000000 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java +++ /dev/null @@ -1,30 +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.adapter.mailbox; - -import org.apache.james.mailbox.exception.MailboxException; - -public interface ReIndexerManagementMBean { - - void reIndex(String namespace, String user, String name) throws MailboxException; - - void reIndex() throws MailboxException; - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
