The fix of issue #34007 merged from prj40_prototype branch. QBE200309030100-BLD200309050745
authormentlicher@netbeans.org
Tue, 02 Sep 2003 17:04:12 +0000
changeset 3525ccc3ae59c7ce
parent 3524 8ba6f9a399d9
child 3526 ef79935b8153
The fix of issue #34007 merged from prj40_prototype branch.
vcscore/src/org/netbeans/modules/vcscore/objectintegrity/IntegritySupportMaintainer.java
vcscore/src/org/netbeans/modules/vcscore/objectintegrity/VcsObjectIntegritySupport.java
     1.1 --- a/vcscore/src/org/netbeans/modules/vcscore/objectintegrity/IntegritySupportMaintainer.java	Tue Sep 02 14:10:34 2003 +0000
     1.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/objectintegrity/IntegritySupportMaintainer.java	Tue Sep 02 17:04:12 2003 +0000
     1.3 @@ -168,7 +168,9 @@
     1.4                  boolean ok = false;
     1.5                  try {
     1.6                      oout = new ObjectOutputStream(new FileOutputStream(dbSaveFile));
     1.7 +                    vois.suspendChanges();
     1.8                      oout.writeObject(vois);
     1.9 +                    vois.resumeChanges();
    1.10                  } catch (java.io.IOException ioex) {
    1.11                      ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioex);
    1.12                  } finally {
     2.1 --- a/vcscore/src/org/netbeans/modules/vcscore/objectintegrity/VcsObjectIntegritySupport.java	Tue Sep 02 14:10:34 2003 +0000
     2.2 +++ b/vcscore/src/org/netbeans/modules/vcscore/objectintegrity/VcsObjectIntegritySupport.java	Tue Sep 02 17:04:12 2003 +0000
     2.3 @@ -105,6 +105,8 @@
     2.4      private transient PropertyChangeSupport propertyChangeSupport;
     2.5      private transient PropertyChangeListener doFileChangeListener;
     2.6      
     2.7 +    private transient boolean filesStorageLocked = false;
     2.8 +    
     2.9      //private List localFileNames = new ArrayList();
    2.10      /** A map of set of names of local secondary files by names of primary files. */
    2.11      private Map objectsWithLocalFiles = new HashMap();
    2.12 @@ -143,10 +145,20 @@
    2.13      
    2.14      private void copyDataFrom(VcsObjectIntegritySupport vois) {
    2.15          synchronized (objectsWithLocalFiles) {
    2.16 +            if (filesStorageLocked) {
    2.17 +                try {
    2.18 +                    objectsWithLocalFiles.wait();
    2.19 +                } catch (InterruptedException iex) { /* continue */ }
    2.20 +            }
    2.21              objectsWithLocalFiles.putAll(vois.objectsWithLocalFiles);
    2.22              filesMap.putAll(vois.filesMap);
    2.23          }
    2.24          synchronized (primaryLocalFiles) {
    2.25 +            if (filesStorageLocked) {
    2.26 +                try {
    2.27 +                    primaryLocalFiles.wait();
    2.28 +                } catch (InterruptedException iex) { /* continue */ }
    2.29 +            }
    2.30              primaryLocalFiles.addAll(vois.primaryLocalFiles);
    2.31          }
    2.32          ignoredSecondaryLocalFiles.addAll(vois.ignoredSecondaryLocalFiles);
    2.33 @@ -213,6 +225,33 @@
    2.34          //System.out.println("VOID DEActivated for ("+fsRootPath+"):"+fileSystem);
    2.35      }
    2.36      
    2.37 +    /**
    2.38 +     * Suspend the changes in the internal database. This is necessary to be
    2.39 +     * called e.g. before serialization or any other processes, that access
    2.40 +     * internal data. The changes are suspended until resumeChanges() is called.
    2.41 +     */
    2.42 +    public void suspendChanges() {
    2.43 +        synchronized (objectsWithLocalFiles) {
    2.44 +            synchronized (primaryLocalFiles) {
    2.45 +                filesStorageLocked = true;
    2.46 +            }
    2.47 +        }
    2.48 +    }
    2.49 +    
    2.50 +    /**
    2.51 +     * Resume the changes in the internal database. This must be called after
    2.52 +     * suspendChanges() and after the access to internal data is finished.
    2.53 +     */
    2.54 +    public void resumeChanges() {
    2.55 +        synchronized (objectsWithLocalFiles) {
    2.56 +            synchronized (primaryLocalFiles) {
    2.57 +                filesStorageLocked = false;
    2.58 +                primaryLocalFiles.notifyAll();
    2.59 +            }
    2.60 +            objectsWithLocalFiles.notifyAll();
    2.61 +        }
    2.62 +    }
    2.63 +    
    2.64      public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
    2.65          if (propertyChangeSupport != null) {
    2.66              //System.out.println(this+"addPropertyChangeListener("+l+")");
    2.67 @@ -297,12 +336,22 @@
    2.68              CacheFile pcFile = cache.getCacheFile(primaryFile, CacheHandler.STRAT_DISK, null);
    2.69              if (pcFile == null || pcFile.isLocal()) {
    2.70                  synchronized (primaryLocalFiles) {
    2.71 +                    if (filesStorageLocked) {
    2.72 +                        try {
    2.73 +                            primaryLocalFiles.wait();
    2.74 +                        } catch (InterruptedException iex) { /* continue */ }
    2.75 +                    }
    2.76                      primaryLocalFiles.add(primary.getPath());
    2.77                  }
    2.78                  changed = true;
    2.79                  continue;
    2.80              } else {
    2.81                  synchronized (primaryLocalFiles) {
    2.82 +                    if (filesStorageLocked) {
    2.83 +                        try {
    2.84 +                            primaryLocalFiles.wait();
    2.85 +                        } catch (InterruptedException iex) { /* continue */ }
    2.86 +                    }
    2.87                      if (primaryLocalFiles.remove(primary.getPath())) {
    2.88                          changed = true;
    2.89                      }
    2.90 @@ -336,6 +385,11 @@
    2.91                  }
    2.92              }
    2.93              synchronized (objectsWithLocalFiles) {
    2.94 +                if (filesStorageLocked) {
    2.95 +                    try {
    2.96 +                        objectsWithLocalFiles.wait();
    2.97 +                    } catch (InterruptedException iex) { /* continue */ }
    2.98 +                }
    2.99                  Set localSec = (Set) objectsWithLocalFiles.get(primaryFilePath);
   2.100                  if (localSec == null) {
   2.101                      localSec = new HashSet();
   2.102 @@ -375,6 +429,11 @@
   2.103          //System.out.println("ignoredSecondaryLocalFiles = "+ignoredSecondaryLocalFiles);
   2.104          boolean changed = false;
   2.105          synchronized (objectsWithLocalFiles) {
   2.106 +            if (filesStorageLocked) {
   2.107 +                try {
   2.108 +                    objectsWithLocalFiles.wait();
   2.109 +                } catch (InterruptedException iex) { /* continue */ }
   2.110 +            }
   2.111              for (int i = 0; i < ignoredFilePaths.length; i++) {
   2.112                  String primary = (String) filesMap.remove(ignoredFilePaths[i]);
   2.113                  if (primary != null) {
   2.114 @@ -428,6 +487,11 @@
   2.115              initialize(); // Assure, that we're initialized.
   2.116              boolean wasLocal;
   2.117              synchronized (primaryLocalFiles) {
   2.118 +                if (filesStorageLocked && primaryLocalFiles.contains(path)) {
   2.119 +                    try {
   2.120 +                        primaryLocalFiles.wait();
   2.121 +                    } catch (InterruptedException iex) { /* continue */ }
   2.122 +                }
   2.123                  wasLocal = primaryLocalFiles.remove(path);
   2.124              }
   2.125              if (wasLocal) {
   2.126 @@ -441,6 +505,11 @@
   2.127              }
   2.128              boolean changed = false;
   2.129              synchronized (objectsWithLocalFiles) {
   2.130 +                if (filesStorageLocked && filesMap.containsKey(path)) {
   2.131 +                    try {
   2.132 +                        objectsWithLocalFiles.wait();
   2.133 +                    } catch (InterruptedException iex) { /* continue */ }
   2.134 +                }
   2.135                  String primary = (String) filesMap.remove(path);
   2.136                  if (primary != null) {
   2.137                      // It was a local secondary file, so it needs to be removed.
   2.138 @@ -471,6 +540,11 @@
   2.139              initialize(); // Assure, that we're initialized.
   2.140              boolean changed = false;
   2.141              synchronized (objectsWithLocalFiles) {
   2.142 +                if (filesStorageLocked && objectsWithLocalFiles.containsKey(path)) {
   2.143 +                    try {
   2.144 +                        objectsWithLocalFiles.wait();
   2.145 +                    } catch (InterruptedException iex) { /* continue */ }
   2.146 +                }
   2.147                  // If it was a primary file, remove all local secondary files:
   2.148                  Set localSet = (Set) objectsWithLocalFiles.remove(path);
   2.149                  if (localSet != null) {
   2.150 @@ -486,8 +560,6 @@
   2.151      }
   2.152      
   2.153      /** is called each time the status of a file changes in cache.
   2.154 -     * The filesystem has to decide wheater it affects him (only in case when
   2.155 -     * there's not the 1-to-1 relationship between cache and fs.
   2.156       */
   2.157      public void statusChanged(CacheHandlerEvent event) {
   2.158          CacheFile cFile = event.getCacheFile();
   2.159 @@ -499,6 +571,11 @@
   2.160              boolean changed = false;
   2.161              if (cFile.isLocal()) {
   2.162                  synchronized (objectsWithLocalFiles) {
   2.163 +                    if (filesStorageLocked && objectsWithLocalFiles.containsKey(path)) {
   2.164 +                        try {
   2.165 +                            objectsWithLocalFiles.wait();
   2.166 +                        } catch (InterruptedException iex) { /* continue */ }
   2.167 +                    }
   2.168                      // If it was a primary file, remove all local secondary files:
   2.169                      Set localSet = (Set) objectsWithLocalFiles.remove(path);
   2.170                      if (localSet != null) {
   2.171 @@ -508,6 +585,11 @@
   2.172                              filesMap.remove(secondary);
   2.173                          }
   2.174                          synchronized (primaryLocalFiles) {
   2.175 +                            if (filesStorageLocked) {
   2.176 +                                try {
   2.177 +                                    primaryLocalFiles.wait();
   2.178 +                                } catch (InterruptedException iex) { /* continue */ }
   2.179 +                            }
   2.180                              primaryLocalFiles.add(path);
   2.181                          }
   2.182                          changed = true;
   2.183 @@ -519,6 +601,11 @@
   2.184                  }
   2.185              } else {
   2.186                  synchronized (objectsWithLocalFiles) {
   2.187 +                    if (filesStorageLocked && filesMap.containsKey(path)) {
   2.188 +                        try {
   2.189 +                            objectsWithLocalFiles.wait();
   2.190 +                        } catch (InterruptedException iex) { /* continue */ }
   2.191 +                    }
   2.192                      // If a secondary FileObject becomes non-local, remove it
   2.193                      // from the maps.
   2.194                      String primary = (String) filesMap.remove(path);
   2.195 @@ -531,6 +618,11 @@
   2.196                      }
   2.197                  }
   2.198                  synchronized (primaryLocalFiles) {
   2.199 +                    if (filesStorageLocked && primaryLocalFiles.contains(path)) {
   2.200 +                        try {
   2.201 +                            primaryLocalFiles.wait();
   2.202 +                        } catch (InterruptedException iex) { /* continue */ }
   2.203 +                    }
   2.204                      // If a primary file becomes non-local, an analysis must be made
   2.205                      if (primaryLocalFiles.remove(path)) {
   2.206                          // It was a local primary file; now it's not local, we need to
   2.207 @@ -552,6 +644,7 @@
   2.208              ignoredSecondaryLocalFiles = Collections.synchronizedSet(new HashSet());
   2.209          }
   2.210          initializeLock = new Object();
   2.211 +        filesStorageLocked = false;
   2.212      }
   2.213      
   2.214      /**