Class MessageCache


  • public class MessageCache
    extends java.lang.Object
    A cache of IMAPMessage objects along with the mapping from message number to IMAP sequence number. All operations on this object are protected by the messageCacheLock in IMAPFolder.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private IMAPFolder folder
      The folder these messages belong to.
      private MailLogger logger  
      private IMAPMessage[] messages  
      private int[] seqnums  
      private int size  
      private static int SLOP
      Grow the array by at least this much, to avoid constantly reallocating the array.
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageCache​(int size, boolean debug)
      Constructor for debugging and testing.
      MessageCache​(IMAPFolder folder, IMAPStore store, int size)
      Construct a new message cache of the indicated size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMessages​(int count, int newSeqNum)
      Add count messages to the cache.
      private void ensureCapacity​(int newsize, int newSeqNum)  
      void expungeMessage​(int seqnum)
      Expunge the message with the given sequence number.
      IMAPMessage getMessage​(int msgnum)
      Get the message object for the indicated message number.
      IMAPMessage getMessageBySeqnum​(int seqnum)
      Get the message object for the indicated sequence number.
      private int msgnumOf​(int seqnum)
      Return the message number for the given sequence number.
      IMAPMessage[] removeExpungedMessages()
      Remove all the expunged messages from the array, returning a list of removed message objects.
      IMAPMessage[] removeExpungedMessages​(Message[] msgs)
      Remove expunged messages in msgs from the array, returning a list of removed message objects.
      int seqnumOf​(int msgnum)
      Return the sequence number for the given message number.
      private void shrink​(int newend, int oldend)
      Shrink the messages and seqnums arrays.
      int size()
      Size of cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • seqnums

        private int[] seqnums
      • size

        private int size
      • folder

        private IMAPFolder folder
        The folder these messages belong to.
      • SLOP

        private static final int SLOP
        Grow the array by at least this much, to avoid constantly reallocating the array.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MessageCache

        MessageCache​(IMAPFolder folder,
                     IMAPStore store,
                     int size)
        Construct a new message cache of the indicated size.
      • MessageCache

        MessageCache​(int size,
                     boolean debug)
        Constructor for debugging and testing.
    • Method Detail

      • size

        public int size()
        Size of cache.
        Returns:
        the size of the cache
      • getMessage

        public IMAPMessage getMessage​(int msgnum)
        Get the message object for the indicated message number. If the message object hasn't been created, create it.
        Parameters:
        msgnum - the message number
        Returns:
        the message
      • getMessageBySeqnum

        public IMAPMessage getMessageBySeqnum​(int seqnum)
        Get the message object for the indicated sequence number. If the message object hasn't been created, create it. Return null if there's no message with that sequence number.
        Parameters:
        seqnum - the sequence number of the message
        Returns:
        the message
      • expungeMessage

        public void expungeMessage​(int seqnum)
        Expunge the message with the given sequence number.
        Parameters:
        seqnum - the sequence number of the message to expunge
      • removeExpungedMessages

        public IMAPMessage[] removeExpungedMessages()
        Remove all the expunged messages from the array, returning a list of removed message objects.
        Returns:
        the removed messages
      • removeExpungedMessages

        public IMAPMessage[] removeExpungedMessages​(Message[] msgs)
        Remove expunged messages in msgs from the array, returning a list of removed message objects. All messages in msgs must be IMAPMessage objects from this folder.
        Parameters:
        msgs - the messages
        Returns:
        the removed messages
      • shrink

        private void shrink​(int newend,
                            int oldend)
        Shrink the messages and seqnums arrays. newend is one past last valid element. oldend is one past the previous last valid element.
      • addMessages

        public void addMessages​(int count,
                                int newSeqNum)
        Add count messages to the cache. newSeqNum is the sequence number of the first message added.
        Parameters:
        count - the number of messges
        newSeqNum - sequence number of first message
      • ensureCapacity

        private void ensureCapacity​(int newsize,
                                    int newSeqNum)
      • seqnumOf

        public int seqnumOf​(int msgnum)
        Return the sequence number for the given message number.
        Parameters:
        msgnum - the message number
        Returns:
        the sequence number
      • msgnumOf

        private int msgnumOf​(int seqnum)
        Return the message number for the given sequence number.