| 1 | package de.uka.ipd.sdq.simulation.abstractsimengine; |
| 2 | |
| 3 | import java.util.concurrent.atomic.AtomicLong; |
| 4 | |
| 5 | /** |
| 6 | * @author Steffen Becker (this code has been factored out from SimuCom) |
| 7 | * @author Philipp Merkle |
| 8 | * |
| 9 | * @param <M> |
| 10 | * the type of the simulation model |
| 11 | * @see ISimProcess |
| 12 | */ |
| 13 | public abstract class AbstractSimProcessDelegator extends AbstractSimEntityDelegator implements |
| 14 | ISimProcess { |
| 15 | |
| 16 | private static AtomicLong processIdGenerator = new AtomicLong(0); |
| 17 | |
| 18 | /** |
| 19 | * the delegate has the simulation-library-specific knowledge of how this process can be |
| 20 | * suspended and resumed again. The delegate, however, is not aware of the lifecycle associated |
| 21 | * with this process, which is why it invokes the <code>lifecycle</code> method as soon as the |
| 22 | * process is to be executed. |
| 23 | */ |
| 24 | private ISimProcess delegate; |
| 25 | private long id; |
| 26 | |
| 27 | public AbstractSimProcessDelegator(ISimulationModel model, String name) { |
| 28 | super(model, name); |
| 29 | this.delegate = model.getSimEngineFactory().createSimProcess(this, name); |
| 30 | this.id = generateNextID(); |
| 31 | } |
| 32 | |
| 33 | // TODO This method should be rather named getId() but there is already such a method. Thus, |
| 34 | // getId() should be renamed to getTextualId() or similar. |
| 35 | public long getRawId() { |
| 36 | return id; |
| 37 | } |
| 38 | |
| 39 | public String getId() { |
| 40 | return getName() + "_" + id; |
| 41 | } |
| 42 | |
| 43 | private static long generateNextID() { |
| 44 | return processIdGenerator.incrementAndGet(); |
| 45 | } |
| 46 | |
| 47 | public abstract void lifeCycle(); |
| 48 | |
| 49 | /** |
| 50 | * {@inheritDoc} |
| 51 | */ |
| 52 | public boolean isTerminated() { |
| 53 | return delegate.isTerminated(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * {@inheritDoc} |
| 58 | */ |
| 59 | public void passivate() { |
| 60 | delegate.passivate(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * {@inheritDoc} |
| 65 | */ |
| 66 | public void scheduleAt(double d) { |
| 67 | delegate.scheduleAt(d); |
| 68 | } |
| 69 | |
| 70 | public void addProcessListener(ISimProcessListener l) { |
| 71 | delegate.addProcessListener(l); |
| 72 | } |
| 73 | |
| 74 | public void removeProcessListener(ISimProcessListener l) { |
| 75 | delegate.removeProcessListener(l); |
| 76 | } |
| 77 | |
| 78 | // public boolean isScheduled() { |
| 79 | // return delegate.isScheduled(); |
| 80 | // } |
| 81 | // |
| 82 | // public void reschedule(double d) { |
| 83 | // delegate.reschedule(d); |
| 84 | // } |
| 85 | |
| 86 | } |