View Javadoc

1   /*
2    * @(#) DelaySendingDevice.java Feb 27, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  
14  package nl.tudelft.simulation.messaging.devices.components;
15  
16  import nl.tudelft.simulation.dsol.formalisms.devs.SimEvent;
17  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
18  import nl.tudelft.simulation.jstats.distributions.DistContinuous;
19  import nl.tudelft.simulation.logger.Logger;
20  import nl.tudelft.simulation.messaging.Message;
21  import nl.tudelft.simulation.messaging.devices.types.DeviceType;
22  
23  /***
24   * The DelaySendingDevice device is a device that sends out a message, which
25   * will arrive after a certain delay. There is no resource behavior in the
26   * device. <br>
27   * <br>
28   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
29   * Delft, the Netherlands. All rights reserved.
30   * 
31   * See for project information <a href="http://www.simulation.tudelft.nl/">
32   * www.simulation.tudelft.nl </a>.
33   * 
34   * The source code and binary code of this software is proprietary information
35   * of Delft University of Technology.
36   * 
37   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
38   *         Jacobs </a>, <a
39   *         href="mailto:s.p.a.vanhouten@tbm.tudelft.nl">Stijn-Pieter van Houten
40   *         </a>, <a
41   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
42   *         Verbraeck </a>
43   * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 11:29:12 $$
44   */
45  public class DelaySendingDevice extends SendingDevice
46  {
47  	/*** the serial version uid */
48  	private static final long serialVersionUID = 12L;
49  
50  	/*** the simulator to schedule on */
51  	protected DEVSSimulatorInterface simulator = null;
52  
53  	/*** the delay of the sender */
54  	protected DistContinuous delay = null;
55  
56  	/***
57  	 * constructs a new DelaySendingDevice, take the transmission delay and
58  	 * frequency from the DeviceType.
59  	 * 
60  	 * @param name the name or description of the device
61  	 * @param deviceType the type of device
62  	 * @param simulator the simulator
63  	 * @param delay the delay
64  	 */
65  	public DelaySendingDevice(final String name, final DeviceType deviceType,
66  			final DEVSSimulatorInterface simulator, final DistContinuous delay)
67  	{
68  		super(name, deviceType);
69  		this.simulator = simulator;
70  		this.delay = delay;
71  	}
72  
73  	/***
74  	 * constructs a new DelaySendingDevice, override the default transmission
75  	 * delay and frequency from the DeviceType.
76  	 * 
77  	 * @param name the name or description of the device
78  	 * @param deviceType the type of device
79  	 * @param transmissionDelay the default logarithmic transmission delay of
80  	 *        the device.
81  	 * @param transmissionFrequency the maximum transmission frequency of the
82  	 *        device.
83  	 * @param simulator the simulator
84  	 * @param delay the delay
85  	 */
86  	public DelaySendingDevice(final String name, final DeviceType deviceType,
87  			final int transmissionDelay, final double transmissionFrequency,
88  			final DEVSSimulatorInterface simulator, final DistContinuous delay)
89  	{
90  		super(name, deviceType, transmissionDelay, transmissionFrequency);
91  		this.simulator = simulator;
92  		this.delay = delay;
93  	}
94  
95  	/***
96  	 * @see nl.tudelft.simulation.messaging.devices.components.SendingDevice
97  	 *      #send(nl.tudelft.simulation.messaging.Message)
98  	 */
99  	public Object send(final Message message)
100 	{
101 		ReceivingDeviceInterface receiver = message.getReceiver()
102 				.getReceivingDevices(this.getDeviceType())[0];
103 		try
104 		{
105 			this.simulator.scheduleEvent(new SimEvent(this.simulator
106 					.getSimulatorTime()
107 					+ this.delay.draw(), this, receiver, "receive",
108 					new Object[]{message}));
109 		} catch (Exception exception)
110 		{
111 			Logger.warning(this, "send", exception);
112 		}
113 		return Boolean.TRUE;
114 	}
115 }