1 | package de.uka.ipd.sdq.simulation.abstractsimengine.desmoj; |
2 | |
3 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEntityDelegator; |
4 | import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEventDelegator; |
5 | import de.uka.ipd.sdq.simulation.abstractsimengine.IEntity; |
6 | import de.uka.ipd.sdq.simulation.abstractsimengine.ISimEvent; |
7 | import desmoj.core.simulator.Event; |
8 | import desmoj.core.simulator.TimeSpan; |
9 | |
10 | /** |
11 | * @author Steffen Becker |
12 | * @author Philipp Merkle |
13 | */ |
14 | public class DesmoJSimEvent<E extends IEntity> extends Event<DesmoJEntity> implements |
15 | ISimEvent<E> { |
16 | |
17 | private final AbstractSimEventDelegator<E> event; |
18 | |
19 | public DesmoJSimEvent(final AbstractSimEventDelegator<E> event, final DesmoJModel owner, final String name) { |
20 | super(owner, name, false); |
21 | this.event = event; |
22 | } |
23 | |
24 | /** |
25 | * The event handler, which is called by DESMO-J when an event occurred. |
26 | * <p> |
27 | * {@inheritDoc} |
28 | * |
29 | * @see Event#eventRoutine(desmoj.core.simulator.Entity) |
30 | */ |
31 | @SuppressWarnings("unchecked") |
32 | @Override |
33 | public void eventRoutine(final DesmoJEntity who) { |
34 | // delegate the event handling to the encapsulated event |
35 | this.event.eventRoutine((E) who.getEncapsulatedEntity()); |
36 | } |
37 | |
38 | @Override |
39 | public void schedule(final E entity, final double delay) { |
40 | final AbstractSimEntityDelegator simEntity = (AbstractSimEntityDelegator) entity; |
41 | final DesmoJEntity desmoJEntity = (DesmoJEntity) simEntity.getEncapsulatedEntity(); |
42 | this.schedule(desmoJEntity, new TimeSpan(delay)); |
43 | } |
44 | |
45 | @Override |
46 | public void removeEvent() { |
47 | if (this.isScheduled()) { |
48 | this.cancel(); |
49 | } |
50 | } |
51 | |
52 | @Override |
53 | public double scheduledAtTime() { |
54 | return this.scheduledAt().getTimeAsDouble(); |
55 | } |
56 | |
57 | } |