james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r773231 - in /james/imap/trunk: mailbox/src/main/java/org/apache/james/imap/mailbox/ processor/src/main/java/org/apache/james/imap/processor/ store/src/main/java/org/apache/james/imap/store/ torque/src/main/java/org/apache/james/mailboxmana...
Date Sat, 09 May 2009 15:15:23 GMT
Author: rdonkin
Date: Sat May  9 15:15:21 2009
New Revision: 773231

URL: http://svn.apache.org/viewvc?rev=773231&view=rev
Log:
Start to consolidate calls into a single MetaData for the Mailbox. IMAP-79 https://issues.apache.org/jira/browse/IMAP-79

Modified:
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java?rev=773231&r1=773230&r2=773231&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java (original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/Mailbox.java Sat
May  9 15:15:21 2009
@@ -47,9 +47,6 @@
      */
     Iterator<Long> search(SearchQuery searchQuery, MailboxSession mailboxSession) throws
MailboxException;
 
-    long getUidValidity(MailboxSession mailboxSession)
-            throws MailboxException;
-
     /**
      * 
      * @param mailboxSession not null
@@ -59,13 +56,6 @@
 
     long getUidNext(MailboxSession mailboxSession) throws MailboxException;
 
-    /**
-     * @return Flags that can be stored
-     */
-    Flags getPermanentFlags();
-
-    long[] recent(boolean reset, MailboxSession mailboxSession) throws MailboxException;
-
     int getUnseenCount(MailboxSession mailboxSession) throws MailboxException;
 
     /**
@@ -126,4 +116,48 @@
      * @throws MailboxException
      */
     Iterator<MessageResult> getMessages(MessageRange set, FetchGroup fetchGroup, MailboxSession
mailboxSession) throws MailboxException;
+    
+    /**
+     * Gets current meta data for the mailbox.
+     * Consolidates common calls together to allow improved performance.
+     * The meta-data returned should be immutable and represent the current state
+     * of the mailbox.
+     * @param resetRecent true when recent flags should be reset,
+     * false otherwise
+     * @param mailboxSession context, not null
+     * @return meta data, not null
+     * @throws MailboxException
+     */
+    MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws MailboxException;
+    
+    /**
+     * Meta data about the current state of the mailbox.
+     */
+    public interface MetaData {
+        
+        /**
+         * Gets the UIDs of recent messages. 
+         * @return the uids flagged RECENT in this mailbox, 
+         * or null when there are no recent uids
+         */
+        public long[] getRecent();
+
+        /**
+         * Gets the number of recent messages.
+         * @return the number of messages flagged RECENT in this mailbox
+         */
+        public int countRecent();
+        
+        /**
+         * Gets the flags which can be stored by this mailbox.
+         * @return Flags that can be stored
+         */
+        Flags getPermanentFlags();
+        
+        /**
+         * Gets the UIDVALIDITY.
+         * @return UIDVALIDITY
+         */
+        long getUidValidity();
+    }
 }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java?rev=773231&r1=773230&r2=773231&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
Sat May  9 15:15:21 2009
@@ -80,8 +80,8 @@
         final String mailboxName = request.getMailboxName();
         try {
             final String fullMailboxName = buildFullName(session, mailboxName);
-            selectMailbox(fullMailboxName, session);
-            respond(tag, command, session, responder);
+            final Mailbox.MetaData metaData = selectMailbox(fullMailboxName, session);
+            respond(tag, command, session, metaData, responder);
         } catch (MailboxNotFoundException e) {
             responder.respond(statusResponseFactory.taggedNo(tag, command,
                     HumanReadableTextKey.FAILURE_NO_SUCH_MAILBOX));
@@ -91,7 +91,7 @@
     }
 
     private void respond(String tag, ImapCommand command, ImapSession session,
-            Responder responder) throws MailboxException {
+            final Mailbox.MetaData metaData, Responder responder) throws MailboxException
{
 
         Mailbox mailbox = getSelectedMailbox(session);
         final MailboxSession mailboxSession = ImapSessionUtils
@@ -103,9 +103,9 @@
         flags(responder);
         exists(responder, mailbox, mailboxSession);
         recent(responder, selected);
-        uidValidity(responder, mailbox, mailboxSession);
+        uidValidity(responder, metaData);
         unseen(responder, mailbox, mailboxSession, selected);
-        permanentFlags(responder, mailbox);
+        permanentFlags(responder, metaData);
         taggedOk(responder, tag, command, mailbox);
     }
 
@@ -127,8 +127,8 @@
         responder.respond(standardFlags);
     }
 
-    private void permanentFlags(Responder responder, Mailbox mailbox) {
-        final Flags permanentFlags = mailbox.getPermanentFlags();
+    private void permanentFlags(Responder responder, Mailbox.MetaData metaData) {
+        final Flags permanentFlags = metaData.getPermanentFlags();
         final StatusResponse untaggedOk = statusResponseFactory.untaggedOk(
                 HumanReadableTextKey.PERMANENT_FLAGS, ResponseCode
                         .permanentFlags(permanentFlags));
@@ -149,9 +149,8 @@
 
     }
 
-    private void uidValidity(Responder responder, Mailbox mailbox,
-            final MailboxSession mailboxSession) throws MailboxException {
-        final long uidValidity = mailbox.getUidValidity(mailboxSession);
+    private void uidValidity(Responder responder, Mailbox.MetaData metaData) throws MailboxException
{
+        final long uidValidity = metaData.getUidValidity();
         final StatusResponse untaggedOk = statusResponseFactory.untaggedOk(
                 HumanReadableTextKey.UID_VALIDITY, ResponseCode
                         .uidValidity(uidValidity));
@@ -171,7 +170,7 @@
         responder.respond(existsResponse);
     }
 
-    private void selectMailbox(String mailboxName, ImapSession session)
+    private Mailbox.MetaData  selectMailbox(String mailboxName, ImapSession session)
             throws MailboxException {
         final MailboxManager mailboxManager = getMailboxManager();
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
@@ -186,7 +185,9 @@
         } else {
             sessionMailbox = currentMailbox;
         }
-        addRecent(mailbox, mailboxSession, sessionMailbox);
+        final Mailbox.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession);
+        addRecent(metaData, sessionMailbox);
+        return metaData;
     }
 
     private SelectedMailbox createNewSelectedMailbox(final Mailbox mailbox,
@@ -206,13 +207,14 @@
         return sessionMailbox;
     }
 
-    private void addRecent(final Mailbox mailbox,
-            final MailboxSession mailboxSession,
+    private void addRecent(final Mailbox.MetaData metaData,
             SelectedMailbox sessionMailbox) throws MailboxException {
-        final long[] recentUids = mailbox.recent(!openReadOnly, mailboxSession);
-        for (int i = 0; i < recentUids.length; i++) {
-            long uid = recentUids[i];
-            sessionMailbox.addRecent(uid);
+        final long[] recentUids = metaData.getRecent();
+        if (recentUids != null) {
+            for (int i = 0; i < recentUids.length; i++) {
+                long uid = recentUids[i];
+                sessionMailbox.addRecent(uid);
+            }
         }
     }
 }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java?rev=773231&r1=773230&r2=773231&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
Sat May  9 15:15:21 2009
@@ -67,14 +67,13 @@
 
             final MailboxManager mailboxManager = getMailboxManager();
             final Mailbox mailbox = mailboxManager.getMailbox(fullMailboxName, ImapSessionUtils.getMailboxSession(session));
-
-            final Long messages = messages(statusDataItems, mailboxSession,
-                    mailbox);
-            final Long recent = recent(statusDataItems, mailboxSession, mailbox);
+            final Mailbox.MetaData metaData = mailbox.getMetaData(false, mailboxSession);
+            
+            final Long messages = messages(statusDataItems, mailboxSession, mailbox);
+            final Long recent = recent(statusDataItems, metaData, mailbox);
             final Long uidNext = uidNext(statusDataItems, mailboxSession,
                     mailbox);
-            final Long uidValidity = uidValidity(statusDataItems,
-                    mailboxSession, mailbox);
+            final Long uidValidity = uidValidity(statusDataItems, metaData);
             final Long unseen = unseen(statusDataItems, mailboxSession, mailbox);
 
             final MailboxStatusResponse response = new MailboxStatusResponse(messages,
@@ -102,12 +101,10 @@
     }
 
     private Long uidValidity(final StatusDataItems statusDataItems,
-            final MailboxSession mailboxSession, final Mailbox mailbox)
-            throws MailboxException {
+            final Mailbox.MetaData metaData) throws MailboxException {
         final Long uidValidity;
         if (statusDataItems.isUidValidity()) {
-            final long uidValidityValue = mailbox
-                    .getUidValidity(mailboxSession);
+            final long uidValidityValue = metaData.getUidValidity();
             uidValidity = new Long(uidValidityValue);
         } else {
             uidValidity = null;
@@ -129,11 +126,11 @@
     }
 
     private Long recent(final StatusDataItems statusDataItems,
-            final MailboxSession mailboxSession, final Mailbox mailbox)
+            final Mailbox.MetaData metaData, final Mailbox mailbox)
             throws MailboxException {
         final Long recent;
         if (statusDataItems.isRecent()) {
-            final int recentCount = mailbox.recent(false, mailboxSession).length;
+            final int recentCount = metaData.countRecent();
             recent = new Long(recentCount);
         } else {
             recent = null;

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=773231&r1=773230&r2=773231&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Sat
May  9 15:15:21 2009
@@ -469,4 +469,14 @@
     public void reportRenamed(String to) {
         tracker.reportRenamed(to);
     }
+    
+    /**
+     * @see {@link Mailbox#getMetaData(boolean, MailboxSession)}
+     */
+    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws
MailboxException {
+        final long[] recent = recent(resetRecent, mailboxSession);
+        final Flags permanentFlags = getPermanentFlags();
+        final long uidValidity = getUidValidity(mailboxSession);
+        return new MailboxMetaData(recent, permanentFlags, uidValidity);
+    }
 }

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=773231&r1=773230&r2=773231&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
Sat May  9 15:15:21 2009
@@ -807,4 +807,14 @@
         tracker.reportRenamed(mailboxRow.getName());
         this.mailboxRow = mailboxRow;
     }
+
+    /**
+     * @see {@link Mailbox#getMetaData(boolean, MailboxSession)}
+     */
+    public MetaData getMetaData(boolean resetRecent, MailboxSession mailboxSession) throws
MailboxException {
+        final long[] recent = recent(resetRecent, mailboxSession);
+        final Flags permanentFlags = getPermanentFlags();
+        final long uidValidity = getUidValidity(mailboxSession);
+        return new MailboxMetaData(recent, permanentFlags, uidValidity);
+    }
 }



---------------------------------------------------------------------
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