Advanced Modelling Features

CondQueue

The Condition Class

   
 

When using a condition queue to synchronise processes, a model designer has to specifiy the condition a process is waiting for. DESMO-J expects the model designer to derive a subclass from its abstract desmoj.core.simulator.Condition<E extends Entity> class and implement the abstract method check(E e). In our case, a subclass of Condition<Truck> is created, where methode check(Truck t) compares the current ship in the harbour (stored in the model's currentShipInPort attribute) with the myShip attribute of the given truck process:

public class ShipArrivedCondition extends Condition<Truck> {

   /**
    * Constructs a new ShipArrivedCondition.
    * @param owner the model this condition belongs to
    * @param name this condition's name
    * @param showInTrace flag to indicate if this condition shall produce
    *                    output for the trace
    */
   public ShipArrivedCondition(desmoj.core.simulator.Model owner,
                               String name, boolean showInTrace) {
	super(owner, name, showInTrace);
   }

   /** test routine that will be call from the condition queue to check whether
    *  the condition is met for the given entity (truck).
    */
   public boolean check(Truck t) {
	// is the current ship in port the ship this truck is waiting for?
	return ((CondQueueExample)getModel()).currentShipInPort == t.myShip;
   }
}


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