Proper use of TransformationFeedback
Posted: Fri Sep 11, 2015 10:44 am
Hi,
As a novice Java programmer, I'm having trouble figuring out how to use TransformationFeedback properly within an AuthorOperation. I'm using AuthorEditorAccess.runTransformationScenarios() to execute a transformation on the current document. The transformation is not supposed to modify the document itself, and so far everything works. The problem occurs when I try to add more functionality which modifies the current document by deleting nodes as well as certain external resources on which the transformation depends. In order to make sure that the transformation succeeds, I need to prevent these other operations from executing prematurely. I've tried to set a flag using TransformationFeedback.transformationFinished(). However, I can't seem to avoid an infinite loop while checking the flag. My first attempt was a naive busy loop, but I have also tried synchronized blocks calling wait() from doOperation() and notify() from transformationFinished(), but neither works. As you can probably tell, my grasp on threading and concurrency issues is rather shaky. Any help will be much appreciated.
The outline of my code is basically as follows:
As a novice Java programmer, I'm having trouble figuring out how to use TransformationFeedback properly within an AuthorOperation. I'm using AuthorEditorAccess.runTransformationScenarios() to execute a transformation on the current document. The transformation is not supposed to modify the document itself, and so far everything works. The problem occurs when I try to add more functionality which modifies the current document by deleting nodes as well as certain external resources on which the transformation depends. In order to make sure that the transformation succeeds, I need to prevent these other operations from executing prematurely. I've tried to set a flag using TransformationFeedback.transformationFinished(). However, I can't seem to avoid an infinite loop while checking the flag. My first attempt was a naive busy loop, but I have also tried synchronized blocks calling wait() from doOperation() and notify() from transformationFinished(), but neither works. As you can probably tell, my grasp on threading and concurrency issues is rather shaky. Any help will be much appreciated.
The outline of my code is basically as follows:
Code: Select all
private volatile boolean transformationFinished;
public void doOperation() {
runTransformationScenarios();
while (!transformationFinished) continue;
modifyDocument();
}
private class Feedback extends TransformationFeedback {
public void transformationFinished() {
transformationFinished = true;
}
public void transformationStopped() {
transformationFinished = true;
}
}