KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > engine > LagDetector


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/LagDetector.java,v 1.5 2004/02/13 02:21:37 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.engine;
20
21 /**
22  * TODO - appears to be unused
23  *
24  * @version $Revision: 1.5 $
25  */

26 public class LagDetector extends Thread JavaDoc
27 {
28     private long incr = MAX_SLEEP / DIV;
29     private long totalLag;
30     private int count;
31     private boolean running;
32     public final static long MAX_SLEEP = 500;
33
34     private final static long DIV = 3;
35
36     /**
37      * Constructor for the LagDetector object.
38      */

39     public LagDetector()
40     {
41     }
42
43     /**
44      * Gets the AveLag attribute of the LagDetector object.
45      *
46      * @return the AveLag value
47      */

48     public float getAveLag()
49     {
50         return (float) ((float) totalLag / (float) count);
51     }
52
53     /**
54      * Gets the LagRatio attribute of the LagDetector object.
55      *
56      * @return the LagRatio value
57      */

58     public float getLagRatio()
59     {
60         return ((float) totalLag / (float) count) / incr;
61     }
62
63     public void stopRunning()
64     {
65         running = false;
66     }
67
68     /**
69      * Main processing method for the LagDetector object.
70      */

71     public void run()
72     {
73         running = true;
74         long time;
75         totalLag = 0;
76         count = 0;
77         while (running)
78         {
79             time = System.currentTimeMillis();
80             try
81             {
82                 Thread.sleep(incr);
83             }
84             catch (Exception JavaDoc e)
85             {
86             }
87             time = System.currentTimeMillis() - time;
88             totalLag += time - incr;
89             count++;
90         }
91     }
92 }
93
Popular Tags