View Javadoc

1   /*
2    * @(#)Message.java Feb 17, 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;
15  
16  import java.io.Serializable;
17  
18  import nl.tudelft.simulation.actor.ActorInterface;
19  
20  /***
21   * A message, which can be sent from a sender to a receiver with some content.
22   * The Message is actually the 'envelope' around the content of the message.
23   * Messages are exchanged between devices. The Serializable content that is part
24   * of the message, needs to be handled by separate, domain specific, content
25   * handlers. <br>
26   * <br>
27   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
28   * Delft, the Netherlands. All rights reserved.
29   * 
30   * See for project information <a href="http://www.simulation.tudelft.nl/">
31   * www.simulation.tudelft.nl </a>.
32   * 
33   * The source code and binary code of this software is proprietary information
34   * of Delft University of Technology.
35   * 
36   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
37   *         Jacobs </a>, <a
38   *         href="mailto:s.p.a.vanhouten@tbm.tudelft.nl">Stijn-Pieter van Houten
39   *         </a>, <a
40   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
41   *         Verbraeck </a>
42   * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 11:29:13 $$
43   */
44  public class Message implements Serializable, Cloneable
45  {
46  	/*** the serial version uid */
47  	private static final long serialVersionUID = 12L;
48  
49  	/*** sender of the message */
50  	private ActorInterface sender = null;
51  
52  	/*** the receiver of a message */
53  	private ActorInterface receiver = null;
54  
55  	/*** the timestamp of a message */
56  	private double timestamp = Double.NaN;
57  
58  	/*** the priority of a message */
59  	private int priority = -1;
60  
61  	/*** the body of a message */
62  	private Serializable body = null;
63  
64  	/*** the id */
65  	private long id = -1;
66  
67  	/***
68  	 * constructs a new message
69  	 * 
70  	 * @param sender the sender
71  	 * @param receiver the receiver
72  	 * @param timestamp the timestamp
73  	 * @param priority the priority
74  	 * @param body the body
75  	 * @param id the id
76  	 */
77  	public Message(final ActorInterface sender, final ActorInterface receiver,
78  			final double timestamp, final int priority,
79  			final Serializable body, final long id)
80  	{
81  		this(sender, receiver, body);
82  		this.timestamp = timestamp;
83  		this.priority = priority;
84  		this.id = id;
85  	}
86  
87  	/***
88  	 * constructs a new Message
89  	 * 
90  	 * @param sender the sender
91  	 * @param receiver the receiver
92  	 * @param body the body
93  	 */
94  	public Message(final ActorInterface sender, final ActorInterface receiver,
95  			final Serializable body)
96  	{
97  		super();
98  		this.sender = sender;
99  		this.receiver = receiver;
100 		this.body = body;
101 	}
102 
103 	/***
104 	 * @return the sender of the message
105 	 */
106 	public ActorInterface getSender()
107 	{
108 		return this.sender;
109 	}
110 
111 	/***
112 	 * @return the receiver or the group of receivers of the message
113 	 */
114 	public ActorInterface getReceiver()
115 	{
116 		return this.receiver;
117 	}
118 
119 	/***
120 	 * @return the timestamp of the message
121 	 */
122 	public double getTimestamp()
123 	{
124 		return this.timestamp;
125 	}
126 
127 	/***
128 	 * @return the message priority
129 	 */
130 	public int getPriority()
131 	{
132 		return this.priority;
133 	}
134 
135 	/***
136 	 * @return the body of the message
137 	 */
138 	public Serializable getBody()
139 	{
140 		return this.body;
141 	}
142 
143 	/***
144 	 * @return Returns the id.
145 	 */
146 	public long getId()
147 	{
148 		return this.id;
149 	}
150 
151 	/***
152 	 * sets the id of a message
153 	 * 
154 	 * @param id The id to set.
155 	 */
156 	public void setId(final long id)
157 	{
158 		this.id = id;
159 	}
160 
161 	/***
162 	 * sets the body of a message
163 	 * 
164 	 * @param body The body to set.
165 	 */
166 	public void setBody(final Serializable body)
167 	{
168 		this.body = body;
169 	}
170 
171 	/***
172 	 * sets the priority of the message
173 	 * 
174 	 * @param priority The priority to set.
175 	 */
176 	public void setPriority(final int priority)
177 	{
178 		this.priority = priority;
179 	}
180 
181 	/***
182 	 * sets the receiver of the message
183 	 * 
184 	 * @param receiver The receiver to set.
185 	 */
186 	public void setReceiver(final ActorInterface receiver)
187 	{
188 		this.receiver = receiver;
189 	}
190 
191 	/***
192 	 * sets the timestamp
193 	 * 
194 	 * @param timestamp The timestamp to set.
195 	 */
196 	public void setTimestamp(final double timestamp)
197 	{
198 		this.timestamp = timestamp;
199 	}
200 }