View Javadoc

1   /*
2    * @(#) SendingReceivingDevice.java Feb 18, 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 java.rmi.RemoteException;
17  
18  import nl.tudelft.simulation.event.EventInterface;
19  import nl.tudelft.simulation.event.EventListenerInterface;
20  import nl.tudelft.simulation.logger.Logger;
21  import nl.tudelft.simulation.messaging.Message;
22  import nl.tudelft.simulation.messaging.queues.MessageQueueInterface;
23  
24  /***
25   * A SendingReceivingDevice combines the sending device and receiving device in
26   * one aggregated object. <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 abstract class SendingReceivingDevice extends Device implements
46  		SendingDeviceInterface, ReceivingDeviceInterface,
47  		EventListenerInterface
48  {
49  	/*** the serial version uid */
50  	private static final long serialVersionUID = 12L;
51  
52  	/*** the sender */
53  	private SendingDeviceInterface sender = null;
54  
55  	/*** the receiver */
56  	private ReceivingDeviceInterface receiver = null;
57  
58  	/***
59  	 * constructs a new SendingReceivingDevice
60  	 * 
61  	 * @param name the name of the device
62  	 * @param sender the sending part of this device
63  	 * @param receiver the receiving part of this device
64  	 */
65  	public SendingReceivingDevice(final String name,
66  			final ReceivingDeviceInterface receiver,
67  			final SendingDeviceInterface sender)
68  	{
69  		super(name, sender.getDeviceType());
70  		this.sender = sender;
71  		this.receiver = receiver;
72  		try
73  		{
74  			this.sender.addListener(this, DeviceInterface.STATE_CHANGE_EVENT);
75  			this.receiver.addListener(this, DeviceInterface.STATE_CHANGE_EVENT);
76  			this.receiver.addListener(this,
77  					ReceivingDeviceInterface.RECEIVED_NEW_MESSAGE_EVENT);
78  		} catch (RemoteException e)
79  		{
80  			Logger.warning(this, "<init>", e);
81  		}
82  	}
83  
84  	/***
85  	 * @see nl.tudelft.simulation.messaging.devices.components.SendingDeviceInterface#send(nl.tudelft.simulation.messaging.Message)
86  	 */
87  	public Object send(final Message message)
88  	{
89  		return this.sender.send(message);
90  	}
91  
92  	/***
93  	 * @see nl.tudelft.simulation.messaging.devices.components.ReceivingDeviceInterface#receive(nl.tudelft.simulation.messaging.Message)
94  	 */
95  	public Object receive(final Message message)
96  	{
97  		return this.receiver.receive(message);
98  	}
99  
100 	/***
101 	 * @see nl.tudelft.simulation.messaging.devices.components.ReceivingDeviceInterface#getQueue()
102 	 */
103 	public MessageQueueInterface getQueue()
104 	{
105 		return this.receiver.getQueue();
106 	}
107 
108 	/***
109 	 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
110 	 */
111 	public void notify(final EventInterface event)
112 	{
113 		this.fireEvent(event.getType(), event.getContent());
114 	}
115 }