1 | package de.uka.ipd.sdq.simulation.abstractsimengine; |
2 | |
3 | /** |
4 | * @author Steffen Becker (this code has been factored out from SimuCom) |
5 | * @author Philipp Merkle |
6 | * |
7 | * @param <M> |
8 | * the type of the simulation model |
9 | * @param <E> |
10 | * the type of the entity which is modified by this event |
11 | * @see ISimEvent |
12 | */ |
13 | public abstract class AbstractSimEventDelegator<E extends IEntity> extends SimulationElement |
14 | implements ISimEvent<E> { |
15 | |
16 | /** |
17 | * the delegate has the simulation-library-specific knowledge of how this event can be scheduled |
18 | * or removed from the event list. The delegate, however, is not aware of the simulation logic |
19 | * associated with this event, which is why it invokes the <code>eventRoutine</code> method |
20 | * whenever the event is to be executed. |
21 | */ |
22 | private ISimEvent<E> delegate; |
23 | |
24 | protected AbstractSimEventDelegator(ISimulationModel model, String name) { |
25 | super(model, name); |
26 | delegate = model.getSimEngineFactory().createSimEvent(this, name); |
27 | } |
28 | |
29 | /** |
30 | * Executes the simulation logic associated with this event. |
31 | * <p> |
32 | * Notice, that this method is not intended to be called by clients. Instead, the event |
33 | * scheduler of the respective simulation library invokes this method as soon as the simulation |
34 | * is reached at which the event has been scheduled. |
35 | * |
36 | * @param who |
37 | * the entity associated with this event |
38 | */ |
39 | public abstract void eventRoutine(E who); |
40 | |
41 | /** |
42 | * {@inheritDoc} |
43 | */ |
44 | public void schedule(E entity, double delay) { |
45 | // delegate the method call |
46 | delegate.schedule(entity, delay); |
47 | } |
48 | |
49 | /** |
50 | * {@inheritDoc} |
51 | */ |
52 | public void removeEvent() { |
53 | // delegate the method call |
54 | delegate.removeEvent(); |
55 | } |
56 | |
57 | /** |
58 | * {@inheritDoc} |
59 | */ |
60 | public double scheduledAtTime() { |
61 | return delegate.scheduledAtTime(); |
62 | } |
63 | |
64 | } |