dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12540
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3879: Replaced TimeUtils with a Clock class which is an extension of commons-lang StopWatch. The previo...
------------------------------------------------------------
revno: 3879
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-06-12 11:34:27 +0200
message:
Replaced TimeUtils with a Clock class which is an extension of commons-lang StopWatch. The previous tool was a bit useless since it had static methods and was not threadsafe.
removed:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TimeUtils.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TimeUtilsTest.java
added:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Clock.java
modified:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
dhis-2/pom.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2011-06-12 08:23:05 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2011-06-12 09:34:27 +0000
@@ -33,8 +33,6 @@
import java.util.List;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.aggregation.AggregatedDataValueService;
import org.hisp.dhis.common.ProcessState;
import org.hisp.dhis.dataelement.DataElement;
@@ -53,8 +51,8 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.system.util.Clock;
import org.hisp.dhis.system.util.ConversionUtils;
-import org.hisp.dhis.system.util.TimeUtils;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -63,8 +61,6 @@
public class DefaultDataMartEngine
implements DataMartEngine
{
- private static final Log log = LogFactory.getLog( DefaultDataMartEngine.class );
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -154,12 +150,10 @@
public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
Collection<Integer> periodIds, Collection<Integer> organisationUnitIds, boolean useIndexes, ProcessState state )
{
- log.info( "Data mart export process started" );
-
int count = 0;
- TimeUtils.start();
-
+ Clock clock = new Clock().startClock().logTime( "Data mart export process started" );
+
// ---------------------------------------------------------------------
// Get objects
// ---------------------------------------------------------------------
@@ -190,7 +184,7 @@
allOperands.addAll( dataElementOperands );
allOperands.addAll( indicatorOperands );
- log.info( "Filtered data elements, number of operands: " + allOperands.size() + ", " + TimeUtils.getHMS() );
+ clock.logTime( "Filtered data elements, number of operands: " + allOperands.size() );
// ---------------------------------------------------------------------
// Remove operands without data
@@ -200,7 +194,7 @@
indicatorOperands.retainAll( allOperands );
- log.info( "Number of operands with data: " + allOperands.size() + ", "+ TimeUtils.getHMS() );
+ clock.logTime( "Number of operands with data: " + allOperands.size() );
// ---------------------------------------------------------------------
// Create crosstabtable
@@ -213,7 +207,7 @@
String key = crossTabService.populateCrossTabTable( new ArrayList<DataElementOperand>( allOperands ), intersectingPeriodIds, childrenIds );
- log.info( "Populated crosstab table: " + TimeUtils.getHMS() );
+ clock.logTime( "Populated crosstab table" );
// ---------------------------------------------------------------------
// Create aggregated data cache
@@ -223,7 +217,7 @@
crossTabService.createAggregatedDataCache( indicatorOperands, key );
- log.info( "Created aggregated data cache: " + TimeUtils.getHMS() );
+ clock.logTime( "Created aggregated data cache" );
// ---------------------------------------------------------------------
// Drop potential indexes
@@ -233,19 +227,17 @@
aggregatedDataValueService.dropIndex( true, isIndicators );
- log.info( "Dropped potential indexes: " + TimeUtils.getHMS() );
+ clock.logTime( "Dropped potential indexes" );
// ---------------------------------------------------------------------
// Delete existing aggregated data
// ---------------------------------------------------------------------
- state.setMessage( "deleting_existing_aggregated_data" );
-
aggregatedDataValueService.deleteAggregatedDataValues( dataElementIds, periodIds, organisationUnitIds );
aggregatedDataValueService.deleteAggregatedIndicatorValues( indicatorIds, periodIds, organisationUnitIds );
- log.info( "Deleted existing aggregated data: " + TimeUtils.getHMS() );
+ clock.logTime( "Deleted existing aggregated data" );
// ---------------------------------------------------------------------
// Export data element values
@@ -257,7 +249,7 @@
{
count += dataElementDataMart.exportDataValues( allOperands, periods, organisationUnits, operandList, key );
- log.info( "Exported values for data element operands (" + allOperands.size() + "): " + TimeUtils.getHMS() );
+ clock.logTime( "Exported values for data element operands (" + allOperands.size() + ")" );
}
// ---------------------------------------------------------------------
@@ -266,7 +258,7 @@
crossTabService.dropCrossTabTable( key );
- log.info( "Dropped crosstab table: " + TimeUtils.getHMS() );
+ clock.logTime( "Dropped crosstab table" );
// ---------------------------------------------------------------------
// Export indicator values
@@ -278,7 +270,7 @@
{
count += indicatorDataMart.exportIndicatorValues( indicators, periods, organisationUnits, indicatorOperands, key );
- log.info( "Exported values for indicators (" + indicators.size() + "): " + TimeUtils.getHMS() );
+ clock.logTime( "Exported values for indicators (" + indicators.size() + ")" );
}
// ---------------------------------------------------------------------
@@ -287,7 +279,7 @@
crossTabService.dropAggregatedDataCache( key );
- log.info( "Dropped aggregated data cache: " + TimeUtils.getHMS() );
+ clock.logTime( "Dropped aggregated data cache" );
// ---------------------------------------------------------------------
// Create potential indexes
@@ -297,15 +289,13 @@
{
aggregatedDataValueService.createIndex( true, isIndicators );
- log.info( "Created indexes: " + TimeUtils.getHMS() );
+ clock.logTime( "Created indexes" );
}
-
- log.info( "Data mart export process completed: " + TimeUtils.getHMS() );
-
- TimeUtils.stop();
aggregationCache.clearCache();
+ clock.logTime( "Data mart export process completed" );
+
return count;
}
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Clock.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Clock.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Clock.java 2011-06-12 09:34:27 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class Clock
+ extends StopWatch
+{
+ private static final Log log = LogFactory.getLog( Clock.class );
+
+ private static final String SEPARATOR = ": ";
+
+ public Clock()
+ {
+ super();
+ }
+
+ public Clock startClock()
+ {
+ this.start();
+
+ return this;
+ }
+
+ public Clock logTime( String message )
+ {
+ super.split();
+
+ String time = DurationFormatUtils.formatDurationHMS( super.getSplitTime() );
+
+ log.info( message + SEPARATOR + time );
+
+ return this;
+ }
+}
=== removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TimeUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TimeUtils.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TimeUtils.java 1970-01-01 00:00:00 +0000
@@ -1,91 +0,0 @@
-package org.hisp.dhis.system.util;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-import org.apache.commons.lang.time.StopWatch;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author Lars Helge Overland
- * @version $Id: TimeUtil.java 4646 2008-02-26 14:54:29Z larshelg $
- */
-public class TimeUtils
-{
- private static final Log log = LogFactory.getLog( TimeUtils.class );
-
- private static StopWatch watch;
-
- static
- {
- watch = new StopWatch();
- }
-
- public static void start()
- {
- watch.reset();
- watch.start();
- }
-
- public static long getMillis()
- {
- watch.split();
-
- return watch.getSplitTime();
- }
-
- public static String getHMS()
- {
- watch.split();
-
- return DurationFormatUtils.formatDurationHMS( watch.getSplitTime() );
- }
-
- public static void markMillis( String message )
- {
- watch.split();
-
- log.info( message + ": " + watch.getSplitTime() );
- }
-
- public static void markHMS( String message )
- {
- watch.split();
-
- String time = DurationFormatUtils.formatDurationHMS( watch.getSplitTime() );
-
- log.info( message + ": " + time + " ms" );
- }
-
- public static void stop()
- {
- watch.stop();
- watch.reset();
- }
-}
=== removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TimeUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TimeUtilsTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TimeUtilsTest.java 1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
-package org.hisp.dhis.system.util;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import junit.framework.TestCase;
-
-/**
- * @author Lars Helge Overland
- * @version $Id: MathUtil.java 4712 2008-03-12 10:32:45Z larshelg $
- */
-public class TimeUtilsTest
- extends TestCase
-{
- public void testStopWatch()
- throws Exception
- {
- TimeUtils.start();
-
- Thread.sleep( 100 );
-
- TimeUtils.markMillis( "Split Millis" );
-
- Thread.sleep( 400 );
-
- TimeUtils.markHMS( "Split HMS" );
-
- TimeUtils.stop();
- }
-
- public void testStopWatchAbort()
- throws Exception
- {
- TimeUtils.start();
-
- Thread.sleep( 100 );
-
- TimeUtils.start();
- }
-}
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2011-05-29 11:16:49 +0000
+++ dhis-2/pom.xml 2011-06-12 09:34:27 +0000
@@ -440,7 +440,7 @@
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
- <version>2.5</version>
+ <version>2.6</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>