james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/5] james-project git commit: MAILBOX-327 Adding and firing QuotaEvents
Date Fri, 06 Apr 2018 08:27:10 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 9866ac382 -> dbc6f88cd


MAILBOX-327 Adding and firing QuotaEvents


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dbc6f88c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dbc6f88c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dbc6f88c

Branch: refs/heads/master
Commit: dbc6f88cd12cc411379f7042a3443be06a9a5555
Parents: 045b5b7
Author: benwa <btellier@linagora.com>
Authored: Tue Apr 3 11:39:30 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 6 15:26:32 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 60 ++++++++++++++++++++
 .../apache/james/mailbox/MailboxManager.java    |  3 +-
 .../james/mailbox/MailboxManagerTest.java       | 33 +++++++++++
 .../cassandra/CassandraMailboxManager.java      |  8 ++-
 .../CassandraMailboxManagerProvider.java        | 21 +++++++
 .../CassandraMailboxManagerStressTest.java      |  4 +-
 .../cassandra/CassandraMailboxManagerTest.java  |  4 +-
 .../CassandraMessageIdManagerTestSystem.java    |  2 +-
 .../james/mailbox/jpa/JPAMailboxManager.java    |  4 +-
 .../inmemory/InMemoryMailboxManager.java        |  3 +-
 .../manager/InMemoryIntegrationResources.java   | 21 ++++---
 .../main/resources/META-INF/spring/quota.xml    |  2 +
 .../store/event/MailboxEventDispatcher.java     |  8 +++
 .../quota/ListeningCurrentQuotaUpdater.java     | 16 +++++-
 .../quota/ListeningCurrentQuotaUpdaterTest.java |  5 +-
 .../cassandra/host/CassandraHostSystem.java     |  2 +-
 .../inmemory/host/InMemoryHostSystem.java       |  2 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |  2 +-
 18 files changed, 181 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 1facc04..de16426 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -21,11 +21,16 @@ package org.apache.james.mailbox;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
 
 
 /**
@@ -56,6 +61,61 @@ public interface MailboxListener {
      *            not null
      */
     void event(Event event);
+    
+    interface QuotaEvent extends Event {
+        QuotaRoot getQuotaRoot();
+    }
+
+    class QuotaUsageUpdatedEvent implements QuotaEvent, Serializable {
+        private final MailboxSession session;
+        private final QuotaRoot quotaRoot;
+        private final Quota<QuotaCount> countQuota;
+        private final Quota<QuotaSize> sizeQuota;
+
+        public QuotaUsageUpdatedEvent(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount>
countQuota, Quota<QuotaSize> sizeQuota) {
+            this.session = session;
+            this.quotaRoot = quotaRoot;
+            this.countQuota = countQuota;
+            this.sizeQuota = sizeQuota;
+        }
+
+        @Override
+        public MailboxSession getSession() {
+            return session;
+        }
+
+        public Quota<QuotaCount> getCountQuota() {
+            return countQuota;
+        }
+
+        public Quota<QuotaSize> getSizeQuota() {
+            return sizeQuota;
+        }
+
+        @Override
+        public QuotaRoot getQuotaRoot() {
+            return quotaRoot;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof QuotaUsageUpdatedEvent) {
+                QuotaUsageUpdatedEvent that = (QuotaUsageUpdatedEvent) o;
+
+                return Objects.equals(this.session, that.session)
+                    && Objects.equals(this.quotaRoot, that.quotaRoot)
+                    && Objects.equals(this.countQuota, that.countQuota)
+                    && Objects.equals(this.sizeQuota, that.sizeQuota);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(session, quotaRoot, countQuota, sizeQuota);
+        }
+
+    }
 
     /**
      * A mailbox event.

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index 3374e4e..e027103 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -75,7 +75,8 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport,
Ri
         Move,
         Namespace,
         UserFlag,
-        ACL
+        ACL,
+        Quota
     }
 
     EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities();

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index a340cf9..2edda06 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -41,9 +41,14 @@ import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+import org.apache.james.mailbox.util.EventCollector;
 import org.assertj.core.api.JUnitSoftAssertions;
 import org.junit.Assume;
 import org.junit.Rule;
@@ -905,4 +910,32 @@ public abstract class MailboxManagerTest {
             .extracting(MessageManager.MetaData::getPermanentFlags)
             .contains(new Flags());
     }
+
+    @Test
+    public void addingMessageShouldFireQuotaUpdateEvent() throws Exception {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Quota));
+        session = mailboxManager.createSystemSession(USER_1);
+
+        EventCollector listener = new EventCollector();
+        mailboxManager.addGlobalListener(listener, session);
+
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        mailboxManager.getMailbox(inbox, session)
+            .appendMessage(MessageManager.AppendCommand.builder()
+                .build(message), session);
+
+        assertThat(listener.getEvents())
+            .contains(new MailboxListener.QuotaUsageUpdatedEvent(
+                session,
+                QuotaRoot.quotaRoot("#private&" + USER_1, Optional.empty()),
+                Quota.<QuotaCount>builder()
+                    .used(QuotaCount.count(1))
+                    .computedLimit(QuotaCount.unlimited())
+                    .build(),
+                Quota.<QuotaSize>builder()
+                    .used(QuotaSize.size(85))
+                    .computedLimit(QuotaSize.unlimited())
+                    .build()));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
index a6d6603..be5d71c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
@@ -78,7 +78,13 @@ public class CassandraMailboxManager extends StoreMailboxManager {
 
     @Override
     public EnumSet<MailboxManager.MailboxCapabilities> getSupportedMailboxCapabilities()
{
-        return EnumSet.of(MailboxCapabilities.Move, MailboxCapabilities.UserFlag, MailboxCapabilities.Namespace,
MailboxCapabilities.Annotation, MailboxCapabilities.ACL);
+        return EnumSet.of(
+            MailboxCapabilities.Move,
+            MailboxCapabilities.UserFlag,
+            MailboxCapabilities.Namespace,
+            MailboxCapabilities.Annotation,
+            MailboxCapabilities.ACL,
+            MailboxCapabilities.Quota);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
index 056c899..4eb765d 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
@@ -25,7 +25,13 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
+import org.apache.james.mailbox.cassandra.quota.CassandraCurrentQuotaManager;
+import org.apache.james.mailbox.cassandra.quota.CassandraGlobalMaxQuotaDao;
+import org.apache.james.mailbox.cassandra.quota.CassandraPerDomainMaxQuotaDao;
+import org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaDao;
+import org.apache.james.mailbox.cassandra.quota.CassandraPerUserMaxQuotaManager;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
@@ -34,6 +40,9 @@ import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
+import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
+import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
+import org.apache.james.mailbox.store.quota.StoreQuotaManager;
 
 import com.datastax.driver.core.Session;
 import com.google.common.base.Throwables;
@@ -65,6 +74,18 @@ public class CassandraMailboxManagerProvider {
         CassandraMailboxManager manager = new CassandraMailboxManager(mapperFactory, noAuthenticator,
noAuthorizator, new NoMailboxPathLocker(),
             messageParser, messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener,
             annotationManager, storeRightManager);
+
+        CassandraPerUserMaxQuotaManager maxQuotaManager = new CassandraPerUserMaxQuotaManager(new
CassandraPerUserMaxQuotaDao(session),
+            new CassandraPerDomainMaxQuotaDao(session),
+            new CassandraGlobalMaxQuotaDao(session));
+        CassandraCurrentQuotaManager currentQuotaUpdater = new CassandraCurrentQuotaManager(session);
+        StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaUpdater,
maxQuotaManager);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaUpdater,
quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
+        manager.setQuotaManager(storeQuotaManager);
+        manager.setQuotaUpdater(quotaUpdater);
+        manager.setQuotaRootResolver(quotaRootResolver);
         try {
             manager.init();
         } catch (MailboxException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerStressTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerStressTest.java
index b460538..f511f06 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerStressTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerStressTest.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxRecentsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraSubscriptionModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
 import org.junit.After;
@@ -64,7 +65,8 @@ public class CassandraMailboxManagerStressTest extends MailboxManagerStressTest
                 new CassandraAttachmentModule(),
                 new CassandraDeletedMessageModule(),
                 new CassandraAnnotationModule(),
-                new CassandraApplicableFlagsModule());
+                new CassandraApplicableFlagsModule(),
+                new CassandraQuotaModule());
         cassandra = CassandraCluster.create(modules, cassandraServer.getIp(), cassandraServer.getBindingPort());
         super.setUp();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
index ad8acaa..4594300 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxRecentsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraSubscriptionModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
 import org.junit.After;
@@ -63,7 +64,8 @@ public class CassandraMailboxManagerTest extends MailboxManagerTest {
                 new CassandraAttachmentModule(),
                 new CassandraDeletedMessageModule(),
                 new CassandraAnnotationModule(),
-                new CassandraApplicableFlagsModule());
+                new CassandraApplicableFlagsModule(),
+                new CassandraQuotaModule());
         cassandra = CassandraCluster.create(modules, cassandraServer.getIp(), cassandraServer.getBindingPort());
         super.setUp();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
index 54ec881..7adc220 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
@@ -68,7 +68,7 @@ public class CassandraMessageIdManagerTestSystem extends MessageIdManagerTestSys
         CassandraMailboxManager mailboxManager = CassandraTestSystemFixture.createMailboxManager(mapperFactory);
         ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(
             (StoreCurrentQuotaManager) currentQuotaManager,
-            mailboxManager.getQuotaRootResolver());
+            mailboxManager.getQuotaRootResolver(), mailboxManager.getEventDispatcher(), quotaManager);
         mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, mailboxManager.createSystemSession("System"));
         return new CassandraMessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory,
quotaManager, mailboxManager.getEventDispatcher()),
             new CassandraMessageId.Factory(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
index 2943e01..f6282d2 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
@@ -65,7 +65,9 @@ public abstract class JPAMailboxManager extends StoreMailboxManager {
 
     @Override
     public EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities() {
-        return EnumSet.of(MailboxCapabilities.UserFlag, MailboxCapabilities.Namespace, MailboxCapabilities.Annotation);
+        return EnumSet.of(MailboxCapabilities.UserFlag,
+            MailboxCapabilities.Namespace,
+            MailboxCapabilities.Annotation);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
index f333035..2d5a11d 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
@@ -65,7 +65,8 @@ public class InMemoryMailboxManager extends StoreMailboxManager {
             MailboxCapabilities.UserFlag,
             MailboxCapabilities.Namespace,
             MailboxCapabilities.Annotation,
-            MailboxCapabilities.ACL);
+            MailboxCapabilities.ACL,
+            MailboxCapabilities.Quota);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 1e8ae1f..fe27013 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -54,6 +54,8 @@ import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
 import org.apache.james.mailbox.store.quota.StoreQuotaManager;
 
+import com.google.common.base.Throwables;
+
 public class InMemoryIntegrationResources implements IntegrationResources<StoreMailboxManager>
{
 
     private SimpleGroupMembershipResolver groupMembershipResolver;
@@ -105,6 +107,11 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             annotationManager,
             storeRightManager);
         manager.init();
+        try {
+            createQuotaManager(createMaxQuotaManager(), manager);
+        } catch (Exception e) {
+            throw Throwables.propagate(e);
+        }
         return manager;
     }
 
@@ -149,15 +156,15 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
 
         InMemoryCurrentQuotaManager currentQuotaManager = createCurrentQuotaManager(mailboxManager);
 
-        ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver);
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager);
+        ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
         mailboxManager.setQuotaManager(quotaManager);
         mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, null);
         return quotaManager;
     }
 
     @Override
-    public InMemoryCurrentQuotaManager createCurrentQuotaManager(StoreMailboxManager mailboxManager)
throws Exception {
+    public InMemoryCurrentQuotaManager createCurrentQuotaManager(StoreMailboxManager mailboxManager)
{
         if (currentQuotaManager == null) {
             currentQuotaManager = new InMemoryCurrentQuotaManager(
                     new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), createQuotaRootResolver(mailboxManager)),
@@ -167,18 +174,18 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
     }
 
     @Override
-    public MaxQuotaManager createMaxQuotaManager() throws Exception {
+    public MaxQuotaManager createMaxQuotaManager() {
         return new InMemoryPerUserMaxQuotaManager();
     }
 
     @Override
-    public GroupMembershipResolver createGroupMembershipResolver() throws Exception {
+    public GroupMembershipResolver createGroupMembershipResolver() {
         groupMembershipResolver = new SimpleGroupMembershipResolver();
         return groupMembershipResolver;
     }
 
     @Override
-    public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager)
throws Exception {
+    public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager)
{
         if (quotaRootResolver == null) {
             quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
         }
@@ -186,11 +193,11 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
     }
 
     @Override
-    public void init() throws MailboxException {
+    public void init() {
     }
 
     @Override
-    public void clean() throws MailboxException {
+    public void clean() {
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
index 2a564aa..a43f300 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
@@ -53,6 +53,8 @@
     <bean id="eventQuotaUpdater" class="org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater"
lazy-init="true">
         <constructor-arg index="0" ref="currentQuotaManager"/>
         <constructor-arg index="1" ref="quotaRootResolver"/>
+        <constructor-arg index="2" ref="dispatcher"/>
+        <constructor-arg index="3" ref="storeQuotaManager"/>
     </bean>
 
 </beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index e64a18f..c4fb3c9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -32,7 +32,11 @@ import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageMoves;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -158,4 +162,8 @@ public class MailboxEventDispatcher {
     public void moved(MailboxSession session, MessageMoves messageMoves, Map<MessageUid,
MailboxMessage> messages) {
         listener.event(eventFactory.moved(session, messageMoves, messages));
     }
+
+    public void quota(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount>
countQuota, Quota<QuotaSize> sizeQuota) {
+        listener.event(new MailboxListener.QuotaUsageUpdatedEvent(session, quotaRoot, countQuota,
sizeQuota));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 6512b18..62e4ee0 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -27,7 +27,9 @@ import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,11 +39,15 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener,
QuotaUpdat
 
     private final StoreCurrentQuotaManager currentQuotaManager;
     private final QuotaRootResolver quotaRootResolver;
+    private final MailboxEventDispatcher dispatcher;
+    private final QuotaManager quotaManager;
 
     @Inject
-    public ListeningCurrentQuotaUpdater(StoreCurrentQuotaManager currentQuotaManager, QuotaRootResolver
quotaRootResolver) {
+    public ListeningCurrentQuotaUpdater(StoreCurrentQuotaManager currentQuotaManager, QuotaRootResolver
quotaRootResolver, MailboxEventDispatcher dispatcher, QuotaManager quotaManager) {
         this.currentQuotaManager = currentQuotaManager;
         this.quotaRootResolver = quotaRootResolver;
+        this.dispatcher = dispatcher;
+        this.quotaManager = quotaManager;
     }
 
     @Override
@@ -83,6 +89,10 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
+        dispatcher.quota(expunged.getSession(),
+            quotaRoot,
+            quotaManager.getMessageQuota(quotaRoot),
+            quotaManager.getStorageQuota(quotaRoot));
     }
 
     private void handleAddedEvent(Added added, QuotaRoot quotaRoot) throws MailboxException
{
@@ -96,6 +106,10 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener,
QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
+        dispatcher.quota(added.getSession(),
+            quotaRoot,
+            quotaManager.getMessageQuota(quotaRoot),
+            quotaManager.getStorageQuota(quotaRoot));
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index f2e9c7d..158cd97 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -33,8 +33,10 @@ import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
+import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,7 +57,8 @@ public class ListeningCurrentQuotaUpdaterTest {
     public void setUp() throws Exception {
         mockedQuotaRootResolver = mock(QuotaRootResolver.class);
         mockedCurrentQuotaManager = mock(StoreCurrentQuotaManager.class);
-        testee = new ListeningCurrentQuotaUpdater(mockedCurrentQuotaManager, mockedQuotaRootResolver);
+        testee = new ListeningCurrentQuotaUpdater(mockedCurrentQuotaManager, mockedQuotaRootResolver,
+            mock(MailboxEventDispatcher.class), mock(QuotaManager.class));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index 42628af..13e303e 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -137,7 +137,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
 
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
 
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver, mailboxEventDispatcher, quotaManager);
 
         mailboxManager.setQuotaRootResolver(quotaRootResolver);
         mailboxManager.setQuotaManager(quotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index d428200..c341a58 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -74,7 +74,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
 
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
 
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
 
         mailboxManager.setQuotaRootResolver(quotaRootResolver);
         mailboxManager.setQuotaManager(quotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/dbc6f88c/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index 6516cbd..41f1bbc 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -110,7 +110,7 @@ public class JPAHostSystem extends JamesImapHostSystem {
         JpaCurrentQuotaManager currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);
         maxQuotaManager = new JPAPerUserMaxQuotaManager(new JPAPerUserMaxQuotaDAO(entityManagerFactory));
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaManager,
maxQuotaManager);
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager,
quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
 
         mailboxManager.setQuotaManager(storeQuotaManager);
         mailboxManager.setQuotaUpdater(quotaUpdater);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message