KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > TimeWatch


1 package org.webdocwf.util.loader;
2
3 /**
4  * <p>Title: TimeWatch.java</p>
5  * <p>Description: Time measuring of importDefinitions </p>
6  * <p>Copyright: Copyright (c) 2003</p>
7  * <p>Company: Together</p>
8  * @author Sinisa Milosevic sinisa@prozone.co.yu
9  * @version 1.0
10  */

11
12 /**
13     Copyright (C) 2002-2003 Together
14
15     This library is free software; you can redistribute it and/or
16     modify it under the terms of the GNU Lesser General Public
17     License as published by the Free Software Foundation; either
18     version 2.1 of the License, or (at your option) any later version.
19
20     This library is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23     Lesser General Public License for more details.
24
25     You should have received a copy of the GNU Lesser General Public
26     License along with this library; if not, write to the Free Software
27     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
29 */

30 import java.text.SimpleDateFormat JavaDoc;
31 import java.text.DateFormat JavaDoc;
32 import java.util.Date JavaDoc;
33
34 /**
35  * Class used for calculating time.
36  *
37  * @author Sinisa Milosevic
38  * @version 1.1
39  */

40 public class TimeWatch {
41
42   private long startTime = 0;
43   private long startJobTime = 0;
44
45   /**
46    * Constructor
47    */

48   public TimeWatch() {
49     this.startJobTime=0;
50     this.startTime=System.currentTimeMillis();
51   }
52
53
54   /**
55    * Method getTotalTime - return all jobs duration as a String (min:sec,milsec)
56    * @return String (min:sec,milsec)
57    */

58   public String JavaDoc getTotalTime() {
59     long currentTime = System.currentTimeMillis();
60         long difference = currentTime-this.startTime;
61
62         if(difference>60000){
63           long minutes = difference/60000;
64           long remainder = difference%60000;
65           return new String JavaDoc((new Long JavaDoc(minutes)).toString()+" minutes "+
66                             (new Long JavaDoc(remainder/1000)).toString()+","+(new Long JavaDoc(remainder%1000)).toString()+" seconds");
67         }
68         else if(currentTime>1000)
69           return new String JavaDoc((new Long JavaDoc(difference/1000)).toString()+","+(new Long JavaDoc(difference%1000)).toString()+" seconds");
70         else
71       return new String JavaDoc((new Long JavaDoc(difference)).toString() +" miliseconds"); }
72
73   /**
74    * Method setStartJobTime - set time counter for new loader job
75    */

76   public void setStartJobTime() {
77     this.startJobTime = System.currentTimeMillis();
78   }
79
80   /**
81      *Method setStartTime - set time counter for all loader jobs
82      */

83     public void setStartTime() {
84       this.startTime = System.currentTimeMillis();
85   }
86   /**
87    * Method getJobTime - return duration of loader job (importDefinition or sql) as a String (min:sec,milsec)
88    * @return (min:sec,milsec)
89    */

90   public String JavaDoc getJobTime() {
91 // DateFormat df = new SimpleDateFormat("mm:ss");
92
long currentTime = System.currentTimeMillis();
93     long difference = currentTime-this.startJobTime;
94     if(difference>60000){
95       long minutes = difference/60000;
96       long remainder = difference%60000;
97       return new String JavaDoc((new Long JavaDoc(minutes)).toString()+" minutes "+
98                         (new Long JavaDoc(remainder/1000)).toString()+","+(new Long JavaDoc(remainder%1000)).toString()+" seconds");
99     }
100     else if(currentTime>1000)
101       return new String JavaDoc((new Long JavaDoc(difference/1000)).toString()+","+(new Long JavaDoc(difference%1000)).toString()+" seconds");
102     else
103       return new String JavaDoc((new Long JavaDoc(difference)).toString() +" miliseconds");
104   }
105
106   /**
107    * set jop time to 0.
108    */

109   public void reset() {
110     this.startJobTime=0;
111   }
112
113 }
Popular Tags