Revision: 20290 http://sourceforge.net/p/gate/code/20290 Author: ian_roberts Date: 2018-06-18 15:28:58 +0000 (Mon, 18 Jun 2018) Log Message: ----------- Back-porting the fix to https://github.com/GateNLP/gate-core/issues/52 - progress and status listeners were getting added but not removed in case of exceptions.
Modified Paths: -------------- gate/trunk/src/main/gate/Factory.java gate/trunk/src/main/gate/creole/ConditionalSerialController.java gate/trunk/src/main/gate/creole/SerialController.java gate/trunk/src/main/gate/gui/NameBearerHandle.java Modified: gate/trunk/src/main/gate/Factory.java =================================================================== --- gate/trunk/src/main/gate/Factory.java 2018-05-16 12:45:42 UTC (rev 20289) +++ gate/trunk/src/main/gate/Factory.java 2018-06-18 15:28:58 UTC (rev 20290) @@ -416,32 +416,34 @@ ResourceInstantiationException("Parameterisation failure" + e); } } + try { + // if the features of the resource have not been explicitly set, + // set them to the features of the resource data + if(res.getFeatures() == null || res.getFeatures().isEmpty()){ + FeatureMap fm = newFeatureMap(); + fm.putAll(resData.getFeatures()); + res.setFeatures(fm); + } + // add the features specified by the user + if(features != null) res.getFeatures().putAll(features); - // if the features of the resource have not been explicitly set, - // set them to the features of the resource data - if(res.getFeatures() == null || res.getFeatures().isEmpty()){ - FeatureMap fm = newFeatureMap(); - fm.putAll(resData.getFeatures()); - res.setFeatures(fm); - } - // add the features specified by the user - if(features != null) res.getFeatures().putAll(features); + // initialise the resource + if(DEBUG) Out.prln("Initialising resource " + res.toString()); + res = res.init(); - // initialise the resource - if(DEBUG) Out.prln("Initialising resource " + res.toString()); - res = res.init(); - - // remove the listeners if any - if(listeners != null && !listeners.isEmpty()) { - try { - if(DEBUG) Out.prln("Removing the listeners for " + res.toString()); - AbstractResource.removeResourceListeners(res, listeners); - } catch(Exception e) { - if (DEBUG) Out.prln( - "Failed to remove the listeners for " + res.toString() - ); - throw new - ResourceInstantiationException("Parameterisation failure" + e); + } finally { + // remove the listeners if any + if(listeners != null && !listeners.isEmpty()) { + try { + if(DEBUG) Out.prln("Removing the listeners for " + res.toString()); + AbstractResource.removeResourceListeners(res, listeners); + } catch(Exception e) { + if (DEBUG) Out.prln( + "Failed to remove the listeners for " + res.toString() + ); + throw new + ResourceInstantiationException("Parameterisation failure" + e); + } } } // record the instantiation on the resource data's stack Modified: gate/trunk/src/main/gate/creole/ConditionalSerialController.java =================================================================== --- gate/trunk/src/main/gate/creole/ConditionalSerialController.java 2018-05-16 12:45:42 UTC (rev 20289) +++ gate/trunk/src/main/gate/creole/ConditionalSerialController.java 2018-06-18 15:28:58 UTC (rev 20290) @@ -153,39 +153,39 @@ "\n" + e.toString() + "\n...nothing to lose any sleep over."); } + try { + //run the thing + if(strategiesList.get(componentIndex).shouldRun()){ + benchmarkFeatures.put(Benchmark.PR_NAME_FEATURE, currentPR.getName()); - //run the thing - if(strategiesList.get(componentIndex).shouldRun()){ - benchmarkFeatures.put(Benchmark.PR_NAME_FEATURE, currentPR.getName()); + long startTime = System.currentTimeMillis(); + // run the thing + Benchmark.executeWithBenchmarking(currentPR, + Benchmark.createBenchmarkId(Benchmark.PR_PREFIX + currentPR.getName(), + getBenchmarkId()), this, benchmarkFeatures); - long startTime = System.currentTimeMillis(); - // run the thing - Benchmark.executeWithBenchmarking(currentPR, - Benchmark.createBenchmarkId(Benchmark.PR_PREFIX + currentPR.getName(), - getBenchmarkId()), this, benchmarkFeatures); - - benchmarkFeatures.remove(Benchmark.PR_NAME_FEATURE); - - // calculate the time taken by the PR - long timeTakenByThePR = System.currentTimeMillis() - startTime; - Long time = prTimeMap.get(currentPR.getName()); - if(time == null) { - time = new Long(0); + benchmarkFeatures.remove(Benchmark.PR_NAME_FEATURE); + + // calculate the time taken by the PR + long timeTakenByThePR = System.currentTimeMillis() - startTime; + Long time = prTimeMap.get(currentPR.getName()); + if(time == null) { + time = new Long(0); + } + time = new Long(time.longValue() + timeTakenByThePR); + prTimeMap.put(currentPR.getName(), time); } - time = new Long(time.longValue() + timeTakenByThePR); - prTimeMap.put(currentPR.getName(), time); + } finally { + //remove the listeners + try{ + AbstractResource.removeResourceListeners(currentPR, listeners); + }catch(Exception e){ + // the listeners removing failed; nothing important + Err.prln("Could not clear listeners for " + + currentPR.getClass().getName() + + "\n" + e.toString() + "\n...nothing to lose any sleep over."); + } } - - - //remove the listeners - try{ - AbstractResource.removeResourceListeners(currentPR, listeners); - }catch(Exception e){ - // the listeners removing failed; nothing important - Err.prln("Could not clear listeners for " + - currentPR.getClass().getName() + - "\n" + e.toString() + "\n...nothing to lose any sleep over."); - } }//protected void runComponent(int componentIndex) /** Modified: gate/trunk/src/main/gate/creole/SerialController.java =================================================================== --- gate/trunk/src/main/gate/creole/SerialController.java 2018-05-16 12:45:42 UTC (rev 20289) +++ gate/trunk/src/main/gate/creole/SerialController.java 2018-06-18 15:28:58 UTC (rev 20290) @@ -218,36 +218,37 @@ + "\n" + e.toString() + "\n...nothing to lose any sleep over."); } - benchmarkFeatures.put(Benchmark.PR_NAME_FEATURE, currentPR.getName()); + try { + benchmarkFeatures.put(Benchmark.PR_NAME_FEATURE, currentPR.getName()); - long startTime = System.currentTimeMillis(); - // run the thing - Benchmark.executeWithBenchmarking(currentPR, - Benchmark.createBenchmarkId(Benchmark.PR_PREFIX + currentPR.getName(), - getBenchmarkId()), this, benchmarkFeatures); + long startTime = System.currentTimeMillis(); + // run the thing + Benchmark.executeWithBenchmarking(currentPR, + Benchmark.createBenchmarkId(Benchmark.PR_PREFIX + currentPR.getName(), + getBenchmarkId()), this, benchmarkFeatures); - benchmarkFeatures.remove(Benchmark.PR_NAME_FEATURE); + benchmarkFeatures.remove(Benchmark.PR_NAME_FEATURE); - // calculate the time taken by the PR - long timeTakenByThePR = System.currentTimeMillis() - startTime; - Long time = prTimeMap.get(currentPR.getName()); - if(time == null) { - time = new Long(0); + // calculate the time taken by the PR + long timeTakenByThePR = System.currentTimeMillis() - startTime; + Long time = prTimeMap.get(currentPR.getName()); + if(time == null) { + time = new Long(0); + } + time = new Long(time.longValue() + timeTakenByThePR); + prTimeMap.put(currentPR.getName(), time); + } finally { + // remove the listeners + try { + AbstractResource.removeResourceListeners(currentPR, listeners); + } + catch(Exception e) { + // the listeners removing failed; nothing important + log.error("Could not clear listeners for " + + currentPR.getClass().getName() + "\n" + e.toString() + + "\n...nothing to lose any sleep over."); + } } - time = new Long(time.longValue() + timeTakenByThePR); - prTimeMap.put(currentPR.getName(), time); - - - // remove the listeners - try { - AbstractResource.removeResourceListeners(currentPR, listeners); - } - catch(Exception e) { - // the listeners removing failed; nothing important - log.error("Could not clear listeners for " - + currentPR.getClass().getName() + "\n" + e.toString() - + "\n...nothing to lose any sleep over."); - } }// protected void runComponent(int componentIndex) /** Modified: gate/trunk/src/main/gate/gui/NameBearerHandle.java =================================================================== --- gate/trunk/src/main/gate/gui/NameBearerHandle.java 2018-05-16 12:45:42 UTC (rev 20289) +++ gate/trunk/src/main/gate/gui/NameBearerHandle.java 2018-06-18 15:28:58 UTC (rev 20290) @@ -1154,16 +1154,18 @@ catch(Exception e) { e.printStackTrace(Err.getPrintWriter()); } - // show the progress indicator - fireProgressChanged(0); - // the actual reinitialisation - res.reInit(); try { - AbstractResource.removeResourceListeners(res, listeners); + // show the progress indicator + fireProgressChanged(0); + // the actual reinitialisation + res.reInit(); + } finally { + try { + AbstractResource.removeResourceListeners(res, listeners); + } catch(Exception e) { + e.printStackTrace(Err.getPrintWriter()); + } } - catch(Exception e) { - e.printStackTrace(Err.getPrintWriter()); - } long endTime = System.currentTimeMillis(); fireStatusChanged(target.getName() + " reinitialised in " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ GATE-cvs mailing list GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs