package nl.tudelft.simulation.examples.dsol.timesharedcomputer;
import nl.tudelft.simulation.dsol.SimRuntimeException;
import nl.tudelft.simulation.dsol.formalisms.flow.Station;
import nl.tudelft.simulation.dsol.formalisms.flow.StationInterface;
import nl.tudelft.simulation.dsol.simtime.SimTimeDouble;
import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
import nl.tudelft.simulation.event.EventType;
import nl.tudelft.simulation.jstats.distributions.DistContinuous;
/**
* The Terminal as published in Simulation Modeling and Analysis by A.M. Law & W.D. Kelton section 1.4 and 2.4.
* Copyright (c) 2003-2018 Delft University of Technology , the
* Netherlands.
* See for project information www.simulation.tudelft.nl
* License of use: General Public License (GPL) , no warranty
* @version 1.1 02.04.2003
* @author Peter Jacobs
*/
public class Terminal extends Station
{
/** */
private static final long serialVersionUID = 1L;
/** SERVICE_TIME is fired on job completion. */
public static final EventType SERVICE_TIME = new EventType("SERVICE_TIME");
/** the thinkDelay. */
private DistContinuous thinkDelay = null;
/** the jobSize. */
private DistContinuous jobSize = null;
/**
* constructs a new Terminal.
* @param simulator the simulator
* @param cpu the destination
* @param thinkDelay the delay
* @param jobSize in time
*/
public Terminal(final DEVSSimulatorInterface.TimeDouble simulator, final StationInterface cpu,
final DistContinuous thinkDelay, final DistContinuous jobSize)
{
super(simulator);
this.thinkDelay = thinkDelay;
this.jobSize = jobSize;
this.setDestination(cpu);
this.releaseObject(null);
}
/** {@inheritDoc} */
@Override
public void receiveObject(final Object object)
{
this.fireTimedEvent(SERVICE_TIME, this.simulator.getSimulatorTime() - ((Job) object).getCreationTime(),
this.simulator.getSimulatorTime());
try
{
Object[] args = {object};
this.simulator.scheduleEventAbs(this.simulator.getSimulatorTime() + this.thinkDelay.draw(), this,
this, "releaseObject", args);
}
catch (SimRuntimeException exception)
{
exception.printStackTrace();
}
}
/** {@inheritDoc} */
@Override
public synchronized void releaseObject(final Object object)
{
Job job = new Job(this.jobSize, this, this.simulator.getSimulatorTime());
this.fireEvent(StationInterface.RELEASE_EVENT, 1);
super.destination.receiveObject(job);
}
}