001: package org.webdocwf.util.loader;
002:
003: /**
004: * <p>Title: TimeWatch.java</p>
005: * <p>Description: Time measuring of importDefinitions </p>
006: * <p>Copyright: Copyright (c) 2003</p>
007: * <p>Company: Together</p>
008: * @author Sinisa Milosevic sinisa@prozone.co.yu
009: * @version 1.0
010: */
011:
012: /**
013: Copyright (C) 2002-2003 Together
014:
015: This library is free software; you can redistribute it and/or
016: modify it under the terms of the GNU Lesser General Public
017: License as published by the Free Software Foundation; either
018: version 2.1 of the License, or (at your option) any later version.
019:
020: This library is distributed in the hope that it will be useful,
021: but WITHOUT ANY WARRANTY; without even the implied warranty of
022: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: Lesser General Public License for more details.
024:
025: You should have received a copy of the GNU Lesser General Public
026: License along with this library; if not, write to the Free Software
027: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
028:
029: */
030: import java.text.SimpleDateFormat;
031: import java.text.DateFormat;
032: import java.util.Date;
033:
034: /**
035: * Class used for calculating time.
036: *
037: * @author Sinisa Milosevic
038: * @version 1.1
039: */
040: public class TimeWatch {
041:
042: private long startTime = 0;
043: private long startJobTime = 0;
044:
045: /**
046: * Constructor
047: */
048: public TimeWatch() {
049: this .startJobTime = 0;
050: this .startTime = System.currentTimeMillis();
051: }
052:
053: /**
054: * Method getTotalTime - return all jobs duration as a String (min:sec,milsec)
055: * @return String (min:sec,milsec)
056: */
057: public String getTotalTime() {
058: long currentTime = System.currentTimeMillis();
059: long difference = currentTime - this .startTime;
060:
061: if (difference > 60000) {
062: long minutes = difference / 60000;
063: long remainder = difference % 60000;
064: return new String((new Long(minutes)).toString()
065: + " minutes "
066: + (new Long(remainder / 1000)).toString() + ","
067: + (new Long(remainder % 1000)).toString()
068: + " seconds");
069: } else if (currentTime > 1000)
070: return new String((new Long(difference / 1000)).toString()
071: + "," + (new Long(difference % 1000)).toString()
072: + " seconds");
073: else
074: return new String((new Long(difference)).toString()
075: + " miliseconds");
076: }
077:
078: /**
079: * Method setStartJobTime - set time counter for new loader job
080: */
081: public void setStartJobTime() {
082: this .startJobTime = System.currentTimeMillis();
083: }
084:
085: /**
086: *Method setStartTime - set time counter for all loader jobs
087: */
088: public void setStartTime() {
089: this .startTime = System.currentTimeMillis();
090: }
091:
092: /**
093: * Method getJobTime - return duration of loader job (importDefinition or sql) as a String (min:sec,milsec)
094: * @return (min:sec,milsec)
095: */
096: public String getJobTime() {
097: // DateFormat df = new SimpleDateFormat("mm:ss");
098: long currentTime = System.currentTimeMillis();
099: long difference = currentTime - this .startJobTime;
100: if (difference > 60000) {
101: long minutes = difference / 60000;
102: long remainder = difference % 60000;
103: return new String((new Long(minutes)).toString()
104: + " minutes "
105: + (new Long(remainder / 1000)).toString() + ","
106: + (new Long(remainder % 1000)).toString()
107: + " seconds");
108: } else if (currentTime > 1000)
109: return new String((new Long(difference / 1000)).toString()
110: + "," + (new Long(difference % 1000)).toString()
111: + " seconds");
112: else
113: return new String((new Long(difference)).toString()
114: + " miliseconds");
115: }
116:
117: /**
118: * set jop time to 0.
119: */
120: public void reset() {
121: this .startJobTime = 0;
122: }
123:
124: }
|