Author: rdonkin
Date: Fri Jan 23 07:15:37 2009
New Revision: 737045

URL: http://svn.apache.org/viewvc?rev=737045&view=rev
Log:
Simplify UID tracking

Modified:
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
    
james/protocols/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java

Modified: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java?rev=737045&r1=737044&r2=737045&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
 Fri Jan 23 07:15:37 2009
@@ -36,7 +36,6 @@
 import org.apache.james.imap.mailbox.Constants;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxListener;
-import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MessageResult;
 
 public class UidChangeTracker implements Constants {
@@ -45,14 +44,9 @@
 
     private final TreeMap<Long, Flags> cache;
 
-    private long lastUidAtStart;
-
     private long lastUid;
 
-    private long lastScannedUid = 0;
-
     public UidChangeTracker(long lastUid) {
-        this.lastUidAtStart = lastUid;
         this.lastUid = lastUid;
         eventDispatcher = new MailboxEventDispatcher();
         cache = new TreeMap<Long, Flags>();
@@ -72,7 +66,6 @@
      *            flags
      * @param sessionId
      *            id of the session upating the flags
-     * @see #flagsUpdated(MessageResult, long)
      */
     public synchronized void flagsUpdated(SortedMap<Long,Flags> newFlagsByUid, 
Map<Long,Flags> originalFlagsByUid, long sessionId) {
         if (newFlagsByUid != null) {
@@ -94,84 +87,26 @@
         }
     }
 
-    /**
-     * Indicates that the flags on the given messages may have been updated.
-     * 
-     * @param messageResults
-     *            results
-     * @param sessionId
-     *            id of the session upating the flags
-     * @throws MailboxException
-     * @see #flagsUpdated(MessageResult, long)
-     */
-    public synchronized void flagsUpdated(Collection messageResults,
-            long sessionId) throws MailboxException {
-        if (messageResults != null) {
-            for (final Iterator it = messageResults.iterator(); it.hasNext();) 
{
-                final MessageResult result = (MessageResult) it.next();
-                flagsUpdated(result, sessionId);
-            }
-        }
-    }
-
-    /**
-     * Indicates that the flags on the given message may have been updated.
-     * 
-     * @param messageResult
-     *            result of update
-     * @param sessionId
-     *            id of the session updating the flags
-     * @throws MailboxException
-     */
-    public synchronized void flagsUpdated(MessageResult messageResult,
-            long sessionId) throws MailboxException {
-        if (messageResult != null) {
-            final Flags flags = messageResult.getFlags();
-            final long uid = messageResult.getUid();
-            final Long uidLong = new Long(uid);
-            updatedFlags(uid, flags, uidLong, sessionId);
-        }
-    }
-
-    public synchronized void found(UidRange range,
-            final Collection<MessageResult> messageResults) throws 
MessagingException {
-        final Map<Long, Flags> flagsByIndex = new HashMap<Long, Flags>();
-        for (MessageResult result: messageResults) {
-            flagsByIndex.put(result.getUid(), result.getFlags());
-        }
-        found(range, flagsByIndex);
-    }
-
-    public synchronized void found(UidRange range,
-            final Map<Long, Flags> flagsByIndex) {
-        Set<Long> expectedSet = getSubSet(range);
+    public synchronized void found(UidRange range, final Map<Long, Flags> 
flagsByIndex) {
+        final Set<Long> expectedSet = getSubSet(range);
         for (Map.Entry<Long, Flags> entry:flagsByIndex.entrySet()) {
-            long uid = entry.getKey();
-            if (uid > lastScannedUid) {
-                lastScannedUid = uid;
-            }
+            final Long uid = entry.getKey();
             final Flags flags = entry.getValue();
-            final Long uidLong = new Long(uid);
-            if (expectedSet.contains(uidLong)) {
-                expectedSet.remove(uidLong);
-                updatedFlags(uid, flags, uidLong, Mailbox.ANONYMOUS_SESSION);
+            if (expectedSet.contains(uid)) {
+                expectedSet.remove(uid);
+                if (flags != null) {
+                    final Flags cachedFlags = cache.get(uid);
+                    if (cachedFlags == null || !flags.equals(cachedFlags)) {
+                        eventDispatcher.flagsUpdated(uid, 
Mailbox.ANONYMOUS_SESSION, cachedFlags, flags);
+                    }
+                }
             } else {
-                cache.put(uidLong, flags);
-                if (uid > lastUidAtStart) {
+                if (uid > lastUid) {
                     eventDispatcher.added(uid, Mailbox.ANONYMOUS_SESSION);
+                    lastUid = uid;
                 }
             }
-        }
-
-        if (lastScannedUid > lastUid) {
-            lastUid = lastScannedUid;
-        }
-        if (range.getToUid() == UID_INFINITY || range.getToUid() >= lastUid) {
-            lastScannedUid = lastUid;
-        } else if (range.getToUid() != UID_INFINITY
-                && range.getToUid() < lastUid
-                && range.getToUid() > lastScannedUid) {
-            lastScannedUid = range.getToUid();
+            cache.put(uid, flags);
         }
 
         for (Iterator iter = expectedSet.iterator(); iter.hasNext();) {
@@ -180,17 +115,6 @@
         }
     }
 
-    private void updatedFlags(final long uid, final Flags flags,
-            final Long uidLong, final long sessionId) {
-        if (flags != null) {
-            Flags cachedFlags = cache.get(uidLong);
-            if (cachedFlags == null || !flags.equals(cachedFlags)) {
-                eventDispatcher.flagsUpdated(uid, sessionId, cachedFlags, 
flags);
-                cache.put(uidLong, flags);
-            }
-        }
-    }
-
     private SortedSet<Long> getSubSet(UidRange range) {
         final Long rangeStartLong = new Long(range.getFromUid());
         if (range.getToUid() > 0) {
@@ -203,33 +127,21 @@
         } else {
             return new TreeSet<Long>(cache.tailMap(rangeStartLong).keySet());
         }
-
     }
 
-    public synchronized void found(MessageResult messageResult)
-            throws MessagingException {
+    public synchronized void found(MessageResult messageResult) throws 
MessagingException {
         if (messageResult != null) {
             long uid = messageResult.getUid();
             Collection<MessageResult> results = new ArrayList<MessageResult>();
             results.add(messageResult);
-            found(new UidRange(uid, uid), results);
-        }
-    }
-
-    public synchronized long getLastUid() {
-        return lastUid;
-    }
-
-    public synchronized void foundLastUid(long foundLastUid) {
-        if (foundLastUid > lastUid) {
-            lastUid = foundLastUid;
+            final Map<Long, Flags> flagsByIndex = new HashMap<Long, Flags>();
+            for (MessageResult result: results) {
+                flagsByIndex.put(result.getUid(), result.getFlags());
+            }
+            found(new UidRange(uid, uid), flagsByIndex);
         }
     }
-
-    public synchronized long getLastScannedUid() {
-        return lastScannedUid;
-    }
-
+    
     public synchronized void addMailboxListener(MailboxListener listener) {
         eventDispatcher.addMailboxListener(listener);
     }
@@ -241,5 +153,4 @@
     public void reportRenamed(String to) {
         eventDispatcher.mailboxRenamed(to, Mailbox.ANONYMOUS_SESSION);
     }
-
 }

Modified: 
james/protocols/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=737045&r1=737044&r2=737045&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
 (original)
+++ 
james/protocols/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
 Fri Jan 23 07:15:37 2009
@@ -350,8 +350,8 @@
         if (mailbox == null) {
             throw new MailboxNotFoundException("Mailbox has been deleted");
         } else {
-            getUidChangeTracker().foundLastUid(mailbox.getLastUid());
-            return getUidChangeTracker().getLastUid() + 1;
+            final long lastUid = mailbox.getLastUid();
+            return lastUid + 1;
         }
     }
 

Modified: 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=737045&r1=737044&r2=737045&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
 (original)
+++ 
james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
 Fri Jan 23 07:15:37 2009
@@ -600,9 +600,8 @@
                             .retrieveByPK(mailboxRow.getPrimaryKey());
                     if (myMailboxRow != null) {
                         mailboxRow = myMailboxRow;
-                        getUidChangeTracker().foundLastUid(
-                                mailboxRow.getLastUid());
-                        return getUidChangeTracker().getLastUid() + 1;
+                        final long lastUid = mailboxRow.getLastUid();
+                        return lastUid + 1;
                     } else {
                         throw new MailboxException(
                                 "Mailbox has been deleted");



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

Reply via email to