1
2
3
4
5
6
7
8
9
10
11
12
13
14 package nl.tudelft.simulation.messaging.devices.components;
15
16 import nl.tudelft.simulation.event.EventType;
17 import nl.tudelft.simulation.messaging.Message;
18 import nl.tudelft.simulation.messaging.devices.types.DeviceType;
19 import nl.tudelft.simulation.messaging.queues.MessageQueueInterface;
20
21 /***
22 * Models a sending device with a queue of messages. The queue can be
23 * implemented as FiFo, LiFo, priority, or any other queuing mechanism that has
24 * been defined. The device just puts the messages in the queue; another
25 * mechanism (probably from the actor) needs to take out the messages from the
26 * queue. <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 QueuingSendingDevice extends SendingDevice
46 {
47 /*** the serial version uid */
48 private static final long serialVersionUID = 12L;
49
50 /*** The event to indicate there is a message ready to be sent */
51 public static final EventType NEW_MESSAGE_TO_SEND_EVENT = new EventType(
52 "NEW_MESSAGE_TO_SEND_EVENT");
53
54 /*** The queue to store the messages in */
55 protected MessageQueueInterface queue = null;
56
57 /***
58 * constructs a new sending device with a message queue, override the
59 * default transmission delay and frequency from the DeviceType.
60 *
61 * @param name the name or description of the device
62 * @param deviceType the type of device
63 * @param queue the type of queue to store the messages in
64 */
65 public QueuingSendingDevice(final String name, final DeviceType deviceType,
66 final MessageQueueInterface queue)
67 {
68 super(name, deviceType);
69 this.queue = queue;
70 }
71
72 /***
73 * constructs a new sending device with a message queue, override the
74 * default transmission delay and frequency from the DeviceType.
75 *
76 * @param name the name or description of the device
77 * @param deviceType the type of device
78 * @param transmissionDelay the default logarithmic transmission delay of
79 * the device.
80 * @param transmissionFrequency the maximum transmission frequency of the
81 * device.
82 * @param queue the type of queue to store the messages in
83 */
84 public QueuingSendingDevice(final String name, final DeviceType deviceType,
85 final int transmissionDelay, final double transmissionFrequency,
86 final MessageQueueInterface queue)
87 {
88 super(name, deviceType, transmissionDelay, transmissionFrequency);
89 this.queue = queue;
90 }
91
92 /***
93 * @see nl.tudelft.simulation.messaging.devices.components.SendingDeviceInterface#send(nl.tudelft.simulation.messaging.Message)
94 */
95 public Object send(final Message message)
96 {
97 if (!this.getState().isWorking())
98 {
99 return Boolean.FALSE;
100 }
101 this.queue.add(message);
102 this.fireEvent(QueuingSendingDevice.NEW_MESSAGE_TO_SEND_EVENT, null);
103 return Boolean.TRUE;
104 }
105 }