Changeset 1229 for trunk


Ignore:
Timestamp:
02/04/19 10:54:41 (5 years ago)
Author:
bln4
Message:

org.expeditee.gui.Frame ->
org.expeditee.gui.FrameIO ->

When loading a frame and deciding if the cache should be used, the file system is now consulted to check if there is a more recent version available. If there is then the cache is not used. This is useful for collaborative frame authoring when access to frame is controlled via a system such as google drive.

Location:
trunk/src/org/expeditee/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/Frame.java

    r1227 r1229  
    101101
    102102        private String _modifiedDate = null;
     103        private long _modifiedDatePrecise;
    103104
    104105        private String _frozenDate = null;
     
    803804         * @param date
    804805         *            The date to set as the last modified date.
    805          */
    806         public void setLastModifyDate(String date)
    807         {
     806         * @param precise The millisecond precision last modified date.
     807         */
     808        public void setLastModifyDate(String date, long precise) {
    808809                _modifiedDate = date;
     810                _modifiedDatePrecise = precise;
     811        }
     812       
     813        /**
     814         * Sets the last modified date of this Frame to the given String.
     815         * Used during startup.  If able to be more precise then use the overloaded function.
     816         *
     817         * @param date
     818         *            The date to set as the last modified date.
     819         */
     820        public void setLastModifyDate(String date) {
     821                _modifiedDate = date;
     822                _modifiedDatePrecise = -1l;
    809823        }
    810824
     
    815829         *            The date to set as the last frozen date.
    816830         */
    817         public void setFrozenDate(String date)
    818         {
     831        public void setFrozenDate(String date)  {
    819832                _frozenDate = date;
    820833        }
     
    11981211        }
    11991212
    1200         public String getLastModifyDate()
    1201         {
     1213        public String getLastModifyDate() {
    12021214                return _modifiedDate;
     1215        }
     1216       
     1217        public long getLastModifyPrecise() {
     1218                return _modifiedDatePrecise;
    12031219        }
    12041220
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1227 r1229  
    220220                        Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName + " from cache.");
    221221                        Frame frame = _Cache.get(frameNameLower);
    222                         return frame;
     222                       
     223                        // if frame is cache is older than the one on disk then don't use the cached one
     224                        String p = frame.getPath() + frame.getNumber() + ".exp";
     225                        File file = new File(p);
     226                        if (file.lastModified() <= frame.getLastModifyPrecise()) {
     227                                return frame;
     228                        }
    223229                }
    224230
     
    230236
    231237        //Loads the 'restore' version of a frame if there is one
    232                 public static Frame LoadRestoreFrame(Frame frameToRestore) {                   
     238        public static Frame LoadRestoreFrame(Frame frameToRestore) {                   
    233239                       
    234                         String fullPath = getFrameFullPathName(frameToRestore.getPath(), frameToRestore
    235                                         .getName());
    236                         //System.out.println("fullpath: " + fullPath);
    237                         String restoreVersion = fullPath + ".restore";
    238                         //System.out.println("restoreversion" + restoreVersion);
    239                         File source = new File(restoreVersion);
    240                         File dest = new File(fullPath);
    241                        
    242                         FileChannel inputChannel = null;
    243                         FileChannel outputChannel = null;
    244                        
    245                         try{
    246                                         FileInputStream source_fis = new FileInputStream(source);
    247                                         inputChannel = source_fis.getChannel();
    248                                        
    249                                         FileOutputStream dest_fos = new FileOutputStream(dest);
    250                                         outputChannel = dest_fos.getChannel();
    251                                        
    252                                         outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
    253                                         inputChannel.close();
    254                                         outputChannel.close();
    255                                         source_fis.close();
    256                                         dest_fos.close();
    257                         }               
    258                         catch(Exception e){
     240                String fullPath = getFrameFullPathName(frameToRestore.getPath(), frameToRestore
     241                                .getName());
     242                //System.out.println("fullpath: " + fullPath);
     243                String restoreVersion = fullPath + ".restore";
     244                //System.out.println("restoreversion" + restoreVersion);
     245                File source = new File(restoreVersion);
     246                File dest = new File(fullPath);
     247               
     248                FileChannel inputChannel = null;
     249                FileChannel outputChannel = null;
     250               
     251                try{
     252                                FileInputStream source_fis = new FileInputStream(source);
     253                                inputChannel = source_fis.getChannel();
    259254                               
    260                                 System.err.println("No restore point detected.");
    261                         }
    262                         String frameName = frameToRestore.getName();
    263                         String frameNameLower = frameName.toLowerCase();
    264                        
    265                         // first try reading from cache
    266                         if (isCacheOn() && _Cache.containsKey(frameNameLower)) {
    267                                 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Clearing " + frameName
    268                                                 + " from cache.");
    269                                 _Cache.remove(frameNameLower);                         
    270                         }
    271                        
    272                         return LoadFrame(frameName, frameToRestore.getPath(), true);
    273                 }               
     255                                FileOutputStream dest_fos = new FileOutputStream(dest);
     256                                outputChannel = dest_fos.getChannel();
     257                               
     258                                outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
     259                                inputChannel.close();
     260                                outputChannel.close();
     261                                source_fis.close();
     262                                dest_fos.close();
     263                }               
     264                catch(Exception e){     
     265                        System.err.println("No restore point detected.");
     266                }
     267                String frameName = frameToRestore.getName();
     268                String frameNameLower = frameName.toLowerCase();
     269               
     270                // first try reading from cache
     271                if (isCacheOn() && _Cache.containsKey(frameNameLower)) {
     272                        Logger.Log(Logger.SYSTEM, Logger.LOAD, "Clearing " + frameName
     273                                        + " from cache.");
     274                        _Cache.remove(frameNameLower);                         
     275                }
     276               
     277                return LoadFrame(frameName, frameToRestore.getPath(), true);
     278        }               
    274279               
    275280        public static BufferedReader LoadPublicFrame(String frameName) {
     
    18091814
    18101815        public static void setSavedProperties(Frame toSave) {
    1811                 toSave.setLastModifyDate(Formatter.getDateTime());
     1816                toSave.setLastModifyDate(Formatter.getDateTime(), System.currentTimeMillis());
    18121817                toSave.setLastModifyUser(UserSettings.UserName.get());
    18131818                toSave.setVersion(toSave.getVersion() + 1);
Note: See TracChangeset for help on using the changeset viewer.