Author: btellier
Date: Tue Sep 22 10:31:10 2015
New Revision: 1704550

URL: http://svn.apache.org/viewvc?rev=1704550&view=rev
Log:
JAMES-511 Introduce QuotaManagement interfaces

Added:
    
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
    
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
    
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/SerializableQuota.java

Added: 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java?rev=1704550&view=auto
==============================================================================
--- 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
 (added)
+++ 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
 Tue Sep 22 10:31:10 2015
@@ -0,0 +1,100 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.adapter.mailbox;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+public class QuotaManagement implements QuotaManagementMBean {
+
+    private QuotaManager quotaManager;
+    private MaxQuotaManager maxQuotaManager;
+    private QuotaRootResolver quotaRootResolver;
+
+    public void setQuotaManager(QuotaManager quotaManager) {
+        this.quotaManager = quotaManager;
+    }
+
+    public void setMaxQuotaManager(MaxQuotaManager maxQuotaManager) {
+        this.maxQuotaManager = maxQuotaManager;
+    }
+
+    public void setQuotaRootResolver(QuotaRootResolver quotaRootResolver) {
+        this.quotaRootResolver = quotaRootResolver;
+    }
+
+    @Override
+    public String getQuotaRoot(String namespace, String user, String name) 
throws MailboxException {
+        return quotaRootResolver.getQuotaRoot(new MailboxPath(namespace, user, 
name)).getValue();
+    }
+
+    @Override
+    public long getMaxMessageCount(String quotaRoot) throws MailboxException {
+        return 
maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot));
+    }
+
+    @Override
+    public long getMaxStorage(String quotaRoot) throws MailboxException {
+        return 
maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot));
+    }
+
+    @Override
+    public long getDefaultMaxMessageCount() throws MailboxException {
+        return maxQuotaManager.getDefaultMaxMessage();
+    }
+
+    @Override
+    public long getDefaultMaxStorage() throws MailboxException {
+        return maxQuotaManager.getDefaultMaxStorage();
+    }
+
+    @Override
+    public void setMaxMessageCount(String quotaRoot, long maxMessageCount) 
throws MailboxException {
+        
maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot), 
maxMessageCount);
+    }
+
+    @Override
+    public void setMaxStorage(String quotaRoot, long maxSize) throws 
MailboxException {
+        
maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot), 
maxSize);
+    }
+
+    @Override
+    public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws 
MailboxException {
+        maxQuotaManager.setDefaultMaxMessage(maxDefaultMessageCount);
+    }
+
+    @Override
+    public void setDefaultMaxStorage(long maxDefaultSize) throws 
MailboxException {
+        maxQuotaManager.setDefaultMaxStorage(maxDefaultSize);
+    }
+
+    @Override
+    public SerializableQuota getMessageCountQuota(String quotaRoot) throws 
MailboxException {
+        return new 
SerializableQuota(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot)));
+    }
+
+    @Override
+    public SerializableQuota getStorageQuota(String quotaRoot) throws 
MailboxException {
+        return new 
SerializableQuota(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot)));
+    }
+}

Added: 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java?rev=1704550&view=auto
==============================================================================
--- 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
 (added)
+++ 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
 Tue Sep 22 10:31:10 2015
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.adapter.mailbox;
+
+import org.apache.james.mailbox.exception.MailboxException;
+
+public interface QuotaManagementMBean {
+    String getQuotaRoot(String namespace, String user, String name) throws 
MailboxException;
+
+    SerializableQuota getMessageCountQuota(String quotaRoot) throws 
MailboxException;
+
+    SerializableQuota getStorageQuota(String quotaRoot) throws 
MailboxException;
+
+    long getMaxMessageCount(String quotaRoot) throws MailboxException;
+
+    long getMaxStorage(String quotaRoot) throws MailboxException;
+
+    long getDefaultMaxMessageCount() throws MailboxException;
+
+    long getDefaultMaxStorage() throws MailboxException;
+
+    void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws 
MailboxException;
+
+    void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException;
+
+    void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws 
MailboxException;
+
+    void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException;
+}

Added: 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/SerializableQuota.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/SerializableQuota.java?rev=1704550&view=auto
==============================================================================
--- 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/SerializableQuota.java
 (added)
+++ 
james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/SerializableQuota.java
 Tue Sep 22 10:31:10 2015
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.adapter.mailbox;
+
+import org.apache.james.mailbox.model.Quota;
+
+import java.io.Serializable;
+
+public class SerializableQuota implements Serializable {
+
+    private final long max;
+    private final long used;
+
+    public SerializableQuota(long max, long used) {
+        this.max = max;
+        this.used = used;
+    }
+
+    public SerializableQuota(Quota quota) {
+        this.max = quota.getMax();
+        this.used = quota.getUsed();
+    }
+
+    public long getMax() {
+        return max;
+    }
+
+    public long getUsed() {
+        return used;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to