Source code: java/net/Listener.java
1 /* ZNet - Java Compression Layer for a new Socket Factory
2 Copyright (C) 1999, Free Software Rulez
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 The author of this program may be contacted at morgiaclaudio@yahoo.it. */
19
20 package java.net;
21
22 /**
23 * This class represents the two separate half parts of the measurement process upon which is based
24 * the statistical model used to drive the compression layer.
25 * It exists a listener for every received packet waiting for its ack to come.
26 * When the listener is created it carries information about the interpolator it should update and
27 * the measured parameters like the choosed working level, the compression time and dimension and the
28 * uncompressed dimension.
29 * Finally, when the ack arrives, the listener is awakened and the transmission time is measured.
30 * Now the model is complete and the interpolator can be updated.
31 * @see #run the main loop of the Connector
32 * @see java.net.Connector the main loop owner
33 * @see java.net.Interpolator the statistical engine interface
34 * @author <a href="mailto:morgiaclaudio@yahoo.it">Claudio Morgia</a>
35 * @version 1.0
36 */
37 public class Listener {
38 /**
39 * The interpolator to update.
40 */
41 protected Interpolator interpolator;
42
43 protected int level,uncompr_len,compr_len;
44 protected long compress_time,send_start;
45
46 /**
47 * The constructor represents the first half of the measurement and it's responsible only for storing
48 * measured parameters. No calculation is done yet.
49 * @param interpolator the interpolator to update
50 * @param level the working level
51 * @param compress_time the measured compress time
52 * @param uncompr_len the uncompressed data length
53 * @param compr_len the compressed data length
54 */
55 public Listener(Interpolator interpolator,int level,long compress_time,int uncompr_len,int compr_len) {
56 send_start=System.currentTimeMillis();
57 this.interpolator=interpolator;
58 this.level=level;
59 this.compress_time=compress_time;
60 this.uncompr_len=uncompr_len;
61 this.compr_len=compr_len;
62 }
63
64 /**
65 * This method represents the second half of the measurement and it does the real update, based on
66 * the measured transmission time, after the ack has arrived.
67 * @see java.net.Interpolator#update
68 */
69 public void done() {
70 long trans_time=System.currentTimeMillis()-send_start;
71 interpolator.update(level,uncompr_len,compress_time,compr_len,trans_time);
72 }
73 }