Advanced Modelling Features

CondQueue

The Ship Process

   
 

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

/**
 * Describes this ship's life cycle:
 *
 * On arrival, the ship signals the waiting trucks that it is there now.
 * Then it directly leaves the system again since (un)loading is not
 * modelled.
 */
public void lifeCycle() throws SuspendExecution {

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

   // arrive at the harbour
   model.incomingShips.remove(this);
   model.currentShipInPort = this;
   // send trace note just for information
   sendTraceNote(" arrives at the port");

   // inform waiting trucks about arrival
   model.waitingTrucks.signal();

   // leave the system
   sendTraceNote(" leaves the port");
}

As you can see, the ship's life cycle is very simple. After arriving at the harbour (which means removing itself from the list of incoming ships and setting itself as the currently docked ship), the ship signals its arrival to the waitingTrucks condition queue with the use of the signal() method. This results in the condition queue to test all waiting processes (trucks) if their condition is met, freeing those trucks which are assigned to the current ship.

The ship just leaves the system after that, sending another trace note.



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