Lines 124-158
Link Here
|
124 |
DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(dataFile))); |
124 |
DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(dataFile))); |
125 |
boolean valid = false, dirty = false; |
125 |
boolean valid = false, dirty = false; |
126 |
int size = 0; |
126 |
int size = 0; |
|
|
127 |
List readResults = new ArrayList(); |
127 |
try { |
128 |
try { |
128 |
long time = System.currentTimeMillis(); |
129 |
// Read local file info |
|
|
130 |
print(" - read local files info"); //$NON-NLS-1$ |
129 |
String lastBuildName = stream.readUTF(); |
131 |
String lastBuildName = stream.readUTF(); |
|
|
132 |
// First field is either the build name or, since 3.5, the version number |
133 |
int version = 0; |
134 |
boolean newVersion = true; |
135 |
File versionDataDir = null; |
136 |
if (lastBuildName.startsWith("version")) { //$NON-NLS-1$ |
137 |
int index = lastBuildName.indexOf('='); |
138 |
if (index > 0) { |
139 |
try { |
140 |
version = Integer.parseInt(lastBuildName.substring(index+1)); |
141 |
newVersion = version != LOCAL_DATA_VERSION; |
142 |
} |
143 |
catch (Exception ex) { |
144 |
// skip all exception |
145 |
} |
146 |
} |
147 |
// next field is the build name |
148 |
lastBuildName = stream.readUTF(); |
149 |
} |
150 |
|
151 |
// Save old version files if necessary |
152 |
if (newVersion) { |
153 |
StringBuffer versionName = version < 10 |
154 |
? new StringBuffer("v0") //$NON-NLS-1$ |
155 |
: new StringBuffer("v"); //$NON-NLS-1$ |
156 |
versionName.append(version); |
157 |
versionDataDir = new File(dir, versionName.toString()); |
158 |
if (!versionDataDir.exists()) versionDataDir.mkdir(); |
159 |
if (versionDataDir.exists()) { |
160 |
File oldDataFile = new File(versionDataDir, getName()+".dat"); //$NON-NLS-1$ |
161 |
copyFile(dataFile, oldDataFile); |
162 |
} |
163 |
} |
164 |
|
165 |
// Next field is the number of scenarios for the component |
130 |
size = stream.readInt(); |
166 |
size = stream.readInt(); |
|
|
167 |
|
168 |
// Then follows all the scenario information |
131 |
for (int i=0; i<size; i++) { |
169 |
for (int i=0; i<size; i++) { |
|
|
170 |
// ... which starts with the scenario id |
132 |
int scenario_id = stream.readInt(); |
171 |
int scenario_id = stream.readInt(); |
133 |
ScenarioResults scenarioResults = getScenarioResults(scenarios, scenario_id); |
172 |
ScenarioResults scenarioResults = getScenarioResults(scenarios, scenario_id); |
134 |
if (scenarioResults != null) { |
173 |
if (scenarioResults != null) { |
135 |
scenarioResults.parent = this; |
174 |
scenarioResults.parent = this; |
136 |
scenarioResults.print = this.print; |
175 |
scenarioResults.print = this.print; |
137 |
if (scenarioResults.readData(stream, lastBuildName)) { |
176 |
scenarioResults.readData(stream, version); |
138 |
dirty = true; |
177 |
readResults.add(scenarioResults); |
|
|
178 |
if (this.print) System.out.print('.'); |
179 |
} |
180 |
} |
181 |
println(""); //$NON-NLS-1$ |
182 |
|
183 |
// Read new values for the local result |
184 |
boolean first = true; |
185 |
long readTime = System.currentTimeMillis(); |
186 |
size = readResults.size(); |
187 |
for (int i=0; i<size; i++) { |
188 |
ScenarioResults scenarioResults = (ScenarioResults) readResults.get(i); |
189 |
long start = System.currentTimeMillis(); |
190 |
boolean newData = scenarioResults.readNewData(lastBuildName); |
191 |
long time = System.currentTimeMillis()-start; |
192 |
if (newData || newVersion) { |
193 |
if (first) { |
194 |
println(" - read DB contents:"); //$NON-NLS-1$ |
195 |
first = false; |
196 |
} |
197 |
dirty = true; |
198 |
print(" + scenario '"+scenarioResults.getShortName()+"': "); //$NON-NLS-1$ //$NON-NLS-2$ |
199 |
if (newData) { |
200 |
print(timeString(time)); |
201 |
print (" (values), "); //$NON-NLS-1$ |
139 |
} |
202 |
} |
140 |
addChild(scenarioResults, true); |
203 |
start = System.currentTimeMillis(); |
|
|
204 |
scenarioResults.completeResults(); |
205 |
time = System.currentTimeMillis()-start; |
206 |
print(timeString(time)); |
207 |
println(" (infos)"); //$NON-NLS-1$ |
141 |
} |
208 |
} |
142 |
if (dirty && (System.currentTimeMillis() - time) > 300000) { // save every 5mn |
209 |
addChild(scenarioResults, true); |
|
|
210 |
if (dirty && (System.currentTimeMillis() - readTime) > 300000) { // save every 5mn |
143 |
writeData(dir, true, true); |
211 |
writeData(dir, true, true); |
144 |
time = System.currentTimeMillis(); |
212 |
readTime = System.currentTimeMillis(); |
145 |
dirty = false; |
213 |
dirty = false; |
146 |
} |
214 |
} |
147 |
} |
215 |
} |
148 |
valid = true; |
216 |
valid = true; |
|
|
217 |
if (newVersion && versionDataDir != null) { |
218 |
println(" => previous data file has been saved to "+versionDataDir); //$NON-NLS-1$ |
219 |
} |
149 |
} finally { |
220 |
} finally { |
150 |
stream.close(); |
221 |
stream.close(); |
151 |
if (valid) { |
222 |
if (valid) { |
152 |
println(" => "+size+" scenarios data were read from file "+dataFile); //$NON-NLS-1$ //$NON-NLS-2$ |
223 |
println(" => "+size+" scenarios data were read from file "+dataFile); //$NON-NLS-1$ //$NON-NLS-2$ |
153 |
} else { |
224 |
} else { |
154 |
dataFile.delete(); |
225 |
dataFile.delete(); |
155 |
println(" => deleted file "+dataFile+" as it contained invalid data!!!"); //$NON-NLS-1$ //$NON-NLS-2$ |
226 |
println(" => deleted file "+dataFile+" as it contained invalid data!!!"); //$NON-NLS-1$ //$NON-NLS-2$ |
156 |
} |
227 |
} |
157 |
} |
228 |
} |
158 |
return dirty; |
229 |
return dirty; |
Lines 171-177
Link Here
|
171 |
if (tmpFile.exists()) { |
242 |
if (tmpFile.exists()) { |
172 |
if (dataFile.exists()) dataFile.delete(); |
243 |
if (dataFile.exists()) dataFile.delete(); |
173 |
tmpFile.renameTo(dataFile); |
244 |
tmpFile.renameTo(dataFile); |
174 |
println(" => rename temporary file to "+dataFile); //$NON-NLS-1$ |
245 |
println(" => rename temporary file to "+dataFile); //$NON-NLS-1$ |
175 |
} |
246 |
} |
176 |
return; |
247 |
return; |
177 |
} |
248 |
} |
Lines 190-195
Link Here
|
190 |
try { |
261 |
try { |
191 |
DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); |
262 |
DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); |
192 |
int size = this.children.size(); |
263 |
int size = this.children.size(); |
|
|
264 |
stream.writeUTF("version="+LOCAL_DATA_VERSION); //$NON-NLS-1$ |
193 |
stream.writeUTF(getPerformance().getName()); |
265 |
stream.writeUTF(getPerformance().getName()); |
194 |
stream.writeInt(size); |
266 |
stream.writeInt(size); |
195 |
for (int i=0; i<size; i++) { |
267 |
for (int i=0; i<size; i++) { |
Lines 197-203
Link Here
|
197 |
scenarioResults.write(stream); |
269 |
scenarioResults.write(stream); |
198 |
} |
270 |
} |
199 |
stream.close(); |
271 |
stream.close(); |
200 |
println(" => extracted data "+(temp?"temporarily ":"")+"written in file "+file); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
272 |
println(" => extracted data "+(temp?"temporarily ":"")+"written in file "+file); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
201 |
} catch (FileNotFoundException e) { |
273 |
} catch (FileNotFoundException e) { |
202 |
System.err.println("can't create output file"+file); //$NON-NLS-1$ |
274 |
System.err.println("can't create output file"+file); //$NON-NLS-1$ |
203 |
} catch (IOException e) { |
275 |
} catch (IOException e) { |