Advanced Modelling Features

WaitQueue

The Train Process

   
 

Trains are modelled as simulation processes. Since the actual unloading of a train is not part of our model, a ship doesn't have much to do. Let's have a look at the lifeCycle() of the Train class:

/**
 * Describes this train's life cycle:
 *
 * On arrival, the train requests to be unloaded, which may result
 * in the train having to wait for an empty ship. After transferring
 * its coal onto a ship a train leaves the harbour again.
 */
public void lifeCycle() throws SuspendExecution {

   // get a reference to the model
   WaitQueueExample model = (WaitQueueExample)getModel();

   // create and schedule successor
   new Train(model).activate(new TimeSpan(model.trainArrivals.sample(), TimeUnit.MINUTES));

   // arrive at the harbour:	
   // request to be unloaded --> may cause delay
   model.transferPoint.waitOnCoop();

   // leave the system
}

As you can see, the train's life cycle is very simple. After arriving at the harbour the train immediately requests unloading. As train processes are modelled as slaves, this means the train calls the waitOnCoop() method of the transferPoint wait queue to wait for a suitable master (ship process). If there are no ships available, the wait queue automatically enqueues the train and passivates it. Otherwise, the wait queue retrieves the first master process from its internal master queue and starts the cooperation of both, ship (master) and train (slave).

The train process will be automatically re-activated after unloading is finished. The train just leaves the system after that.

One statement in the train's life cycle might need some additional explanation. What's the deal with creating and scheduling a successor process? Well, it is just one of the options a model designer has to generate new objects. In other process-oriented models, we have usually implemented a separate generator process to let the temporary processes arrive in the system. Having each process generate its successor is just another possibility to do this.



   
  http://desmoj.sourceforge.net/tutorial/advanced/waitqueue3.html