jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java
changeset 7803 56bc97d69d93
parent 5506 202f599c92aa
child 8543 e5ec12a932da
equal deleted inserted replaced
7802:74f2ee2b62ba 7803:56bc97d69d93
   352      * is sync'ed by overwriting our prefsCache with the preference map last
   352      * is sync'ed by overwriting our prefsCache with the preference map last
   353      * written out to disk (by the other VM), and then replaying this change
   353      * written out to disk (by the other VM), and then replaying this change
   354      * log against that map.  The resulting map is then written back
   354      * log against that map.  The resulting map is then written back
   355      * to the disk.
   355      * to the disk.
   356      */
   356      */
   357     final List<Change> changeLog = new ArrayList<Change>();
   357     final List<Change> changeLog = new ArrayList<>();
   358 
   358 
   359     /**
   359     /**
   360      * Represents a change to a preference.
   360      * Represents a change to a preference.
   361      */
   361      */
   362     private abstract class Change {
   362     private abstract class Change {
   505                 return null;
   505                 return null;
   506             }
   506             }
   507         });
   507         });
   508         if (newNode) {
   508         if (newNode) {
   509             // These 2 things guarantee node will get wrtten at next flush/sync
   509             // These 2 things guarantee node will get wrtten at next flush/sync
   510             prefsCache = new TreeMap<String, String>();
   510             prefsCache = new TreeMap<>();
   511             nodeCreate = new NodeCreate();
   511             nodeCreate = new NodeCreate();
   512             changeLog.add(nodeCreate);
   512             changeLog.add(nodeCreate);
   513         }
   513         }
   514     }
   514     }
   515 
   515 
   548 
   548 
   549         try {
   549         try {
   550             loadCache();
   550             loadCache();
   551         } catch(Exception e) {
   551         } catch(Exception e) {
   552             // assert lastSyncTime == 0;
   552             // assert lastSyncTime == 0;
   553             prefsCache = new TreeMap<String, String>();
   553             prefsCache = new TreeMap<>();
   554         }
   554         }
   555     }
   555     }
   556 
   556 
   557     /**
   557     /**
   558      * Attempt to load prefsCache from the backing store.  If the attempt
   558      * Attempt to load prefsCache from the backing store.  If the attempt
   565     private void loadCache() throws BackingStoreException {
   565     private void loadCache() throws BackingStoreException {
   566         try {
   566         try {
   567             AccessController.doPrivileged(
   567             AccessController.doPrivileged(
   568                 new PrivilegedExceptionAction<Void>() {
   568                 new PrivilegedExceptionAction<Void>() {
   569                 public Void run() throws BackingStoreException {
   569                 public Void run() throws BackingStoreException {
   570                     Map<String, String> m = new TreeMap<String, String>();
   570                     Map<String, String> m = new TreeMap<>();
   571                     long newLastSyncTime = 0;
   571                     long newLastSyncTime = 0;
   572                     try {
   572                     try {
   573                         newLastSyncTime = prefsFile.lastModified();
   573                         newLastSyncTime = prefsFile.lastModified();
   574                         FileInputStream fis = new FileInputStream(prefsFile);
   574                         FileInputStream fis = new FileInputStream(prefsFile);
   575                         XmlSupport.importMap(fis, m);
   575                         XmlSupport.importMap(fis, m);
   579                             getLogger().warning("Invalid preferences format in "
   579                             getLogger().warning("Invalid preferences format in "
   580                                                         +  prefsFile.getPath());
   580                                                         +  prefsFile.getPath());
   581                             prefsFile.renameTo( new File(
   581                             prefsFile.renameTo( new File(
   582                                                     prefsFile.getParentFile(),
   582                                                     prefsFile.getParentFile(),
   583                                                   "IncorrectFormatPrefs.xml"));
   583                                                   "IncorrectFormatPrefs.xml"));
   584                             m = new TreeMap<String, String>();
   584                             m = new TreeMap<>();
   585                         } else if (e instanceof FileNotFoundException) {
   585                         } else if (e instanceof FileNotFoundException) {
   586                         getLogger().warning("Prefs file removed in background "
   586                         getLogger().warning("Prefs file removed in background "
   587                                            + prefsFile.getPath());
   587                                            + prefsFile.getPath());
   588                         } else {
   588                         } else {
   589                             throw new BackingStoreException(e);
   589                             throw new BackingStoreException(e);
   644 
   644 
   645     protected String[] childrenNamesSpi() {
   645     protected String[] childrenNamesSpi() {
   646         return AccessController.doPrivileged(
   646         return AccessController.doPrivileged(
   647             new PrivilegedAction<String[]>() {
   647             new PrivilegedAction<String[]>() {
   648                 public String[] run() {
   648                 public String[] run() {
   649                     List<String> result = new ArrayList<String>();
   649                     List<String> result = new ArrayList<>();
   650                     File[] dirContents = dir.listFiles();
   650                     File[] dirContents = dir.listFiles();
   651                     if (dirContents != null) {
   651                     if (dirContents != null) {
   652                         for (int i = 0; i < dirContents.length; i++)
   652                         for (int i = 0; i < dirContents.length; i++)
   653                             if (dirContents[i].isDirectory())
   653                             if (dirContents[i].isDirectory())
   654                                 result.add(nodeName(dirContents[i].getName()));
   654                                 result.add(nodeName(dirContents[i].getName()));
   792                 lastSyncTime = lastModifiedTime;
   792                 lastSyncTime = lastModifiedTime;
   793             }
   793             }
   794         } else if (lastSyncTime != 0 && !dir.exists()) {
   794         } else if (lastSyncTime != 0 && !dir.exists()) {
   795             // This node was removed in the background.  Playback any changes
   795             // This node was removed in the background.  Playback any changes
   796             // against a virgin (empty) Map.
   796             // against a virgin (empty) Map.
   797             prefsCache = new TreeMap<String, String>();
   797             prefsCache = new TreeMap<>();
   798             replayChanges();
   798             replayChanges();
   799         }
   799         }
   800         if (!changeLog.isEmpty()) {
   800         if (!changeLog.isEmpty()) {
   801             writeBackCache();  // Creates directory & file if necessary
   801             writeBackCache();  // Creates directory & file if necessary
   802            /*
   802            /*