Changeset 691


Ignore:
Timestamp:
08/21/10 15:51:17 (21 months ago)
Author:
octorian
Message:

Added static thread queue for saving to cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MessageNode.java

    r655 r691  
    6161import org.logicprobe.LogicMail.util.EventListenerList; 
    6262import org.logicprobe.LogicMail.util.StringParser; 
     63import org.logicprobe.LogicMail.util.ThreadQueue; 
    6364 
    6465/** 
     
    165166        private boolean refreshInProgress; 
    166167 
     168        /** Thread queue for calls to MailFileManager. */ 
     169        private static final ThreadQueue threadQueue = new ThreadQueue(); 
     170         
    167171        /** 
    168172         * Instantiates a new message node. 
     
    627631        /** 
    628632         * Commits the current state of the message to the cache, if applicable. 
    629          *  
    630          * @return True if written to cache, false otherwise 
    631          */ 
    632         boolean commitMessage() { 
    633                 boolean result = false; 
     633         */ 
     634        void commitMessage() { 
     635            boolean writeToCache; 
    634636                synchronized(messageContent) { 
    635                         if(!isCached() && isCachable()) { 
    636                                 try { 
    637                                         MailFileManager.getInstance().writeMessage(this); 
    638                                         setCached(true); 
    639                                         result = true; 
    640                                 } catch (IOException e) { 
    641                                         System.err.println("-->Unable to write message: " + e.getMessage()); 
    642                                 } catch (Throwable t) { 
    643                                         System.err.println("-->Unable to write message: " + t.getMessage()); 
    644                                 } 
    645                         } 
    646                 } 
    647                 return result; 
     637                    writeToCache = !isCached() && isCachable(); 
     638                } 
     639                if(!writeToCache) { return; } 
     640                 
     641            synchronized (threadQueue) { 
     642                threadQueue.invokeLater(new Runnable() { 
     643                    public void run() { 
     644                        synchronized(messageContent) { 
     645                            try { 
     646                                MailFileManager.getInstance().writeMessage(MessageNode.this); 
     647                                setCached(true); 
     648                            } catch (Throwable t) { 
     649                                EventLogger.logEvent(AppInfo.GUID, 
     650                                        ("Unable to write message to cache\r\n" 
     651                                                + t.getMessage()).getBytes(), 
     652                                                EventLogger.ERROR); 
     653                            } 
     654                        } 
     655                    } 
     656                }); 
     657            } 
    648658        } 
    649659         
Note: See TracChangeset for help on using the changeset viewer.