speedup: call force() only at the end of the build, between chunk builds drop only...
[idea/community.git] / jps / jps-builders / src / org / jetbrains / jps / server / ProjectDescriptor.java
1 package org.jetbrains.jps.server;
2
3 import org.jetbrains.jps.Project;
4 import org.jetbrains.jps.incremental.FSState;
5 import org.jetbrains.jps.incremental.ModuleRootsIndex;
6 import org.jetbrains.jps.incremental.storage.BuildDataManager;
7 import org.jetbrains.jps.incremental.storage.ProjectTimestamps;
8
9 import java.io.IOException;
10
11 /**
12 * @author Eugene Zhuravlev
13 *         Date: 1/8/12
14 */
15 public final class ProjectDescriptor {
16   public final String projectName;
17   public final Project project;
18   public final FSState fsState;
19   public final ProjectTimestamps timestamps;
20   public final BuildDataManager dataManager;
21   public ModuleRootsIndex rootsIndex;
22
23   private int myUseCounter = 1;
24
25   public ProjectDescriptor(String projectName, Project project, FSState fsState, ProjectTimestamps timestamps, BuildDataManager dataManager) {
26     this.projectName = projectName;
27     this.project = project;
28     this.fsState = fsState;
29     this.timestamps = timestamps;
30     this.dataManager = dataManager;
31     this.rootsIndex = new ModuleRootsIndex(project);
32   }
33   public synchronized void incUsageCounter() {
34     myUseCounter++;
35   }
36
37   public void release() {
38     boolean shouldClose;
39     synchronized (this) {
40       --myUseCounter;
41       shouldClose = myUseCounter == 0;
42     }
43     if (shouldClose) {
44       try {
45         timestamps.close();
46       }
47       finally {
48         try {
49           dataManager.close();
50         }
51         catch (IOException e) {
52           e.printStackTrace(System.err);
53         }
54       }
55     }
56     else {
57       timestamps.getStorage().force();
58       dataManager.flush(false);
59     }
60   }
61 }