1 | package de.uka.ipd.sdq.simulation.abstractsimengine.ssj; |
2 | |
3 | import umontreal.iro.lecuyer.simevents.Event; |
4 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEntityDelegator; |
5 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEventDelegator; |
6 | import de.uka.ipd.sdq.simulation.abstractsimengine.IEntity; |
7 | import de.uka.ipd.sdq.simulation.abstractsimengine.ISimEvent; |
8 | |
9 | /** |
10 | * @author Steffen Becker |
11 | * @author Philipp Merkle |
12 | * |
13 | * @param <E> |
14 | * the type of the entity which is modified by this event |
15 | */ |
16 | public class SSJSimEvent<E extends IEntity> extends Event implements ISimEvent<E> { |
17 | |
18 | private AbstractSimEventDelegator<E> myAbstractEvent; |
19 | private E who; |
20 | |
21 | public SSJSimEvent(AbstractSimEventDelegator<E> myEvent, String name) { |
22 | super(((SSJExperiment) myEvent.getModel().getSimulationControl()).getSimulator()); |
23 | this.myAbstractEvent = myEvent; |
24 | } |
25 | |
26 | /** |
27 | * The event handler, which is called by SSJ when an event occurred. |
28 | * <p> |
29 | * {@inheritDoc} |
30 | * |
31 | * @see Event#actions() |
32 | */ |
33 | @SuppressWarnings("unchecked") |
34 | @Override |
35 | public void actions() { |
36 | // Check stop conditions when an event happens... |
37 | // TODO: is this really needed!? |
38 | ((SSJExperiment) myAbstractEvent.getModel().getSimulationControl()).checkStopConditions(); |
39 | |
40 | // TODO try to get rid of manual casts |
41 | AbstractSimEntityDelegator abstractEntity = (AbstractSimEntityDelegator) who; |
42 | SSJEntity ssjEntity = (SSJEntity) abstractEntity.getEncapsulatedEntity(); |
43 | ssjEntity.isScheduled = false; |
44 | ssjEntity.nextEventForThisEntity = null; |
45 | myAbstractEvent.eventRoutine((E) ssjEntity.getEncapsulatedEntity()); |
46 | } |
47 | |
48 | @SuppressWarnings("unchecked") |
49 | @Override |
50 | public void schedule(E resource, double delay) { |
51 | who = resource; |
52 | |
53 | // TODO try to get rid of manual casts |
54 | AbstractSimEntityDelegator abstractEntity = (AbstractSimEntityDelegator) who; |
55 | SSJEntity ssjEntity = (SSJEntity) abstractEntity.getEncapsulatedEntity(); |
56 | ssjEntity.isScheduled = true; |
57 | ssjEntity.nextEventForThisEntity = this; |
58 | this.schedule(delay); |
59 | } |
60 | |
61 | @Override |
62 | public void removeEvent() { |
63 | this.cancel(); |
64 | } |
65 | |
66 | @Override |
67 | public double scheduledAtTime() { |
68 | // TODO assure this.eventTime == this.time()! |
69 | return this.time(); |
70 | } |
71 | |
72 | } |