| 1 | package de.uka.ipd.sdq.codegen.simucontroller.dockmodel; |
| 2 | |
| 3 | import java.io.Serializable; |
| 4 | import java.util.Observable; |
| 5 | |
| 6 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockBusyEvent; |
| 7 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockIdleEvent; |
| 8 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockPerformedDebugStepEvent; |
| 9 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockResumedEvent; |
| 10 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSimTimeChangedEvent; |
| 11 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSimulationStartedEvent; |
| 12 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSimulationTerminatedEvent; |
| 13 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockStartedDebugStepEvent; |
| 14 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSuspendedEvent; |
| 15 | import de.uka.ipd.sdq.simucomframework.simulationdock.SimulationDockService; |
| 16 | |
| 17 | /** |
| 18 | * This class represents a single Simulation Dock's status. It fires events if the status of the dock changes. |
| 19 | * @author Steffen |
| 20 | * |
| 21 | */ |
| 22 | public class DockModel extends Observable implements Serializable |
| 23 | { |
| 24 | /** |
| 25 | * |
| 26 | */ |
| 27 | private static final long serialVersionUID = -2378222579642029801L; |
| 28 | private int percentDone = 0; |
| 29 | private double simTime = 0; |
| 30 | private long measurementCount = 0; |
| 31 | private boolean idle = true; |
| 32 | private String id = null; |
| 33 | private String remoteMaschineURI; |
| 34 | private boolean isStepping = false; |
| 35 | private boolean isSuspended = false; |
| 36 | |
| 37 | private transient SimulationDockService service; |
| 38 | private boolean isStarted; |
| 39 | |
| 40 | public DockModel(SimulationDockService service) { |
| 41 | this(service,null); |
| 42 | } |
| 43 | |
| 44 | public DockModel(SimulationDockService service, String remoteMaschineURI) { |
| 45 | this.service = service; |
| 46 | this.id = service.getDockId(); |
| 47 | this.remoteMaschineURI = remoteMaschineURI; |
| 48 | } |
| 49 | |
| 50 | public int getPercentDone() { |
| 51 | return percentDone; |
| 52 | } |
| 53 | public double getSimTime() { |
| 54 | return simTime; |
| 55 | } |
| 56 | public long getMeasurementCount() { |
| 57 | return measurementCount; |
| 58 | } |
| 59 | public boolean isIdle() { |
| 60 | return idle; |
| 61 | } |
| 62 | |
| 63 | public void setPercentDone(int percentDone) { |
| 64 | if (!this.isIdle() && this.percentDone != percentDone) { |
| 65 | this.percentDone = percentDone; |
| 66 | setChanged(); |
| 67 | notifyObservers(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | public void setSimTime(double simTime) { |
| 72 | if (!this.isIdle() && this.simTime != simTime) { |
| 73 | this.simTime = simTime; |
| 74 | setChanged(); |
| 75 | notifyObservers(new DockSimTimeChangedEvent(this,simTime)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public void setMeasurementCount(long measurementCount) { |
| 80 | if (!this.isIdle()) { |
| 81 | this.measurementCount = measurementCount; |
| 82 | setChanged(); |
| 83 | notifyObservers(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | public void setIdle(boolean idle) { |
| 88 | if (this.idle != idle) { |
| 89 | this.idle = idle; |
| 90 | this.measurementCount = 0; |
| 91 | this.simTime = 0; |
| 92 | this.percentDone = 0; |
| 93 | setChanged(); |
| 94 | if (idle) |
| 95 | notifyObservers(new DockIdleEvent(this)); |
| 96 | else |
| 97 | notifyObservers(new DockBusyEvent(this)); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | public String getID() { |
| 102 | return id; |
| 103 | } |
| 104 | |
| 105 | public SimulationDockService getService() { |
| 106 | return service; |
| 107 | } |
| 108 | |
| 109 | public boolean isRemote() { |
| 110 | return remoteMaschineURI != null; |
| 111 | } |
| 112 | |
| 113 | public String getRemoteMaschineURI() { |
| 114 | return remoteMaschineURI; |
| 115 | } |
| 116 | |
| 117 | public boolean isStepping() { |
| 118 | return isStepping; |
| 119 | } |
| 120 | |
| 121 | public void setIsStepping(boolean isStepping) { |
| 122 | if (this.isStepping != isStepping) { |
| 123 | this.isStepping = isStepping; |
| 124 | setChanged(); |
| 125 | if (isStepping) |
| 126 | notifyObservers(new DockStartedDebugStepEvent(this)); |
| 127 | else |
| 128 | notifyObservers(new DockPerformedDebugStepEvent(this)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | public boolean isSuspended() { |
| 133 | return isSuspended; |
| 134 | } |
| 135 | |
| 136 | public void setIsSuspended(boolean isSuspended) { |
| 137 | if (this.isSuspended != isSuspended) { |
| 138 | this.isSuspended = isSuspended; |
| 139 | setChanged(); |
| 140 | if (isSuspended) |
| 141 | notifyObservers(new DockSuspendedEvent(this)); |
| 142 | else |
| 143 | notifyObservers(new DockResumedEvent(this)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public void setStarted(boolean started) { |
| 148 | if (this.isStarted != started) { |
| 149 | this.isStarted = started; |
| 150 | setChanged(); |
| 151 | if (isStarted) |
| 152 | notifyObservers(new DockSimulationStartedEvent(this)); |
| 153 | else |
| 154 | notifyObservers(new DockSimulationTerminatedEvent(this)); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | } |