Author: norman Date: Thu Jun 9 18:49:19 2011 New Revision: 1134034 URL: http://svn.apache.org/viewvc?rev=1134034&view=rev Log: Get ready for supporting Quotas. See MAILBOX-64
Added: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/Quota.java james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/QuotaManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/FixedQuotaManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/PerUserQuotaManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java Added: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/Quota.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/Quota.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/Quota.java (added) +++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/Quota.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,54 @@ +/**************************************************************** + * 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.quota; + +/** + * A {@link Quota} restriction + * + * + * + */ +public interface Quota { + + /** + * Unlimited value + */ + public final static long UNLIMITED = -1; + + + /** + * Value not known + */ + public final static long UNKNOWN = Long.MIN_VALUE; + + /** + * Return the maximum value for the {@link Quota} + * + * @return max + */ + long getMax(); + + /** + * Return the currently used for the {@link Quota} + * + * @return used + */ + long getUsed(); + +} Added: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/QuotaManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/QuotaManager.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/QuotaManager.java (added) +++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/quota/QuotaManager.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,54 @@ +/**************************************************************** + * 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.quota; + +import org.apache.james.mailbox.MailboxException; +import org.apache.james.mailbox.MailboxSession; + + +/** + * Allows to get quotas for {@link MailboxSession} which are bound to a user. + * + * + * @param <Id> + */ +public interface QuotaManager { + + /** + * Return the message count {@link Quota} for the given {@link MailboxSession} (which in fact is + * bound to a user) + * + * @param session + * @return quota + * @throws MailboxException + */ + public Quota getMessageQuota(MailboxSession session) throws MailboxException; + + + /** + * Return the message storage {@link Quota} for the given {@link MailboxSession} (which in fact is + * bound to a user) + * + * @param session + * @return quota + * @throws MailboxException + */ + public Quota getStorageQuota(MailboxSession session) throws MailboxException; + +} Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1134034&r1=1134033&r2=1134034&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java Thu Jun 9 18:49:19 2011 @@ -52,7 +52,6 @@ import org.apache.james.mailbox.store.tr import org.apache.james.mailbox.store.transaction.TransactionalMapper; import org.apache.james.mailbox.util.SimpleMailboxMetaData; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This abstract base class of an {@link MailboxManager} implementation provides a high-level api for writing your own @@ -74,7 +73,6 @@ public abstract class StoreMailboxManage private final Authenticator authenticator; private final static Random RANDOM = new Random(); - private Logger log = LoggerFactory.getLogger("org.apache.james.mailbox"); private MailboxPathLocker locker; @@ -105,22 +103,22 @@ public abstract class StoreMailboxManage } } - protected AbstractDelegatingMailboxListener getDelegationListener() { + public AbstractDelegatingMailboxListener getDelegationListener() { if (delegatingListener == null) { delegatingListener = new HashMapDelegatingMailboxListener(); } return delegatingListener; } - protected MessageSearchIndex<Id> getMessageSearchIndex() { + public MessageSearchIndex<Id> getMessageSearchIndex() { return index; } - protected MailboxEventDispatcher<Id> getEventDispatcher() { + public MailboxEventDispatcher<Id> getEventDispatcher() { return dispatcher; } - protected MailboxSessionMapperFactory<Id> getMapperFactory() { + public MailboxSessionMapperFactory<Id> getMapperFactory() { return mailboxSessionMapperFactory; } @@ -141,14 +139,6 @@ public abstract class StoreMailboxManage public void setMessageSearchIndex(MessageSearchIndex<Id> index) { this.index = index; } - - protected Logger getLog() { - return log; - } - - public void setLog(Logger log) { - this.log = log; - } /** * Generate an return the next uid validity @@ -253,11 +243,11 @@ public abstract class StoreMailboxManage Mailbox<Id> mailboxRow = mapper.findMailboxByPath(mailboxPath); if (mailboxRow == null) { - getLog().info("Mailbox '" + mailboxPath + "' not found."); + session.getLog().info("Mailbox '" + mailboxPath + "' not found."); throw new MailboxNotFoundException(mailboxPath); } else { - getLog().debug("Loaded mailbox " + mailboxPath); + session.getLog().debug("Loaded mailbox " + mailboxPath); StoreMessageManager<Id> m = createMessageManager(mailboxRow, session); return m; @@ -272,10 +262,10 @@ public abstract class StoreMailboxManage */ public void createMailbox(MailboxPath mailboxPath, final MailboxSession mailboxSession) throws MailboxException { - getLog().debug("createMailbox " + mailboxPath); + mailboxSession.getLog().debug("createMailbox " + mailboxPath); final int length = mailboxPath.getName().length(); if (length == 0) { - getLog().warn("Ignoring mailbox with empty name"); + mailboxSession.getLog().warn("Ignoring mailbox with empty name"); } else { if (mailboxPath.getName().charAt(length - 1) == getDelimiter()) mailboxPath.setName(mailboxPath.getName().substring(0, length - 1)); @@ -339,7 +329,7 @@ public abstract class StoreMailboxManage * @see org.apache.james.mailbox.MailboxManager#renameMailbox(org.apache.james.imap.api.MailboxPath, org.apache.james.imap.api.MailboxPath, org.apache.james.mailbox.MailboxSession) */ public void renameMailbox(final MailboxPath from, final MailboxPath to, final MailboxSession session) throws MailboxException { - final Logger log = getLog(); + final Logger log = session.getLog(); if (log.isDebugEnabled()) log.debug("renameMailbox " + from + " to " + to); if (mailboxExists(to, session)) { Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java?rev=1134034&r1=1134033&r2=1134034&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java Thu Jun 9 18:49:19 2011 @@ -27,7 +27,6 @@ import javax.mail.Flags; import org.apache.james.mailbox.MailboxException; import org.apache.james.mailbox.MessageMetaData; import org.apache.james.mailbox.MessageRange; -import org.apache.james.mailbox.SearchQuery; import org.apache.james.mailbox.UpdatedFlags; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/FixedQuotaManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/FixedQuotaManager.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/FixedQuotaManager.java (added) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/FixedQuotaManager.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,62 @@ +/**************************************************************** + * 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.quota; + +import org.apache.james.mailbox.MailboxException; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.quota.Quota; +import org.apache.james.mailbox.store.StoreMailboxManager; + +/** + * {@link ListeningQuotaManager} which use the same quota for all users. + * + * By default this means not quota at all + * + * + * @param <Id> + */ +public class FixedQuotaManager extends ListeningQuotaManager{ + + @SuppressWarnings("rawtypes") + public FixedQuotaManager(StoreMailboxManager manager) throws MailboxException { + super(manager); + } + + private long maxStorage = Quota.UNLIMITED; + private long maxMessage = Quota.UNLIMITED; + + public void setMaxStorage(long maxStorage) { + this.maxStorage = maxStorage; + } + + public void setMaxMessage(long maxMessage) { + this.maxMessage = maxMessage; + } + + @Override + protected long getMaxStorage(MailboxSession session) throws MailboxException { + return maxStorage; + } + + @Override + protected long getMaxMessage(MailboxSession session) throws MailboxException { + return maxMessage; + } + +} Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java (added) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,237 @@ +/**************************************************************** + * 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.quota; + +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.james.mailbox.MailboxException; +import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.MailboxPath; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.MessageRange; +import org.apache.james.mailbox.quota.Quota; +import org.apache.james.mailbox.quota.QuotaManager; +import org.apache.james.mailbox.store.MailboxSessionMapperFactory; +import org.apache.james.mailbox.store.StoreMailboxManager; +import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.apache.james.mailbox.store.mail.model.Message; +import org.apache.james.mailbox.store.transaction.Mapper.MailboxMembershipCallback; + +/** + * {@link QuotaManager} which will keep track of quota by listing for {@link Event}'s. + * + * The whole quota is keeped in memory after it was lazy-fetched on the first access + * * + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public abstract class ListeningQuotaManager implements QuotaManager, MailboxListener{ + + private MailboxSessionMapperFactory factory; + private ConcurrentHashMap<String, AtomicLong> counts = new ConcurrentHashMap<String, AtomicLong>(); + private ConcurrentHashMap<String, AtomicLong> sizes = new ConcurrentHashMap<String, AtomicLong>(); + private boolean calculateWhenUnlimited = false; + + public ListeningQuotaManager(StoreMailboxManager<?> manager) throws MailboxException { + this.factory = manager.getMapperFactory(); + manager.addGlobalListener(this, null); + } + + protected MailboxSessionMapperFactory<?> getFactory() { + return factory; + } + + public void setCalculateUsedWhenUnlimited(boolean calculateWhenUnlimited) { + this.calculateWhenUnlimited = calculateWhenUnlimited; + } + + + @Override + public Quota getMessageQuota(MailboxSession session) throws MailboxException { + long max = getMaxMessage(session); + if (max != Quota.UNLIMITED || calculateWhenUnlimited) { + + String id = session.getUser().getUserName(); + AtomicLong count = counts.get(id); + if (count == null) { + long mc = 0; + List<Mailbox> mailboxes = factory.getMailboxMapper(session).findMailboxWithPathLike(new MailboxPath(session.getPersonalSpace(), id, "%")); + for (int i = 0; i < mailboxes.size(); i++) { + mc += factory.getMessageMapper(session).countMessagesInMailbox(mailboxes.get(i)); + } + AtomicLong c = counts.putIfAbsent(id, new AtomicLong(mc)); + if (c != null) { + count = c; + } + } + return QuotaImpl.quota(max, count.get()); + } else { + return QuotaImpl.unlimited(); + } + } + + @Override + public Quota getStorageQuota(MailboxSession session) throws MailboxException { + long max = getMaxStorage(session); + if (max != Quota.UNLIMITED || calculateWhenUnlimited) { + String id = session.getUser().getUserName(); + AtomicLong size = sizes.get(id); + if (size == null) { + final AtomicLong mSizes = new AtomicLong(0); + List<Mailbox> mailboxes = factory.getMailboxMapper(session).findMailboxWithPathLike(new MailboxPath(session.getPersonalSpace(), id, "%")); + for (int i = 0; i < mailboxes.size(); i++) { + factory.getMessageMapper(session).findInMailbox(mailboxes.get(i), MessageRange.all(), new MailboxMembershipCallback<Object>() { + long messageSizes = 0; + + @Override + public void onMailboxMembers(List<Message<Object>> list) throws MailboxException { + for (int i = 0; i < list.size(); i++) { + messageSizes += list.get(i).getFullContentOctets(); + } + mSizes.set(mSizes.get() + messageSizes); + } + }); + } + + + + AtomicLong s = sizes.putIfAbsent(id, mSizes); + if (s != null) { + size = s; + } else { + size = mSizes; + } + } + return QuotaImpl.quota(max, size.get()); + } else { + return QuotaImpl.unlimited(); + } + } + + /** + * Return the maximum storage which is allowed for the given {@link MailboxSession} (in fact the user which the session is bound to) + * + * The returned valued must be in <strong>bytes</strong> + * + * @param session + * @param mailbox + * @return maxBytes + * @throws MailboxException + */ + protected abstract long getMaxStorage(MailboxSession session) throws MailboxException; + + + /** + * Return the maximum message count which is allowed for the given {@link MailboxSession} (in fact the user which the session is bound to) + * + * @param session + * @param mailbox + * @return + * @throws MailboxException + */ + protected abstract long getMaxMessage(MailboxSession session) throws MailboxException; + + + @Override + public void event(Event event) { + String id = event.getSession().getUser().getUserName(); + if (event instanceof Added) { + Added added = (Added) event; + + long s = 0; + long c = 0; + Iterator<Long> uids = added.getUids().iterator();; + while(uids.hasNext()) { + long uid = uids.next(); + s += added.getMetaData(uid).getSize(); + c++; + } + + AtomicLong size = sizes.get(id); + if (size != null) { + while(true) { + long expected = size.get(); + long newValue = expected + s; + if (size.compareAndSet(expected, newValue)) { + break; + } + } + } + + AtomicLong count = counts.get(id); + if (count != null) { + while(true) { + long expected = count.get(); + long newValue = expected + c; + if (count.compareAndSet(expected, newValue)) { + break; + } + } + } + } else if (event instanceof Expunged) { + Expunged expunged = (Expunged) event; + long s = 0; + long c = 0; + Iterator<Long> uids = expunged.getUids().iterator();; + while(uids.hasNext()) { + long uid = uids.next(); + s += expunged.getMetaData(uid).getSize(); + c++; + } + + AtomicLong size = sizes.get(id); + if (size != null) { + while(true) { + long expected = size.get(); + long newValue = expected - s; + if (size.compareAndSet(expected, newValue)) { + break; + } + } + } + + AtomicLong count = counts.get(id); + if (count != null) { + while(true) { + long expected = count.get(); + long newValue = expected - c; + if (count.compareAndSet(expected, newValue)) { + break; + } + } + } + } else if (event instanceof MailboxAdded) { + counts.putIfAbsent(id, new AtomicLong(0)); + sizes.putIfAbsent(id, new AtomicLong(0)); + } + } + + /** + * Get never closed + * + * @return false + */ + public boolean isClosed() { + return false; + } + + +} Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/PerUserQuotaManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/PerUserQuotaManager.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/PerUserQuotaManager.java (added) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/PerUserQuotaManager.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,80 @@ +/**************************************************************** + * 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.quota; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.james.mailbox.MailboxException; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.quota.Quota; +import org.apache.james.mailbox.store.StoreMailboxManager; + +/** + * Allows to set a per Users quota + * + * + */ +public class PerUserQuotaManager<Id> extends ListeningQuotaManager{ + + public PerUserQuotaManager(StoreMailboxManager<Id> manager) throws MailboxException { + super(manager); + } + + private long maxMessage = Quota.UNLIMITED; + private long maxStorage = Quota.UNLIMITED; + + private Map<String, Long> userMaxStorage = new HashMap<String, Long>(); + private Map<String, Long> userMaxMessage = new HashMap<String, Long>(); + + public void setUserMaxStorage(Map<String, Long> userMaxStorage) { + this.userMaxStorage = userMaxStorage; + } + + public void setUserMaxMessage(Map<String, Long> userMaxMessage) { + this.userMaxMessage = userMaxMessage; + } + + public void setDefaultMaxStorage(long maxStorage) { + this.maxStorage = maxStorage; + } + + public void setDefaultMaxMessage(long maxMessage) { + this.maxMessage = maxMessage; + } + + @Override + protected long getMaxStorage(MailboxSession session) throws MailboxException { + Long max = userMaxStorage.get(session.getUser().getUserName()); + if (max == null) { + max = maxStorage; + } + return max; + } + + @Override + protected long getMaxMessage(MailboxSession session) throws MailboxException { + Long max = userMaxMessage.get(session.getUser().getUserName()); + if (max == null) { + max = maxMessage; + } + return max; + } + +} Added: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java?rev=1134034&view=auto ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java (added) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java Thu Jun 9 18:49:19 2011 @@ -0,0 +1,64 @@ +/**************************************************************** + * 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.quota; + +import org.apache.james.mailbox.quota.Quota; + +public final class QuotaImpl implements Quota{ + + private long max; + private long used; + + private final static Quota UNLIMITED_QUOTA = new QuotaImpl(UNKNOWN, UNLIMITED); + + private QuotaImpl(long used, long max) { + + } + + @Override + public long getMax() { + return max; + } + + @Override + public long getUsed() { + return used; + } + + /** + * Return a {@link Quota} which in fact is unlimited + * + * @return unlimited + */ + public static Quota unlimited() { + return UNLIMITED_QUOTA; + } + + /** + * Return a {@link Quota} for the given values + * + * @param max + * @param used + * @return quota + */ + public static Quota quota(long max , long used) { + return new QuotaImpl(used, max); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org