mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[204964] Fixed CountingRequestMinotor bug.
This commit is contained in:
parent
3ba7032c29
commit
e4e9401c92
3 changed files with 47 additions and 31 deletions
|
@ -281,11 +281,7 @@ public abstract class AbstractExpressionLayoutNode<V extends IDMData> extends Ab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childRmCount > 0) {
|
countingRm.setDoneCount(childRmCount);
|
||||||
countingRm.setCount(childRmCount);
|
|
||||||
} else {
|
|
||||||
countingRm.done();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -179,12 +179,8 @@ public class ExpressionManagerLayoutNode extends AbstractVMLayoutNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no expressions were parsed, we're finished.
|
// Set the count to the counting RM.
|
||||||
if (expressionRmCount > 0) {
|
multiRm.setDoneCount(expressionRmCount);
|
||||||
multiRm.setCount(expressionRmCount);
|
|
||||||
} else {
|
|
||||||
multiRm.done();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(ILabelUpdate[] updates) {
|
public void update(ILabelUpdate[] updates) {
|
||||||
|
@ -323,11 +319,7 @@ public class ExpressionManagerLayoutNode extends AbstractVMLayoutNode
|
||||||
buildDeltaForExpressionCallCount++;
|
buildDeltaForExpressionCallCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildDeltaForExpressionCallCount != 0) {
|
multiRm.setDoneCount(buildDeltaForExpressionCallCount);
|
||||||
multiRm.setCount(buildDeltaForExpressionCallCount);
|
|
||||||
} else {
|
|
||||||
requestMonitor.done();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,46 +18,74 @@ import org.eclipse.dd.dsf.DsfPlugin;
|
||||||
/**
|
/**
|
||||||
* Utility class to collect multiple request monitor results of commands
|
* Utility class to collect multiple request monitor results of commands
|
||||||
* that are initiated simultaneously. The usage is as follows:
|
* that are initiated simultaneously. The usage is as follows:
|
||||||
* <pre>
|
* <code><pre>
|
||||||
* final MultiRequestMonitor multiRequestMon = new MultiRequestMonitor(fExecutor, null) {
|
* final CountingRequestMonitor countingRm = new CountingRequestMonitor(fExecutor, null) {
|
||||||
* public void handleCompleted() {
|
* public void handleCompleted() {
|
||||||
* System.out.println("All complete, errors=" + !getStatus().isOK());
|
* System.out.println("All complete, errors=" + !getStatus().isOK());
|
||||||
* }
|
* }
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* for (int i = 0; i < 10; i++) {
|
* int count = 0;
|
||||||
* service.call(i, multiRequestMon.addRequestMonitor(
|
* for (int i : elements) {
|
||||||
* new RequestMonitor(fExecutor, null) {
|
* service.call(i, countingRm);
|
||||||
* public void handleCompleted() {
|
* count++;
|
||||||
* System.out.println(Integer.toString(i) + " complete");
|
|
||||||
* multiRequestMon.requestMonitorDone(this);
|
|
||||||
* }
|
|
||||||
* }));
|
|
||||||
* }
|
* }
|
||||||
* </pre>
|
*
|
||||||
|
* countingRm.setDoneCount(count);
|
||||||
|
* </pre></code>
|
||||||
*/
|
*/
|
||||||
public class CountingRequestMonitor extends RequestMonitor {
|
public class CountingRequestMonitor extends RequestMonitor {
|
||||||
|
/**
|
||||||
|
* Counter tracking the remaining number of times that the done() method
|
||||||
|
* needs to be called before this request monitor is actually done.
|
||||||
|
*/
|
||||||
private int fDoneCounter;
|
private int fDoneCounter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag indicating whether the initial count has been set on this monitor.
|
||||||
|
*/
|
||||||
|
private boolean fInitialCountSet = false;
|
||||||
|
|
||||||
public CountingRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
public CountingRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
||||||
super(executor, parentRequestMonitor);
|
super(executor, parentRequestMonitor);
|
||||||
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCount(int count) {
|
/**
|
||||||
fDoneCounter = count;
|
* Sets the number of times that this request monitor needs to be called
|
||||||
|
* before this monitor is truly considered done. This method must be called
|
||||||
|
* exactly once in the life cycle of each counting request monitor.
|
||||||
|
* @param count Number of times that done() has to be called to mark the request
|
||||||
|
* monitor as complete. If count is '0', then the counting request monitor is
|
||||||
|
* marked as done immediately.
|
||||||
|
*/
|
||||||
|
public synchronized void setDoneCount(int count) {
|
||||||
|
assert !fInitialCountSet;
|
||||||
|
fInitialCountSet = true;
|
||||||
|
fDoneCounter += count;
|
||||||
|
if (fDoneCounter <= 0) {
|
||||||
|
assert fDoneCounter == 0; // Mismatch in the count.
|
||||||
|
super.done();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to indicate that one of the calls using this monitor is finished.
|
||||||
|
* Only when <code>done</done> is called the number of times corresponding to the
|
||||||
|
* count, the request monitor will be considered complete. This method can be
|
||||||
|
* called before {@link #setDoneCount(int)}.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void done() {
|
public synchronized void done() {
|
||||||
fDoneCounter--;
|
fDoneCounter--;
|
||||||
if (fDoneCounter <= 0) {
|
if (fInitialCountSet && fDoneCounter <= 0) {
|
||||||
|
assert fDoneCounter == 0; // Mismatch in the count.
|
||||||
super.done();
|
super.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Multi-RequestMonitor: " + getStatus().toString(); //$NON-NLS-1$
|
return "CountingRequestMonitor: " + getStatus().toString(); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue