Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 775:eedad2ddad14
Removed race-condition while shapefile creation (issue164).
gnv-artifacts/trunk@841 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 15:20:32 +0000 |
parents | 93489a0c1328 |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
774:d0a39efbfd96 | 775:eedad2ddad14 |
---|---|
43 import de.intevation.gnv.state.InputData; | 43 import de.intevation.gnv.state.InputData; |
44 import de.intevation.gnv.state.OutputStateBase; | 44 import de.intevation.gnv.state.OutputStateBase; |
45 | 45 |
46 import de.intevation.gnv.state.exception.StateException; | 46 import de.intevation.gnv.state.exception.StateException; |
47 | 47 |
48 import de.intevation.gnv.utils.ExclusiveExec; | |
48 import de.intevation.gnv.utils.FileUtils; | 49 import de.intevation.gnv.utils.FileUtils; |
49 import de.intevation.gnv.utils.MapfileGenerator; | 50 import de.intevation.gnv.utils.MapfileGenerator; |
50 import de.intevation.gnv.utils.MetaWriter; | 51 import de.intevation.gnv.utils.MetaWriter; |
51 import de.intevation.gnv.utils.Pair; | 52 import de.intevation.gnv.utils.Pair; |
52 import de.intevation.gnv.utils.ShapeFileWriter; | 53 import de.intevation.gnv.utils.ShapeFileWriter; |
220 FileUtils.createZipArchive(dir, output); | 221 FileUtils.createZipArchive(dir, output); |
221 } | 222 } |
222 } | 223 } |
223 else { | 224 else { |
224 AttributedPoint2ds result = getResult(uuid, callContext); | 225 AttributedPoint2ds result = getResult(uuid, callContext); |
226 ExclusiveExec.UniqueKey k = ExclusiveExec.INSTANCE.acquire(uuid); | |
225 if (result != null | 227 if (result != null |
226 && (p = writeToShapeFile(uuid, result, callContext)) != null) { | 228 && (p = writeToShapeFile(uuid, result, callContext)) != null) { |
227 FileUtils.createZipArchive(new File(p), output); | 229 FileUtils.createZipArchive(new File(p), output); |
230 ExclusiveExec.INSTANCE.release(k); | |
228 } | 231 } |
229 } | 232 } |
230 } | 233 } |
231 catch (IOException ioe) { | 234 catch (IOException ioe) { |
232 log.error(ioe.getLocalizedMessage(), ioe); | 235 log.error(ioe.getLocalizedMessage(), ioe); |
272 | 275 |
273 pathElement.setTextContent(path); | 276 pathElement.setTextContent(path); |
274 } | 277 } |
275 else { | 278 else { |
276 AttributedPoint2ds result = getResult(uuid, callContext); | 279 AttributedPoint2ds result = getResult(uuid, callContext); |
280 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid); | |
277 if (result != null | 281 if (result != null |
278 && (path = writeToShapeFile(uuid, result, callContext)) != null) { | 282 && (path = writeToShapeFile(uuid, result, callContext)) != null) { |
283 ExclusiveExec.INSTANCE.release(key); | |
279 | 284 |
280 String paramType = findParameterType(callContext); | 285 String paramType = findParameterType(callContext); |
281 | 286 |
282 InputData inputTitle = this.inputData.get("title"); | 287 InputData inputTitle = this.inputData.get("title"); |
283 String title = getLayerTitle(inputData); | 288 String title = getLayerTitle(inputData); |
292 log.debug("Layer title: " + title); | 297 log.debug("Layer title: " + title); |
293 } | 298 } |
294 | 299 |
295 Document meta = MetaWriter.writeHorizontalcrosssectionMeta( | 300 Document meta = MetaWriter.writeHorizontalcrosssectionMeta( |
296 callContext, uuid, path, paramType); | 301 callContext, uuid, path, paramType); |
302 | |
297 if (meta != null) { | 303 if (meta != null) { |
298 MapfileGenerator.getInstance().update(); | 304 MapfileGenerator.getInstance().update(); |
299 return meta; | 305 return meta; |
300 } | 306 } |
301 | 307 |
347 boolean success = false; | 353 boolean success = false; |
348 boolean createdDir = false; | 354 boolean createdDir = false; |
349 | 355 |
350 try { | 356 try { |
351 synchronized (shapeFileLock) { | 357 synchronized (shapeFileLock) { |
352 int count = 0; | 358 if (shapeDir.exists()) { |
353 while (shapeDir.exists()) { | 359 FileUtils.deleteContent(shapeDir); |
354 shapeDir = new File(baseDir, uuid + "-" + count); | 360 } |
355 ++count; | 361 else if (!shapeDir.mkdirs()) { |
356 } | |
357 | |
358 if (!shapeDir.mkdirs()) { | |
359 log.error("cannot create directory '" | 362 log.error("cannot create directory '" |
360 + shapeDir.getAbsolutePath() + "'"); | 363 + shapeDir.getAbsolutePath() + "'"); |
361 return null; | 364 return null; |
362 } | 365 } |
363 createdDir = true; | 366 createdDir = true; |