Advanced Modelling Features

WaitQueue

The Process Cooperation Class

   
 

When using a wait queue to synchronise processes, a model designer has to specifiy the common task the two processes are wanting to perform. DESMO-J expects the model designer to derive a subclass from desmoj.core.advancedModellingFeatures.ProcessCoop<Ship,Train> class and implement the abstract method cooperate(Ship master, Train slave).

package examples.waitQueue;

import desmoj.core.simulator.*;
import desmoj.core.advancedModellingFeatures.ProcessCoop;
import co.paralleluniverse.fibers.SuspendExecution;

/** The process cooperation between train and ship: transfers coal from
 *  train onto ship.
 */
public class CoalTransfer extends ProcessCoop<Ship,Train> {

   /** standard constructor */
   public CoalTransfer(WaitQueueExample model) {
	super(model, "coal transfer", true);
   }

   /** performs the cooperation between master (ship) and slave (train); i.e.
    *  unloads the train and loads the ship.
    */
   protected void cooperation(Ship master, Train slave) throws SuspendExecution {
	// just hold for the length of time it takes to transfer the coal
	hold(new TimeSpan(((WaitQueueExample)getModel()).unload.sample(), TimeUnit.MINUTES));
   }

}

The cooperate() method defines the common task the master process (in this model: a ship) and the slave process (a train) are performing. In this case, it's unloading the train and loading its coal onto the ship, which is modelled as a simple hold() of the active master process.

Note that the ProcessCoop class defines shortcuts to all relevant methods of the master process, like hold() or activate(); i.e. calling hold() in the above cooperate() method results in calling hold() on the currently active process which is the master.

After cooperation is finished, the wait queue automatically schedules the slave process (train) for re-activation directly after the master (ship), before control passes to the master again.



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