Coverage Report - org.kuali.rice.krms.framework.engine.result.TimingResult
 
Classes in this File Line Coverage Branch Coverage Complexity
TimingResult
25%
8/31
0%
0/2
1.2
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krms.framework.engine.result;
 17  
 
 18  
 import java.util.Collections;
 19  
 import java.util.EventObject;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.joda.time.DateTime;
 23  
 import org.joda.time.format.DateTimeFormat;
 24  
 import org.joda.time.format.DateTimeFormatter;
 25  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 26  
 import org.kuali.rice.krms.api.engine.ResultEvent;
 27  
 
 28  
 public class TimingResult extends EventObject implements ResultEvent {
 29  
     
 30  
         private static final long serialVersionUID = 5335636381355236617L;
 31  
 
 32  1
     private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH.mm.ss.SSS");
 33  
         
 34  
     private String type;
 35  
         private DateTime start;
 36  
         private DateTime end;
 37  
         private ExecutionEnvironment environment;
 38  
         private String description;
 39  
         private Map<String, ?> resultDetails;
 40  
 
 41  
         public TimingResult(String description, String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
 42  0
                 super(source);
 43  0
                 this.type = type;
 44  0
                 this.environment = environment;
 45  0
                 this.start = start;
 46  0
                 this.end = end;
 47  0
                 this.description = description;
 48  0
         }
 49  
         
 50  
         public TimingResult(String type, Object source, ExecutionEnvironment environment, DateTime start, DateTime end){
 51  29
                 super(source);
 52  29
                 this.type = type;
 53  29
                 this.environment = environment;
 54  29
                 this.start = start;
 55  29
                 this.end = end;
 56  29
         }
 57  
         
 58  
         public Long getElapsedTimeInMilliseconds(){
 59  0
                 return Long.valueOf(end.getMillis() - start.getMillis());
 60  
         }
 61  
         
 62  
         public ExecutionEnvironment getEnvironment(){
 63  29
                 return environment;
 64  
         };
 65  
         
 66  
         public String toString(){
 67  0
                 StringBuffer sb = new StringBuffer();
 68  0
                 sb.append(fmt.print(end));
 69  0
                 sb.append(" EventType: "+ type);
 70  0
                 sb.append(" (Start = " + fmt.print(start));
 71  0
                 sb.append(", End = " + fmt.print(end));
 72  0
                 sb.append(",  Elapsed Time = "+ getElapsedTimeInMilliseconds().toString());
 73  0
                 sb.append(" milliseconds.)");
 74  0
                 return sb.toString();
 75  
         }
 76  
 
 77  
         @Override
 78  
         public Boolean getResult() {
 79  0
                 return null;
 80  
         }
 81  
 
 82  
         @Override
 83  
         public DateTime getTimestamp() {
 84  0
                 return end;
 85  
         }
 86  
 
 87  
         @Override
 88  
         public String getType() {
 89  0
                 return type;
 90  
         }
 91  
         
 92  
         @Override
 93  
         public Map<String, ?> getResultDetails() {
 94  0
             if (resultDetails == null) {
 95  0
                 return Collections.emptyMap();
 96  
             } else {
 97  0
                 return Collections.unmodifiableMap(resultDetails);
 98  
             }
 99  
         }
 100  
         
 101  
         @Override
 102  
         public String getDescription() {
 103  0
                 return description;
 104  
         }
 105  
 }