| 1 | package de.uka.ipd.sdq.simucomframework.resources; |
| 2 | |
| 3 | import de.uka.ipd.sdq.simucomframework.model.SimuComModel; |
| 4 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEventDelegator; |
| 5 | |
| 6 | /** |
| 7 | * Represents a failure of an AbstractScheduledResource. |
| 8 | * |
| 9 | * After the occurrence of the failure event, the resource remains unavailable |
| 10 | * until the next repair event occurs. |
| 11 | * |
| 12 | * @author brosch |
| 13 | * |
| 14 | */ |
| 15 | public class ResourceFailedEvent extends AbstractSimEventDelegator<AbstractScheduledResource> { |
| 16 | |
| 17 | /** |
| 18 | * The resource that this event belongs to. |
| 19 | */ |
| 20 | private AbstractScheduledResource resource; |
| 21 | |
| 22 | /** |
| 23 | * The corresponding repair event. |
| 24 | */ |
| 25 | private ResourceRepairedEvent repairedEvent; |
| 26 | |
| 27 | /** |
| 28 | * The constructor. |
| 29 | * |
| 30 | * @param model |
| 31 | * the owner model |
| 32 | * @param name |
| 33 | * the name of the event |
| 34 | */ |
| 35 | public ResourceFailedEvent(final SimuComModel model, final String name) { |
| 36 | super(model, name); |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * (non-Javadoc) |
| 41 | * @see de.uka.ipd.sdq.simucomframework.abstractSimEngine.SimEvent#eventRoutine(de.uka.ipd.sdq.simucomframework.abstractSimEngine.IEntityDelegate) |
| 42 | */ |
| 43 | public void eventRoutine(AbstractScheduledResource who) { |
| 44 | resource.setAvailable(false); |
| 45 | if (this.getModel().getSimulationControl().isRunning()) { |
| 46 | repairedEvent.schedule(resource, resource.getRepairTime()); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Retrieves the resource corresponding to the event. |
| 52 | * |
| 53 | * @return the corresponding resource |
| 54 | */ |
| 55 | public AbstractScheduledResource getResource() { |
| 56 | return resource; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Sets the resource corresponding to the event. |
| 61 | * |
| 62 | * @param resource |
| 63 | * the resource to set |
| 64 | */ |
| 65 | public void setResource(final AbstractScheduledResource resource) { |
| 66 | this.resource = resource; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Retrieves the corresponding repair event. |
| 71 | * |
| 72 | * @return the repair event |
| 73 | */ |
| 74 | public ResourceRepairedEvent getRepairedEvent() { |
| 75 | return repairedEvent; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Sets the corresponding repair event. |
| 80 | * |
| 81 | * @param repairedEvent |
| 82 | * the repair event |
| 83 | */ |
| 84 | public void setRepairedEvent(final ResourceRepairedEvent repairedEvent) { |
| 85 | this.repairedEvent = repairedEvent; |
| 86 | } |
| 87 | } |