JAMES-2344 Handle unlimited quota values in cli
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/63b010d7 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/63b010d7 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/63b010d7 Branch: refs/heads/master Commit: 63b010d78051b4ffc24724108c167f998093d970 Parents: 2d57cf1 Author: Raphael Ouazana <[email protected]> Authored: Fri Mar 2 18:01:56 2018 +0100 Committer: Raphael Ouazana <[email protected]> Committed: Thu Mar 8 09:29:51 2018 +0100 ---------------------------------------------------------------------- .../store/mail/model/SerializableQuota.java | 53 ++++++--- .../mail/model/SerializableQuotaValue.java | 91 +++++++++++++++ .../james/mailbox/store/probe/QuotaProbe.java | 19 ++-- .../james/cli/QuotaCommandsIntegrationTest.java | 8 +- .../java/org/apache/james/cli/ServerCmd.java | 47 ++++++-- .../james/cli/probe/impl/JmxQuotaProbe.java | 18 +-- .../org/apache/james/cli/ServerCmdTest.java | 110 +++++++++++++++++-- .../apache/james/modules/QuotaProbesImpl.java | 53 +++++---- .../james/adapter/mailbox/QuotaManagement.java | 51 +++++---- .../adapter/mailbox/QuotaManagementMBean.java | 19 ++-- 10 files changed, 359 insertions(+), 110 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 index 25370be..b090cf7 100644 --- 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 @@ -20,45 +20,64 @@ 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.mailbox.model.Quota; import org.apache.james.mailbox.quota.QuotaValue; +import com.google.common.base.MoreObjects; + public class SerializableQuota<T extends QuotaValue<T>> implements Serializable { public static final long UNLIMITED = -1; - private final Long max; - private final Long used; + public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(Quota<U> quota) { + return new SerializableQuota<>(new SerializableQuotaValue<>(quota.getMax()), getUsed(quota.getUsed(), SerializableQuotaValue::new)); + } + + + private static <U extends QuotaValue<U>> SerializableQuotaValue<U> getUsed(Optional<U> quota, Function<U, SerializableQuotaValue<U>> factory) { + return quota.map(factory).orElse(null); + } + + private final SerializableQuotaValue<T> max; + private final SerializableQuotaValue<T> used; - public SerializableQuota(Long max, Long used) { + public SerializableQuota(SerializableQuotaValue<T> max, SerializableQuotaValue<T> used) { this.max = max; this.used = used; } - public SerializableQuota(Quota<T> quota) { - this.max = encodeAsLong(quota.getMax()); - this.used = getUsed(quota.getUsed()); + public Long encodeAsLong() { + return max.encodeAsLong(); } - private Long getUsed(Optional<T> quota) { - return quota.map(this::encodeAsLong).orElse(null); + public Long getUsed() { + return Optional.ofNullable(used).map(SerializableQuotaValue::encodeAsLong).orElse(null); } - private Long encodeAsLong(T quota) { - if (quota.isLimited()) { - return quota.asLong(); + @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 UNLIMITED; + return false; } - public Long encodeAsLong() { - return max; + @Override + public int hashCode() { + return Objects.hash(max, used); } - public Long getUsed() { - return 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/63b010d7/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 new file mode 100644 index 0000000..1773464 --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/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.store.mail.model; + +import java.io.Serializable; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +import org.apache.james.mailbox.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/63b010d7/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 ec242be..8747dae 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 @@ -19,12 +19,11 @@ package org.apache.james.mailbox.store.probe; -import java.util.Optional; - import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; import org.apache.james.mailbox.store.mail.model.SerializableQuota; +import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue; public interface QuotaProbe { @@ -34,20 +33,20 @@ public interface QuotaProbe { SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException; - Optional<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException; + SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException; - Optional<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException; + SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException; - Optional<QuotaCount> getDefaultMaxMessageCount() throws MailboxException; + SerializableQuotaValue<QuotaCount> getDefaultMaxMessageCount() throws MailboxException; - Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException; + SerializableQuotaValue<QuotaSize> getDefaultMaxStorage() throws MailboxException; - void setMaxMessageCount(String quotaRoot, QuotaCount maxMessageCount) throws MailboxException; + void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException; - void setMaxStorage(String quotaRoot, QuotaSize maxSize) throws MailboxException; + void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException; - void setDefaultMaxMessageCount(QuotaCount maxDefaultMessageCount) throws MailboxException; + void setDefaultMaxMessageCount(SerializableQuotaValue<QuotaCount> maxDefaultMessageCount) throws MailboxException; - void setDefaultMaxStorage(QuotaSize maxDefaultSize) throws MailboxException; + void setDefaultMaxStorage(SerializableQuotaValue<QuotaSize> maxDefaultSize) throws MailboxException; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java index fc8fb7a..6875461 100644 --- a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java @@ -62,7 +62,7 @@ public class QuotaCommandsIntegrationTest { public void setDefaultMaxStorageShouldWork() throws Exception { ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxstoragequota", "36"}); - assertThat(quotaProbe.getDefaultMaxStorage()).isEqualTo(36); + assertThat(quotaProbe.getDefaultMaxStorage().encodeAsLong()).isEqualTo(36); } @Test @@ -80,7 +80,7 @@ public class QuotaCommandsIntegrationTest { public void setDefaultMaxMessageCountShouldWork() throws Exception { ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxmessagecountquota", "36"}); - assertThat(quotaProbe.getDefaultMaxMessageCount()).isEqualTo(36); + assertThat(quotaProbe.getDefaultMaxMessageCount().encodeAsLong()).isEqualTo(36); } @Test @@ -98,7 +98,7 @@ public class QuotaCommandsIntegrationTest { public void setMaxStorageShouldWork() throws Exception { ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxstoragequota", QUOTA_ROOT.getValue(), "36"}); - assertThat(quotaProbe.getMaxStorage(QUOTA_ROOT.getValue())).isEqualTo(36); + assertThat(quotaProbe.getMaxStorage(QUOTA_ROOT.getValue()).encodeAsLong()).isEqualTo(36); } @Test @@ -116,7 +116,7 @@ public class QuotaCommandsIntegrationTest { public void setMaxMessageCountShouldWork() throws Exception { ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxmessagecountquota", QUOTA_ROOT.getValue(), "36"}); - assertThat(quotaProbe.getMaxMessageCount(QUOTA_ROOT.getValue())).isEqualTo(36); + assertThat(quotaProbe.getMaxMessageCount(QUOTA_ROOT.getValue()).encodeAsLong()).isEqualTo(36); } @Test http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 54e4eaf..f937857 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.function.Function; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -47,7 +48,9 @@ import org.apache.james.cli.type.CmdType; import org.apache.james.cli.utils.ValueWithUnit; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; +import org.apache.james.mailbox.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.store.probe.MailboxProbe; import org.apache.james.mailbox.store.probe.QuotaProbe; import org.apache.james.mailbox.store.probe.SieveProbe; @@ -285,16 +288,16 @@ public class ServerCmd { printStream.println("MailboxMessage count allowed for Quota Root " + arguments[1] + ": " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1]))); break; case SETMAXSTORAGEQUOTA: - quotaProbe.setMaxStorage(arguments[1], QuotaSize.size(ValueWithUnit.parse(arguments[2]).getConvertedValue())); + quotaProbe.setMaxStorage(arguments[1], parseQuotaSize(arguments[2])); break; case SETMAXMESSAGECOUNTQUOTA: - quotaProbe.setMaxMessageCount(arguments[1], QuotaCount.count(Long.parseLong(arguments[2]))); + quotaProbe.setMaxMessageCount(arguments[1], parseQuotaCount(arguments[2])); break; case SETDEFAULTMAXSTORAGEQUOTA: - quotaProbe.setDefaultMaxStorage(QuotaSize.size(ValueWithUnit.parse(arguments[1]).getConvertedValue())); + quotaProbe.setDefaultMaxStorage(parseQuotaSize(arguments[1])); break; case SETDEFAULTMAXMESSAGECOUNTQUOTA: - quotaProbe.setDefaultMaxMessageCount(QuotaCount.count(Long.parseLong(arguments[1]))); + quotaProbe.setDefaultMaxMessageCount(parseQuotaCount(arguments[1])); break; case GETDEFAULTMAXSTORAGEQUOTA: printStream.println("Default Maximum Storage Quota: " + formatStorageValue(quotaProbe.getDefaultMaxStorage())); @@ -335,6 +338,30 @@ public class ServerCmd { } } + private SerializableQuotaValue<QuotaSize> parseQuotaSize(String argument) throws Exception { + long convertedValue = ValueWithUnit.parse(argument).getConvertedValue(); + return longToSerializableQuotaValue(convertedValue, QuotaSize.unlimited(), QuotaSize::size); + } + + private SerializableQuotaValue<QuotaCount> parseQuotaCount(String argument) { + long value = Long.parseLong(argument); + return longToSerializableQuotaValue(value, QuotaCount.unlimited(), QuotaCount::count); + } + + private <T extends QuotaValue<T>> SerializableQuotaValue<T> longToSerializableQuotaValue(long value, T unlimited, Function<Long, T> factory) { + return SerializableQuotaValue.valueOf(Optional.of(longToQuotaValue(value, unlimited, factory))); + } + + private <T extends QuotaValue<T>> T longToQuotaValue(long value, T unlimited, Function<Long, T> factory) { + if (value == -1) { + return unlimited; + } + if (value >= 0) { + return factory.apply(value); + } + throw new IllegalArgumentException("Quota should be -1 for unlimited or a positive value"); + } + private static void print(String[] data, PrintStream out) { print(Arrays.asList(data), out); } @@ -369,8 +396,10 @@ public class ServerCmd { return FileUtils.byteCountToDisplaySize(value); } - private String formatStorageValue(Optional<QuotaSize> value) { - return value.map(size -> { + private String formatStorageValue(SerializableQuotaValue<QuotaSize> value) { + return value + .toValue(QuotaSize::size, QuotaSize.unlimited()) + .map(size -> { if (size.isUnlimited()) { return ValueWithUnit.UNLIMITED; } @@ -388,8 +417,10 @@ public class ServerCmd { return String.valueOf(value); } - private String formatMessageValue(Optional<QuotaCount> value) { - return value.map(count -> { + private String formatMessageValue(SerializableQuotaValue<QuotaCount> value) { + return value + .toValue(QuotaCount::count, QuotaCount.unlimited()) + .map(count -> { if (count.isUnlimited()) { return ValueWithUnit.UNLIMITED; } http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 a03c89a..ff27f48 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 @@ -20,7 +20,6 @@ package org.apache.james.cli.probe.impl; import java.io.IOException; -import java.util.Optional; import javax.management.MalformedObjectNameException; @@ -29,6 +28,7 @@ import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; 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; public class JmxQuotaProbe implements QuotaProbe, JmxProbe { @@ -61,42 +61,42 @@ public class JmxQuotaProbe implements QuotaProbe, JmxProbe { } @Override - public Optional<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { + public SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { return quotaManagement.getMaxMessageCount(quotaRoot); } @Override - public Optional<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { + public SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { return quotaManagement.getMaxStorage(quotaRoot); } @Override - public Optional<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { + public SerializableQuotaValue<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { return quotaManagement.getDefaultMaxMessageCount(); } @Override - public Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException { + public SerializableQuotaValue<QuotaSize> getDefaultMaxStorage() throws MailboxException { return quotaManagement.getDefaultMaxStorage(); } @Override - public void setMaxMessageCount(String quotaRoot, QuotaCount maxMessageCount) throws MailboxException { + public void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException { quotaManagement.setMaxMessageCount(quotaRoot, maxMessageCount); } @Override - public void setMaxStorage(String quotaRoot, QuotaSize maxSize) throws MailboxException { + public void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException { quotaManagement.setMaxStorage(quotaRoot, maxSize); } @Override - public void setDefaultMaxMessageCount(QuotaCount maxDefaultMessageCount) throws MailboxException { + public void setDefaultMaxMessageCount(SerializableQuotaValue<QuotaCount> maxDefaultMessageCount) throws MailboxException { quotaManagement.setDefaultMaxMessageCount(maxDefaultMessageCount); } @Override - public void setDefaultMaxStorage(QuotaSize maxDefaultSize) throws MailboxException { + public void setDefaultMaxStorage(SerializableQuotaValue<QuotaSize> maxDefaultSize) throws MailboxException { quotaManagement.setDefaultMaxStorage(maxDefaultSize); } http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 37d15de..e9a5d98 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 @@ -27,7 +27,6 @@ import static org.easymock.EasyMock.expectLastCall; import java.util.ArrayList; import java.util.HashMap; -import java.util.Optional; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.ParseException; @@ -40,6 +39,7 @@ import org.apache.james.mailbox.model.Quota; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; 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.MailboxProbe; import org.apache.james.mailbox.store.probe.QuotaProbe; import org.apache.james.mailbox.store.probe.SieveProbe; @@ -384,7 +384,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETDEFAULTMAXMESSAGECOUNTQUOTA.getCommand()}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getDefaultMaxMessageCount()).andReturn(Optional.of(QuotaCount.count(1024L * 1024L))); + expect(quotaProbe.getDefaultMaxMessageCount()).andReturn(new SerializableQuotaValue<>(QuotaCount.count(1024L * 1024L))); control.replay(); testee.executeCommandLine(commandLine); @@ -396,7 +396,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETDEFAULTMAXSTORAGEQUOTA.getCommand()}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getDefaultMaxStorage()).andReturn(Optional.of(QuotaSize.size(1024L * 1024L * 1024L))); + expect(quotaProbe.getDefaultMaxStorage()).andReturn(new SerializableQuotaValue<>(QuotaSize.size(1024L * 1024L * 1024L))); control.replay(); testee.executeCommandLine(commandLine); @@ -408,7 +408,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETDEFAULTMAXMESSAGECOUNTQUOTA.getCommand(), "1054"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - quotaProbe.setDefaultMaxMessageCount(QuotaCount.count(1054)); + quotaProbe.setDefaultMaxMessageCount(new SerializableQuotaValue<>(QuotaCount.count(1054))); expectLastCall(); control.replay(); @@ -417,11 +417,45 @@ public class ServerCmdTest { } @Test + public void setDefaultMaxMessageCountCommandShouldWorkWhenUnlimited() throws Exception { + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETDEFAULTMAXMESSAGECOUNTQUOTA.getCommand(), "-1"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + quotaProbe.setDefaultMaxMessageCount(new SerializableQuotaValue<>(QuotaCount.unlimited())); + expectLastCall(); + + control.replay(); + testee.executeCommandLine(commandLine); + control.verify(); + } + + @Test(expected = IllegalArgumentException.class) + public void setDefaultMaxMessageCountCommandShouldThrowWhenNegativeAndNotUnlimited() throws Exception { + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETDEFAULTMAXMESSAGECOUNTQUOTA.getCommand(), "-2"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + testee.executeCommandLine(commandLine); + } + + @Test public void setDefaultMaxStorageCommandShouldWork() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETDEFAULTMAXSTORAGEQUOTA.getCommand(), "1G"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - quotaProbe.setDefaultMaxStorage(QuotaSize.size(1024 * 1024 * 1024)); + quotaProbe.setDefaultMaxStorage(new SerializableQuotaValue<>(QuotaSize.size(1024 * 1024 * 1024))); + expectLastCall(); + + control.replay(); + testee.executeCommandLine(commandLine); + control.verify(); + } + + @Test + public void setDefaultMaxStorageCommandShouldWorkWhenUnlimited() throws Exception { + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETDEFAULTMAXSTORAGEQUOTA.getCommand(), "-1"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + quotaProbe.setDefaultMaxStorage(new SerializableQuotaValue<>(QuotaSize.unlimited())); expectLastCall(); control.replay(); @@ -429,13 +463,35 @@ public class ServerCmdTest { control.verify(); } + @Test(expected = IllegalArgumentException.class) + public void setDefaultMaxStorageCommandShouldThrowWhenNegativeAndNotUnlimited() throws Exception { + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETDEFAULTMAXSTORAGEQUOTA.getCommand(), "-2"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + testee.executeCommandLine(commandLine); + } + @Test public void setMaxMessageCountCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot, "1000"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - quotaProbe.setMaxMessageCount(quotaroot, QuotaCount.count(1000)); + quotaProbe.setMaxMessageCount(quotaroot, new SerializableQuotaValue<>(QuotaCount.count(1000))); + expectLastCall(); + + control.replay(); + testee.executeCommandLine(commandLine); + control.verify(); + } + + @Test + public void setMaxMessageCountCommandShouldWorkWhenUnlimited() throws Exception { + String quotaroot = "#private&user@domain"; + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot, "-1"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + quotaProbe.setMaxMessageCount(quotaroot, new SerializableQuotaValue<>(QuotaCount.unlimited())); expectLastCall(); control.replay(); @@ -443,13 +499,36 @@ public class ServerCmdTest { control.verify(); } + @Test(expected = IllegalArgumentException.class) + public void setMaxMessageCountCommandShouldThrowWhenNegativeAndNotUnlimited() throws Exception { + String quotaroot = "#private&user@domain"; + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot, "-2"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + testee.executeCommandLine(commandLine); + } + @Test public void setMaxStorageCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETMAXSTORAGEQUOTA.getCommand(), quotaroot, "5M"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - quotaProbe.setMaxStorage(quotaroot, QuotaSize.size(5 * 1024 * 1024)); + quotaProbe.setMaxStorage(quotaroot, new SerializableQuotaValue<>(QuotaSize.size(5 * 1024 * 1024))); + expectLastCall(); + + control.replay(); + testee.executeCommandLine(commandLine); + control.verify(); + } + + @Test + public void setMaxStorageCommandShouldWorkWhenUnlimited() throws Exception { + String quotaroot = "#private&user@domain"; + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXSTORAGEQUOTA.getCommand(), quotaroot, "-1"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + quotaProbe.setMaxStorage(quotaroot, new SerializableQuotaValue<>(QuotaSize.unlimited())); expectLastCall(); control.replay(); @@ -457,13 +536,22 @@ public class ServerCmdTest { control.verify(); } + @Test(expected = IllegalArgumentException.class) + public void setMaxStorageCommandShouldThrowWhenNegativeAndNotUnlimited() throws Exception { + String quotaroot = "#private&user@domain"; + String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXSTORAGEQUOTA.getCommand(), quotaroot, "-2"}; + CommandLine commandLine = ServerCmd.parseCommandLine(arguments); + + testee.executeCommandLine(commandLine); + } + @Test public void getMaxMessageCountCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getMaxMessageCount(quotaroot)).andReturn(Optional.of(QuotaCount.unlimited())); + expect(quotaProbe.getMaxMessageCount(quotaroot)).andReturn(new SerializableQuotaValue<>(QuotaCount.unlimited())); control.replay(); testee.executeCommandLine(commandLine); @@ -476,7 +564,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETMAXSTORAGEQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getMaxStorage(quotaroot)).andReturn(Optional.of(QuotaSize.unlimited())); + expect(quotaProbe.getMaxStorage(quotaroot)).andReturn(new SerializableQuotaValue<>(QuotaSize.unlimited())); control.replay(); testee.executeCommandLine(commandLine); @@ -489,7 +577,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETSTORAGEQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getStorageQuota(quotaroot)).andReturn(new SerializableQuota<>(Quota.unknownUsedQuota(QuotaSize.unlimited()))); + expect(quotaProbe.getStorageQuota(quotaroot)).andReturn(SerializableQuota.newInstance(Quota.unknownUsedQuota(QuotaSize.unlimited()))); control.replay(); testee.executeCommandLine(commandLine); @@ -502,7 +590,7 @@ public class ServerCmdTest { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETMESSAGECOUNTQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); - expect(quotaProbe.getMessageCountQuota(quotaroot)).andReturn(new SerializableQuota<>(Quota.unknownUsedQuota(QuotaCount.unlimited()))); + expect(quotaProbe.getMessageCountQuota(quotaroot)).andReturn(SerializableQuota.newInstance(Quota.unknownUsedQuota(QuotaCount.unlimited()))); control.replay(); testee.executeCommandLine(commandLine); http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 8e42a7c..4f7dad5 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 @@ -19,8 +19,6 @@ package org.apache.james.modules; -import java.util.Optional; - import javax.inject.Inject; import org.apache.james.mailbox.exception.MailboxException; @@ -31,9 +29,12 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.quota.QuotaSize; 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; +import com.github.fge.lambdas.Throwing; + public class QuotaProbesImpl implements QuotaProbe, GuiceProbe { private final MaxQuotaManager maxQuotaManager; @@ -54,53 +55,61 @@ public class QuotaProbesImpl implements QuotaProbe, GuiceProbe { @Override public SerializableQuota<QuotaCount> getMessageCountQuota(String quotaRoot) throws MailboxException { - return new SerializableQuota<>(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); + return SerializableQuota.newInstance(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); } @Override public SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException { - return new SerializableQuota<>(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); + return SerializableQuota.newInstance(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); } @Override - public Optional<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { - return maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot)); + public SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { + return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot))); } @Override - public Optional<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { - return maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot)); + public SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { + return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot))); } @Override - public Optional<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { - return maxQuotaManager.getDefaultMaxMessage(); + public SerializableQuotaValue<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { + return SerializableQuotaValue.valueOf(maxQuotaManager.getDefaultMaxMessage()); } @Override - public Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException { - return maxQuotaManager.getDefaultMaxStorage(); + public SerializableQuotaValue<QuotaSize> getDefaultMaxStorage() throws MailboxException { + return SerializableQuotaValue.valueOf(maxQuotaManager.getDefaultMaxStorage()); } @Override - public void setMaxMessageCount(String quotaRoot, QuotaCount maxMessageCount) throws MailboxException { - maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot), - maxMessageCount); + public void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException { + maxMessageCount.toValue(QuotaCount::count, QuotaCount.unlimited()) + .ifPresent( + Throwing.consumer( + (QuotaCount value) -> maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot), value)) + .sneakyThrow()); } @Override - public void setMaxStorage(String quotaRoot, QuotaSize maxSize) throws MailboxException { - maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot), - maxSize); + public void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException { + maxSize.toValue(QuotaSize::size, QuotaSize.unlimited()) + .ifPresent( + Throwing.consumer( + (QuotaSize value) -> maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot), value)) + .sneakyThrow()); } @Override - public void setDefaultMaxMessageCount(QuotaCount maxDefaultMessageCount) throws MailboxException { - maxQuotaManager.setDefaultMaxMessage(maxDefaultMessageCount); + public void setDefaultMaxMessageCount(SerializableQuotaValue<QuotaCount> maxDefaultMessageCount) throws MailboxException { + maxDefaultMessageCount.toValue(QuotaCount::count, QuotaCount.unlimited()) + .ifPresent(Throwing.consumer(maxQuotaManager::setDefaultMaxMessage).sneakyThrow()); } @Override - public void setDefaultMaxStorage(QuotaSize maxDefaultSize) throws MailboxException { - maxQuotaManager.setDefaultMaxStorage(maxDefaultSize); + public void setDefaultMaxStorage(SerializableQuotaValue<QuotaSize> maxDefaultSize) throws MailboxException { + maxDefaultSize.toValue(QuotaSize::size, QuotaSize.unlimited()) + .ifPresent(Throwing.consumer(maxQuotaManager::setDefaultMaxStorage).sneakyThrow()); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 index cf35f78..562b4b2 100644 --- 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 @@ -21,7 +21,6 @@ package org.apache.james.adapter.mailbox; import java.io.Closeable; import java.io.IOException; -import java.util.Optional; import javax.inject.Inject; @@ -33,8 +32,10 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.quota.QuotaSize; 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; import com.google.common.base.Throwables; public class QuotaManagement implements QuotaManagementMBean { @@ -64,104 +65,116 @@ public class QuotaManagement implements QuotaManagementMBean { } @Override - public Optional<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { + public SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getMaxMessageCount") .build()) { - return maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot)); + return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot))); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public Optional<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { + public SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getMaxStorage") .build()) { - return maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot)); + return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot))); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public Optional<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { + public SerializableQuotaValue<QuotaCount> getDefaultMaxMessageCount() throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getDefaultMaxMessageCount") .build()) { - return maxQuotaManager.getDefaultMaxMessage(); + return SerializableQuotaValue.valueOf(maxQuotaManager.getDefaultMaxMessage()); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException { + public SerializableQuotaValue<QuotaSize> getDefaultMaxStorage() throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getDefaultMaxStorage") .build()) { - return maxQuotaManager.getDefaultMaxStorage(); + return SerializableQuotaValue.valueOf(maxQuotaManager.getDefaultMaxStorage()); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public void setMaxMessageCount(String quotaRoot, QuotaCount maxMessageCount) throws MailboxException { + public void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "setMaxMessageCount") .build()) { - maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot), maxMessageCount); + maxMessageCount.toValue(QuotaCount::count, QuotaCount.unlimited()) + .ifPresent( + Throwing.consumer((QuotaCount value) -> + maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot), value)) + .sneakyThrow()); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public void setMaxStorage(String quotaRoot, QuotaSize maxSize) throws MailboxException { + public void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "setMaxStorage") .build()) { - maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot), maxSize); + maxSize.toValue(QuotaSize::size, QuotaSize.unlimited()) + .ifPresent( + Throwing.consumer((QuotaSize value) -> + maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot), value)) + .sneakyThrow()); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public void setDefaultMaxMessageCount(QuotaCount maxDefaultMessageCount) throws MailboxException { + public void setDefaultMaxMessageCount(SerializableQuotaValue<QuotaCount> maxDefaultMessageCount) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "setDefaultMaxMessageCount") .build()) { - maxQuotaManager.setDefaultMaxMessage(maxDefaultMessageCount); + maxDefaultMessageCount + .toValue(QuotaCount::count, QuotaCount.unlimited()) + .ifPresent(Throwing.consumer(maxQuotaManager::setDefaultMaxMessage).sneakyThrow()); } catch (IOException e) { throw Throwables.propagate(e); } } @Override - public void setDefaultMaxStorage(QuotaSize maxDefaultSize) throws MailboxException { + public void setDefaultMaxStorage(SerializableQuotaValue<QuotaSize> maxDefaultSize) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "setDefaultMaxStorage") .build()) { - maxQuotaManager.setDefaultMaxStorage(maxDefaultSize); + maxDefaultSize + .toValue(QuotaSize::size, QuotaSize.unlimited()) + .ifPresent(Throwing.consumer(maxQuotaManager::setDefaultMaxStorage).sneakyThrow()); } catch (IOException e) { throw Throwables.propagate(e); } @@ -174,7 +187,7 @@ public class QuotaManagement implements QuotaManagementMBean { .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getMessageCountQuota") .build()) { - return new SerializableQuota<>(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); + return SerializableQuota.newInstance(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); } catch (IOException e) { throw Throwables.propagate(e); } @@ -187,7 +200,7 @@ public class QuotaManagement implements QuotaManagementMBean { .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "getStorageQuota") .build()) { - return new SerializableQuota<>(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); + return SerializableQuota.newInstance(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot))); } catch (IOException e) { throw Throwables.propagate(e); } http://git-wip-us.apache.org/repos/asf/james-project/blob/63b010d7/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 index 866b587..664f05c 100644 --- 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 @@ -19,12 +19,11 @@ package org.apache.james.adapter.mailbox; -import java.util.Optional; - import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; 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; @@ -33,19 +32,19 @@ public interface QuotaManagementMBean { SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException; - Optional<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException; + SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException; - Optional<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException; + SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException; - Optional<QuotaCount> getDefaultMaxMessageCount() throws MailboxException; + SerializableQuotaValue<QuotaCount> getDefaultMaxMessageCount() throws MailboxException; - Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException; + SerializableQuotaValue<QuotaSize> getDefaultMaxStorage() throws MailboxException; - void setMaxMessageCount(String quotaRoot, QuotaCount maxMessageCount) throws MailboxException; + void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException; - void setMaxStorage(String quotaRoot, QuotaSize maxSize) throws MailboxException; + void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException; - void setDefaultMaxMessageCount(QuotaCount maxDefaultMessageCount) throws MailboxException; + void setDefaultMaxMessageCount(SerializableQuotaValue<QuotaCount> maxDefaultMessageCount) throws MailboxException; - void setDefaultMaxStorage(QuotaSize maxDefaultSize) throws MailboxException; + void setDefaultMaxStorage(SerializableQuotaValue<QuotaSize> maxDefaultSize) throws MailboxException; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
