Revision 809fcc17
Added by Andreas Müller almost 3 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/description/DescriptionAggregationBase.java | ||
---|---|---|
92 | 92 |
//TODO FIXME use UpdateResult |
93 | 93 |
|
94 | 94 |
double start = System.currentTimeMillis(); |
95 |
IProgressMonitor monitor = getConfig().getMonitor(); |
|
95 | 96 |
|
96 | 97 |
// only for debugging: |
97 | 98 |
//logger.setLevel(Level.TRACE); // TRACE will slow down a lot since it forces loading all term representations |
... | ... | |
102 | 103 |
filter.setOrder(ORDER.TREEINDEX_DESC); //DESC guarantees that child taxa are aggregated before parent |
103 | 104 |
filter.setIncludeRootNodes(false); //root nodes do not make sense for aggregation |
104 | 105 |
|
106 |
monitor.beginTask("Accumulating " + pluralDataType(), 100); |
|
105 | 107 |
Long countTaxonNodes = getTaxonNodeService().count(filter); |
106 | 108 |
int aggregationWorkTicks = countTaxonNodes.intValue(); |
107 | 109 |
logger.info(aggregationWorkTicks + " taxa to aggregate"); |
108 | 110 |
int getIdListTicks = 1; |
109 | 111 |
int preAccumulateTicks = 1; |
110 |
beginTask("Accumulating " + pluralDataType(), (aggregationWorkTicks) + getIdListTicks + preAccumulateTicks); |
|
112 |
monitor.worked(5); |
|
113 |
SubProgressMonitor subMonitor = SubProgressMonitor.NewStarted(monitor, |
|
114 |
95, "Accumulating " + pluralDataType(), aggregationWorkTicks + getIdListTicks + preAccumulateTicks); |
|
111 | 115 |
|
112 |
subTask("Get taxon node ID list"); |
|
116 |
subMonitor.subTask("Get taxon node ID list");
|
|
113 | 117 |
List<Integer> taxonNodeIdList = getTaxonNodeService().idList(filter); |
114 | 118 |
|
115 |
worked(getIdListTicks); |
|
119 |
subMonitor.worked(getIdListTicks);
|
|
116 | 120 |
|
117 | 121 |
try { |
118 |
preAggregate(); |
|
122 |
preAggregate(subMonitor);
|
|
119 | 123 |
} catch (Exception e) { |
120 | 124 |
result.addException(new RuntimeException("Unhandled error during pre-aggregation", e)); |
121 | 125 |
result.setError(); |
... | ... | |
123 | 127 |
return result; |
124 | 128 |
} |
125 | 129 |
|
126 |
workedAndNewTask(preAccumulateTicks, "Accumulating "+pluralDataType()+" per taxon for taxon filter " + filter.toString()); |
|
130 |
subMonitor.worked(preAccumulateTicks); |
|
131 |
subMonitor.subTask("Accumulating "+pluralDataType()+" per taxon for taxon filter " + filter.toString()); |
|
127 | 132 |
|
128 | 133 |
double startAccumulate = System.currentTimeMillis(); |
129 | 134 |
|
130 | 135 |
//TODO AM move to invokeOnSingleTaxon() |
131 |
IProgressMonitor subMonitor = new SubProgressMonitor(getMonitor(), aggregationWorkTicks);
|
|
136 |
IProgressMonitor aggregateMonitor = new SubProgressMonitor(subMonitor, aggregationWorkTicks);
|
|
132 | 137 |
try { |
133 |
aggregate(taxonNodeIdList, subMonitor);
|
|
138 |
aggregate(taxonNodeIdList, aggregateMonitor);
|
|
134 | 139 |
} catch (Exception e) { |
135 | 140 |
result.addException(new RuntimeException("Unhandled error during aggregation", e)); |
136 | 141 |
result.setError(); |
... | ... | |
311 | 316 |
|
312 | 317 |
protected abstract List<String> descriptionInitStrategy(); |
313 | 318 |
|
314 |
protected abstract void preAggregate(); |
|
319 |
protected abstract void preAggregate(IProgressMonitor monitor);
|
|
315 | 320 |
|
316 | 321 |
/** |
317 | 322 |
* hook for initializing object when a new transaction starts |
... | ... | |
437 | 442 |
return result; |
438 | 443 |
} |
439 | 444 |
|
440 |
protected IProgressMonitor getMonitor() { |
|
441 |
return config.getMonitor(); |
|
442 |
} |
|
443 |
|
|
444 |
protected void beginTask(String name, int totalWork){ |
|
445 |
if (! (getMonitor() instanceof SubProgressMonitor)){ |
|
446 |
getMonitor().beginTask(name, totalWork); |
|
447 |
} |
|
448 |
} |
|
449 |
|
|
450 |
protected void worked(int work){ |
|
451 |
getMonitor().worked(work); |
|
452 |
} |
|
453 |
|
|
454 |
protected void workedAndNewTask(int work, String newTask){ |
|
455 |
getMonitor().worked(work); |
|
456 |
getMonitor().subTask(newTask); |
|
457 |
} |
|
458 |
|
|
459 |
protected void subTask(String name){ |
|
460 |
getMonitor().subTask(name); |
|
461 |
} |
|
462 |
|
|
463 | 445 |
protected void done(){ |
464 |
getMonitor().done(); |
|
446 |
getConfig().getMonitor().done();
|
|
465 | 447 |
} |
466 | 448 |
|
467 | 449 |
public void setBatchMinFreeHeap(long batchMinFreeHeap) { |
Also available in: Unified diff
ref #9622, ref #6359, #8871 adapt progress monitoring for description aggregation