View Javadoc

1   /*
2    *  
3    *  Fosstrak LLRP Commander (www.fosstrak.org)
4    * 
5    *  Copyright (C) 2008 ETH Zurich
6    *
7    *  This program is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  This program is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with this program.  If not, see <http://www.gnu.org/licenses/> 
19   *
20   */
21  
22  package org.fosstrak.llrp.adaptor;
23  
24  import java.io.Serializable;
25  import java.rmi.Remote;
26  
27  /**
28   * Meta data that contains all information about the reader. this is for 
29   * example the reader name, the address, the port, etc. ...
30   * 
31   * @author sawielan
32   *
33   */
34  public class ReaderMetaData implements Remote, Serializable  {
35  	
36  	// serial version id.
37  	private static final long serialVersionUID = 6184673996217995724L;
38  
39  	// whether the reader is alive.
40  	private boolean alive;
41  
42  	// the number of sent packages in total.
43  	private int packagesSent;
44  	
45  	// the number of received packages in total.
46  	private int packagesReceived;
47  	
48  	// the number of sent packages in the current session.
49  	private int packagesCurrentSessionSent;
50  	
51  	// the number of received packages in the current session.
52  	private int packagesCurrentSessionReceived;
53  	
54  	// whether keep alive messages get logged or not.
55  	private boolean reportKeepAlive;
56  	
57  	// whether the connection is initiated by the reader or from the physical reader.
58  	private boolean clientInitiated;
59  	
60  	// flags whether the reader is connected or not.
61  	private boolean connected;
62  	
63  	// tells whether this reader connects directly after creation.
64  	private boolean connectImmediately = true;
65  	
66  	// the name of this logical reader.
67  	private String readerName = null;
68  		
69  	// the address of the physical reader.
70  	private String readerAddress = null;
71  
72  	// the port where to connect.
73  	private int port = -1;
74  	
75  	// how many times a keep-alive can be missed.
76  	private int allowNKeepAliveMisses;
77  	
78  	// the interval for the reader to send a keep-alive message. 
79  	private int keepAlivePeriod;
80  	
81  	/**
82  	 * default constructor.
83  	 */
84  	public ReaderMetaData() {
85  		
86  	}
87  	
88  	/**
89  	 * copy constructor that creates a complete copy of the meta data.
90  	 * @param other the meta data object to clone;
91  	 */
92  	public ReaderMetaData(ReaderMetaData other) {
93  		_setReaderName(other.getReaderName());
94  		_setReaderAddress(other.getReaderAddress());
95  		_setPort(other.getPort());
96  		
97  		_setAlive(other.isAlive());
98  		
99  		_setPackagesCurrentSessionReceived(other.getPackagesCurrentSessionReceived());
100 		_setPackagesCurrentSessionSent(other.getPackagesCurrentSessionSent());
101 		_setPackagesReceived(other.getPackagesReceived());
102 		_setPackagesSent(other.getPackagesSent());
103 		
104 		_setReportKeepAlive(other.isReportKeepAlive());
105 		
106 		_setClientInitiated(other.isClientInitiated());
107 		_setConnected(other.isConnected());
108 		_setConnectImmediately(other.isConnectImmediately());
109 		
110 		_setAllowNKeepAliveMisses(other.getAllowNKeepAliveMisses());
111 		_setKeepAlivePeriod(other.getKeepAlivePeriod());
112 	}
113 
114 	/**
115 	 * starts a new session.
116 	 */
117 	public void _newSession() {
118 		packagesCurrentSessionReceived = packagesCurrentSessionSent = 0;
119 	}
120 	
121 	/**
122 	 * increases the number of received packages by one.
123 	 */
124 	public void _packageReceived() {
125 		packagesReceived++;
126 		packagesCurrentSessionReceived++;
127 	}
128 	
129 	/**
130 	 * increases the number of sent packages by one.
131 	 */
132 	public void _packageSent() {
133 		packagesSent++;
134 		packagesCurrentSessionSent++;
135 	}
136 	
137 	private String prep(String label, String value) {
138 		return String.format("%s:\t%s\n", label, value);
139 	}
140 	
141 	private String prep(String label, boolean value) {
142 		return prep(label, String.format("%b", value));
143 	}
144 	
145 	private String prep(String label, int value) {
146 		return prep(label, String.format("%d", value));
147 	}
148 	
149 	public String toString() {
150 		StringBuffer sb = new StringBuffer();
151 		sb.append(prep("name", getReaderName()));
152 		sb.append(prep("address", getReaderAddress()));
153 		sb.append(prep("port", getPort()));
154 		
155 		sb.append(prep("alive", isAlive()));
156 		sb.append(prep("connected", isConnected()));
157 		sb.append(prep("report keepAlive", isReportKeepAlive()));
158 		sb.append(prep("client initiated", isClientInitiated()));
159 		sb.append(prep("connect immediate", isConnectImmediately()));
160 		
161 		sb.append(prep("nSent", getPackagesSent()));
162 		sb.append(prep("nRecv", getPackagesReceived()));
163 		sb.append(prep("currentSession nSent", getPackagesCurrentSessionSent()));
164 		sb.append(prep("currentSession nRecv", getPackagesCurrentSessionReceived()));
165 		
166 		sb.append(prep("nAllowedKeepAliveMisses", getAllowNKeepAliveMisses()));
167 		sb.append(prep("keepAlive period", getKeepAlivePeriod()));
168 		return sb.toString();
169 	}
170 	
171 	/**
172 	 * @param keepAlivePeriod the interval for the reader to send a keep-alive message. 
173 	 */
174 	public void _setKeepAlivePeriod(int keepAlivePeriod) {
175 		this.keepAlivePeriod = keepAlivePeriod;
176 	}
177 
178 	/**
179 	 * @return the interval for the reader to send a keep-alive message. 
180 	 */
181 	public int getKeepAlivePeriod() {
182 		return keepAlivePeriod;
183 	}
184 
185 	/**
186 	 * @param allowNKeepAliveMisses how many times a keep-alive can be missed.
187 	 */
188 	public void _setAllowNKeepAliveMisses(int allowNKeepAliveMisses) {
189 		this.allowNKeepAliveMisses = allowNKeepAliveMisses;
190 	}
191 
192 	/**
193 	 * @return how many times a keep-alive can be missed.
194 	 */
195 	public int getAllowNKeepAliveMisses() {
196 		return allowNKeepAliveMisses;
197 	}
198 
199 	/**
200 	 * @param port the port where to connect.
201 	 */
202 	public void _setPort(int port) {
203 		this.port = port;
204 	}
205 
206 	/**
207 	 * @return the port where to connect.
208 	 */
209 	public int getPort() {
210 		return port;
211 	}
212 
213 	/**
214 	 * @param readerAddress the address of the physical reader.
215 	 */
216 	public void _setReaderAddress(String readerAddress) {
217 		this.readerAddress = readerAddress;
218 	}
219 
220 	/**
221 	 * @return the address of the physical reader.
222 	 */
223 	public String getReaderAddress() {
224 		return readerAddress;
225 	}
226 
227 	/**
228 	 * @param readerName the name of this logical reader.
229 	 */
230 	public void _setReaderName(String readerName) {
231 		this.readerName = readerName;
232 	}
233 
234 	/**
235 	 * @return the name of this logical reader.
236 	 */
237 	public String getReaderName() {
238 		return readerName;
239 	}
240 	
241 	/**
242 	 * @param alive whether the reader is alive.
243 	 */
244 	public void _setAlive(boolean alive) {
245 		this.alive = alive;
246 	}
247 
248 	/**
249 	 * @return whether the reader is alive.
250 	 */
251 	public boolean isAlive() {
252 		return alive;
253 	}
254 
255 	/**
256 	 * @param packagesSent the number of sent packages in total.
257 	 */
258 	public void _setPackagesSent(int packagesSent) {
259 		this.packagesSent = packagesSent;
260 	}
261 
262 	/**
263 	 * @return the number of sent packages in total.
264 	 */
265 	public int getPackagesSent() {
266 		return packagesSent;
267 	}
268 
269 	/**
270 	 * @param packagesReceived the number of received packages in total.
271 	 */
272 	public void _setPackagesReceived(int packagesReceived) {
273 		this.packagesReceived = packagesReceived;
274 	}
275 
276 	/**
277 	 * @return the number of received packages in total.
278 	 */
279 	public int getPackagesReceived() {
280 		return packagesReceived;
281 	}
282 
283 	/**
284 	 * @param packagesCurrentSessionSent the number of sent packages in the current session.
285 	 */
286 	public void _setPackagesCurrentSessionSent(int packagesCurrentSessionSent) {
287 		this.packagesCurrentSessionSent = packagesCurrentSessionSent;
288 	}
289 
290 	/**
291 	 * @return the number of sent packages in the current session.
292 	 */
293 	public int getPackagesCurrentSessionSent() {
294 		return packagesCurrentSessionSent;
295 	}
296 
297 	/**
298 	 * @param packagesCurrentSessionReceived the number of received packages in the current session.
299 	 */
300 	public void _setPackagesCurrentSessionReceived(
301 			int packagesCurrentSessionReceived) {
302 		this.packagesCurrentSessionReceived = packagesCurrentSessionReceived;
303 	}
304 
305 	/**
306 	 * @return the number of received packages in the current session.
307 	 */
308 	public int getPackagesCurrentSessionReceived() {
309 		return packagesCurrentSessionReceived;
310 	}
311 
312 	/**
313 	 * @param reportKeepAlive whether keep alive messages get logged or not.
314 	 */
315 	public void _setReportKeepAlive(boolean reportKeepAlive) {
316 		this.reportKeepAlive = reportKeepAlive;
317 	}
318 
319 	/**
320 	 * @return whether keep alive messages get logged or not.
321 	 */
322 	public boolean isReportKeepAlive() {
323 		return reportKeepAlive;
324 	}
325 
326 	/**
327 	 * @param clientInitiated the clientInitiated to set
328 	 */
329 	public void _setClientInitiated(boolean clientInitiated) {
330 		this.clientInitiated = clientInitiated;
331 	}
332 
333 	/**
334 	 * @return the clientInitiated
335 	 */
336 	public boolean isClientInitiated() {
337 		return clientInitiated;
338 	}
339 
340 	/**
341 	 * @param connected flags whether the reader is connected or not.
342 	 */
343 	public void _setConnected(boolean connected) {
344 		this.connected = connected;
345 	}
346 
347 	/**
348 	 * @return whether the reader is connected or not.
349 	 */
350 	public boolean isConnected() {
351 		return connected;
352 	}
353 
354 	/**
355 	 * @param connectImmediately tells whether this reader connects directly after creation.
356 	 */
357 	public void _setConnectImmediately(boolean connectImmediately) {
358 		this.connectImmediately = connectImmediately;
359 	}
360 
361 	/**
362 	 * @return tells whether this reader connects directly after creation.
363 	 */
364 	public boolean isConnectImmediately() {
365 		return connectImmediately;
366 	}
367 }