View Javadoc

1   /*
2    * @(#)Release.java Feb 1, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.formalisms.flow;
11  
12  import java.rmi.RemoteException;
13  
14  import nl.tudelft.simulation.dsol.formalisms.Resource;
15  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
16  import nl.tudelft.simulation.logger.Logger;
17  
18  /***
19   * The release station releases a given quantity of a claimed resource. <br>
20   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
21   * University of Technology </a>, the Netherlands. <br>
22   * See for project information <a href="http://www.simulation.tudelft.nl">
23   * www.simulation.tudelft.nl </a> <br>
24   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
25   * License (GPL) </a>, no warranty <br>
26   * 
27   * @version 2.0 21.09.2003 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
29   *         Jacobs </a>, <a
30   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
31   *         Verbraeck </a>
32   */
33  public class Release extends Station
34  {
35  	/*** resource refers to the resource released */
36  	private Resource resource;
37  
38  	/*** amount defines the amount to be released */
39  	private double amount = 1.0;
40  
41  	/***
42  	 * Constructor for Release.
43  	 * 
44  	 * @param simulator on which is scheduled
45  	 * @param resource which is released
46  	 */
47  	public Release(final DEVSSimulatorInterface simulator,
48  			final Resource resource)
49  	{
50  		this(simulator, resource, 1.0);
51  	}
52  
53  	/***
54  	 * Constructor for Release.
55  	 * 
56  	 * @param simulator on which is scheduled
57  	 * @param resource which is released
58  	 * @param amount of resource which is released
59  	 */
60  	public Release(final DEVSSimulatorInterface simulator,
61  			final Resource resource, final double amount)
62  	{
63  		super(simulator);
64  		this.resource = resource;
65  		this.amount = amount;
66  	}
67  
68  	/***
69  	 * @see StationInterface#receiveObject(Object)
70  	 */
71  	public synchronized void receiveObject(final Object object)
72  			throws RemoteException
73  	{
74  		super.receiveObject(object);
75  		try
76  		{
77  			this.resource.releaseCapacity(this.amount);
78  			this.releaseObject(object);
79  		} catch (Exception exception)
80  		{
81  			Logger.warning(this, "receiveObject", exception);
82  		}
83  	}
84  }