job creates commands, until app freeze, why? [message #534151] |
Tue, 18 May 2010 08:47  |
Eclipse User |
|
|
|
I implement a simple Petrieditor.
After everything have worked fine, I decided to animate a Token Game. For this case, i created a Button, which Handler start a Command - Impletation. This Command has a Job - Implementation which call .getCommandStack to add new Commands, so I can see the Animation on my Editor.
Problem: after a few tasks, or new Commands my application freeze. I think the Problem has something todo with DefaultOperationHistory. After debugging, ithink it freeze on this position: in DefaultOperationHistory
private void notifyListeners(final OperationHistoryEvent event) {
if (event.getOperation() instanceof IAdvancedUndoableOperation) {
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
import petrinets.impl.PetrinetImpl;
import petrinets.impl.PlaceImpl;
import petrinets.impl.TransitionImpl;
public class TokenGameCommand extends Command {
private IGraphicalEditPart part;
private boolean switching = true;
private TransitionImpl activeTransition;
private PetrinetImpl myPetrinetImpl;
public TokenGameCommand() {super("Run App");}
public boolean canExecute() { return true;}
public void redo() {redoModel();}
public void execute() { redo();}
public void undo() {undoModel();}
protected void undoModel() {
System.out.println("Here I am");
}
protected void redoModel() {
if (part != null) {
new Job("token game") {
public IStatus run(IProgressMonitor monitor) {
try {
monitor.beginTask("Animating", 100);
while (!monitor.isCanceled()) {
TransactionalEditingDomain domain = part.getEditingDomain();
int i = (int)(Math.random()*10);
part.getEditingDomain().getCommandStack().execute(
new RecordingCommand(domain, "Start TokenGame" +i){
public void doExecute() {
if (switching){
myPetrinetImpl = (PetrinetImpl) ((View) part.getModel()).getElement();
myPetrinetImpl.setAllTransitionNoActive();
activeTransition = myPetrinetImpl.getRandomActiveTransition();
activeTransition.setActive(true);
myPetrinetImpl.operateTransition(activeTransition);
System.out.println(activeTransition.getName());
System.out.println("Hallo1");
}
else{
activeTransition.setActive(false);
System.out.println("Hallo");
switching = true;
}
}
protected boolean prepare() {return true;}
});
Thread.sleep(1000);
}
monitor.done();
} catch (Exception e) {}
return new Status(IStatus.OK,
"tokengame",
"ended", null);
}
}.schedule();
}
}
public Command setCurrentPart(IGraphicalEditPart part) {
this.part = part;
return null;
}
}
|
|
|
|
Re: job creates commands, until app freeze, why? [message #535640 is a reply to message #534151] |
Tue, 25 May 2010 05:26   |
Eclipse User |
|
|
|
Hi AlexejS,
What exactly appears to be freezing - the entire of Eclipse, or the
animation? Have you tried starting your Eclipse instance through Debug
mode and halting execution when Eclipse appears to freeze, in order to
track down what it is doing?
Hope this helps
Jevon
AlexejS wrote:
> I implement a simple Petrieditor.
> After everything have worked fine, I decided to animate a Token Game.
> For this case, i created a Button, which Handler start a Command -
> Impletation. This Command has a Job - Implementation which call
> .getCommandStack to add new Commands, so I can see the Animation on my
> Editor.
> Problem: after a few tasks, or new Commands my application freeze. I
> think the Problem has something todo with DefaultOperationHistory. After
> debugging, ithink it freeze on this position: in DefaultOperationHistory
>
>
>
> private void notifyListeners(final OperationHistoryEvent event) {
> if (event.getOperation() instanceof IAdvancedUndoableOperation) {
>
>
>
>
>
>
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.core.runtime.IStatus;
> import org.eclipse.core.runtime.OperationCanceledException;
> import org.eclipse.core.runtime.Status;
> import org.eclipse.core.runtime.jobs.Job;
> import org.eclipse.emf.common.command.AbstractCommand;
> import org.eclipse.emf.transaction.RecordingCommand;
> import org.eclipse.emf.transaction.TransactionalEditingDomain;
> import org.eclipse.gef.commands.Command;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
> import org.eclipse.gmf.runtime.notation.View;
>
> import petrinets.impl.PetrinetImpl;
> import petrinets.impl.PlaceImpl;
> import petrinets.impl.TransitionImpl;
>
> public class TokenGameCommand extends Command {
>
> private IGraphicalEditPart part;
> private boolean switching = true;
> private TransitionImpl activeTransition;
> private PetrinetImpl myPetrinetImpl;
> public TokenGameCommand() {super("Run App");}
> public boolean canExecute() { return true;}
> public void redo() {redoModel();}
> public void execute() { redo();}
> public void undo() {undoModel();}
> protected void undoModel() {
> System.out.println("Here I am");
> }
> protected void redoModel() {
> if (part != null) {
> new Job("token game") {
> public IStatus run(IProgressMonitor monitor) {
> try {
> monitor.beginTask("Animating", 100);
> while (!monitor.isCanceled()) {
> TransactionalEditingDomain domain =
> part.getEditingDomain();
> int i = (int)(Math.random()*10);
> part.getEditingDomain().getCommandStack().execute(
> new RecordingCommand(domain, "Start TokenGame" +i){
> public void doExecute() {
> if (switching){
> myPetrinetImpl = (PetrinetImpl)
> ((View) part.getModel()).getElement();
>
> myPetrinetImpl.setAllTransitionNoActive();
> activeTransition =
> myPetrinetImpl.getRandomActiveTransition();
> activeTransition.setActive(true);
>
> myPetrinetImpl.operateTransition(activeTransition);
>
> System.out.println(activeTransition.getName());
> System.out.println("Hallo1");
> }
> else{
> activeTransition.setActive(false);
> System.out.println("Hallo");
> switching = true;
> }
> }
> protected boolean prepare() {return true;}
> });
> Thread.sleep(1000);
> }
> monitor.done();
> } catch (Exception e) {}
> return new Status(IStatus.OK,
> "tokengame",
> "ended", null);
> }
> }.schedule();
> }
> }
>
> public Command setCurrentPart(IGraphicalEditPart part) {
> this.part = part;
> return null;
> }
> }
>
>
|
|
|
Re: job creates commands, until app freeze, why? [message #535658 is a reply to message #534151] |
Tue, 25 May 2010 07:57  |
Eclipse User |
|
|
|
Two days ago I found out a work around for my case.
Instead of RecordingCommand, I used AbstractCommand with an emty undo() implemenatation, which i call after every AbstractCommand creation. So in fact the problem which appears by using RecordingCommand comes from the class DefaultOperationHistory, exactly from DEAFAULT_LIMIT = 20.
So in the past my animation did 20 steps and whole application freez.
The question now is: How to enlarge this Limit, or how to use RecordingCommand with more than 20 crations getEditingDomain().getCommandStack(). <- , or how to do a solution, that I can go 20 steps backwards, with RecordingCommand.
|
|
|
Powered by
FUDForum. Page generated in 0.03909 seconds