Coverage Report - net.admin4j.timer.TaskTimerFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
TaskTimerFactory
94%
18/19
100%
4/4
1.75
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.timer;
 15  
 
 16  
 import java.util.ArrayList;
 17  
 import java.util.Arrays;
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 import java.util.Set;
 21  
 
 22  
 import net.admin4j.deps.commons.lang3.Validate;
 23  
 import net.admin4j.vo.DataMeasurementSummaryVO;
 24  
 
 25  
 /**
 26  
  * Used to start task timings and obtain a TaskTimer.
 27  
  * @author D. Ashmore
 28  
  * @since 1.0
 29  
  */
 30  0
 public class TaskTimerFactory {
 31  
     
 32  
     /**
 33  
      * Will return a started timer using the requested label.
 34  
      * 
 35  
      * <p>By default, timers are configured with a SmmaryDataMeasure and RollingTimePeriodDataMeasure.</p>
 36  
      * 
 37  
      * @see SummaryDataMeasure
 38  
      * @see RollingNbrObservationsDataMeasure
 39  
      * @param label
 40  
      * @param dataMeasures
 41  
      * @return
 42  
      * @since 1.0
 43  
      */
 44  
     public static TaskTimer start(String label, DataMeasure...dataMeasures ) {
 45  3000033
         TaskTimer timer = TaskTimerRegistry.findTaskTimer(label);
 46  
         
 47  3000033
         if (timer != null)  {
 48  3000009
             timer.start();
 49  3000009
             return timer;
 50  
         }
 51  
         
 52  24
         List<DataMeasure> list = new ArrayList<DataMeasure>();
 53  24
         if (dataMeasures.length == 0) {
 54  21
             list.add(new SummaryDataMeasure(System.currentTimeMillis()));
 55  21
             list.add(new RollingNbrObservationsDataMeasure());
 56  
         }
 57  3
         else list.addAll(Arrays.asList(dataMeasures));
 58  
         
 59  
         
 60  24
         timer = new BasicTaskTimer(label, list);
 61  24
         TaskTimerRegistry.register(timer);
 62  
         
 63  24
         timer.start();
 64  24
         return timer;
 65  
     }
 66  
     
 67  
     public static void delete(String label) {
 68  
         Validate.notEmpty(label,"Null or blank label not allowed.");
 69  3
         TaskTimerRegistry.delete(label);
 70  3
     }
 71  
     
 72  
     protected static void clearAll() {
 73  6
         TaskTimerRegistry.clearAll();
 74  6
     }
 75  
     
 76  
     public static Map<String,Set<DataMeasurementSummaryVO>> getDataSummaryMap() {
 77  15
         return TaskTimerRegistry.getDataSummaryMap();
 78  
     }
 79  
 
 80  
 }