create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / simulation / listeners / system / InterruptListener.java
1 package net.sf.openrocket.simulation.listeners.system;
2
3 import net.sf.openrocket.simulation.SimulationStatus;
4 import net.sf.openrocket.simulation.exception.SimulationCancelledException;
5 import net.sf.openrocket.simulation.exception.SimulationException;
6 import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
7
8
9 /**
10  * A simulation listener that throws a {@link SimulationCancelledException} if
11  * this thread has been interrupted.  The conditions is checked every time a step
12  * is taken.
13  * 
14  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15  */
16 public class InterruptListener extends AbstractSimulationListener {
17         
18         public static final InterruptListener INSTANCE = new InterruptListener();
19         
20         @Override
21         public void postStep(SimulationStatus status) throws SimulationException {
22                 if (Thread.interrupted()) {
23                         throw new SimulationCancelledException("The simulation was interrupted.");
24                 }
25         }
26         
27         @Override
28         public boolean isSystemListener() {
29                 return true;
30         }
31 }