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.messaging.Message;
17 import nl.tudelft.simulation.messaging.devices.types.DeviceType;
18 import nl.tudelft.simulation.messaging.queues.MessageQueueInterface;
19
20 /***
21 * Standard implementation of a receiving device. <br>
22 * <br>
23 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
24 * Delft, the Netherlands. All rights reserved.
25 *
26 * See for project information <a href="http://www.simulation.tudelft.nl/">
27 * www.simulation.tudelft.nl </a>.
28 *
29 * The source code and binary code of this software is proprietary information
30 * of Delft University of Technology.
31 *
32 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33 * Jacobs </a>, <a
34 * href="mailto:s.p.a.vanhouten@tbm.tudelft.nl">Stijn-Pieter van Houten
35 * </a>, <a
36 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
37 * Verbraeck </a>
38 * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 11:29:12 $$
39 */
40 public class ReceivingDevice extends Device implements ReceivingDeviceInterface
41 {
42 /*** the serial version uid */
43 private static final long serialVersionUID = 12L;
44
45 /*** The queue to store the messages in */
46 protected MessageQueueInterface queue = null;
47
48 /***
49 * constructs a new receiving device, override the default transmission
50 * delay and frequency from the DeviceType.
51 *
52 * @param name the name or description of the device
53 * @param deviceType the type of device
54 * @param queue the type of queue to store the messages in
55 */
56 public ReceivingDevice(final String name, final DeviceType deviceType,
57 final MessageQueueInterface queue)
58 {
59 super(name, deviceType);
60 this.queue = queue;
61 }
62
63 /***
64 * constructs a new receiving device, override the default transmission
65 * delay and frequency from the DeviceType.
66 *
67 * @param name the name or description of the device
68 * @param deviceType the type of device
69 * @param transmissionDelay the default logarithmic transmission delay of
70 * the device.
71 * @param transmissionFrequency the maximum transmission frequency of the
72 * device.
73 * @param queue the type of queue to store the messages in
74 */
75 public ReceivingDevice(final String name, final DeviceType deviceType,
76 final int transmissionDelay, final double transmissionFrequency,
77 final MessageQueueInterface queue)
78 {
79 super(name, deviceType, transmissionDelay, transmissionFrequency);
80 this.queue = queue;
81 }
82
83 /***
84 * @param message the object or message to receive
85 * @return an acknowledgement object to indicate success, <B>null </B> is
86 * success, an Exception object indicates no success...
87 */
88 public Object receive(final Message message)
89 {
90 if (!super.getState().isWorking())
91 {
92 return new Exception("Device not working, state is "
93 + super.getState().getDescription());
94 }
95 this.queue.add(message);
96 super.fireEvent(ReceivingDeviceInterface.RECEIVED_NEW_MESSAGE_EVENT,
97 null);
98 return null;
99 }
100
101 /***
102 * @see nl.tudelft.simulation.messaging.devices.components.ReceivingDeviceInterface#getQueue()
103 */
104 public MessageQueueInterface getQueue()
105 {
106 return this.queue;
107 }
108 }