Coverage report

  %line %branch
net.sf.infrared.agent.transport.impl.BufferedAggregator
90% 
96% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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  
  *
 17  
  *
 18  
  * Original Author:  kamal.govindraj (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.agent.transport.impl;
 23  
 
 24  
 import org.apache.log4j.Logger;
 25  
 
 26  
 import net.sf.infrared.agent.transport.Aggregator;
 27  
 import net.sf.infrared.agent.transport.Forwarder;
 28  
 import net.sf.infrared.base.model.ApplicationStatistics;
 29  
 import net.sf.infrared.base.model.OperationStatistics;
 30  
 import net.sf.infrared.base.util.LoggingFactory;
 31  
 
 32  
 /**
 33  
  * Implementation of the aggregator which merges each update with a local
 34  
  * statistics instance and flushes the aggregated statistics in response to a
 35  
  * flush.
 36  
  * 
 37  
  * @author kamal.govindraj
 38  
  */
 39  
 public class BufferedAggregator implements Aggregator {
 40  2
     private static final Logger log = LoggingFactory.getLogger(BufferedAggregator.class);
 41  
 
 42  
     private Forwarder forwarder;
 43  
 
 44  
     private ApplicationStatistics bufferStatistics;
 45  
 
 46  4
     public BufferedAggregator() {
 47  4
     }
 48  
 
 49  
     public void aggregate(OperationStatistics stats) {
 50  2
         log.info("BufferedAggregator.aggregate");
 51  2
         synchronized (this) {
 52  2
             if (bufferStatistics == null) {
 53  2
                 bufferStatistics = 
 54  
                         new ApplicationStatistics(stats.getApplicationName(), stats.getInstanceId());
 55  2
                 log.info("Create new statistics object");
 56  
             }
 57  2
             bufferStatistics.merge(stats);
 58  2
             log.info("Merged statistics");
 59  2
         }
 60  2
     }
 61  
 
 62  
     public void flush() {
 63  5
         ApplicationStatistics statsToFlush = null;
 64  5
         synchronized (this) {
 65  5
             if (this.bufferStatistics != null) {
 66  2
                 statsToFlush = this.bufferStatistics;
 67  2
                 this.bufferStatistics = null;
 68  
             } else {
 69  3
                 if (this.bufferStatistics == null && log.isDebugEnabled()) {
 70  0
                     log.debug("No stats to send to collector; ignoring flush");
 71  
                 }
 72  3
                 return;
 73  
             }
 74  2
         }
 75  
         // Moved the forward call out of the synchorinzed block
 76  
         // as this can block and hold up the aggregate calls
 77  2
         if (this.forwarder != null) {
 78  2
             if (statsToFlush != null) {
 79  2
                 this.forwarder.forward(statsToFlush);
 80  2
                 statsToFlush.reset();
 81  
             }
 82  
         } else {
 83  0
             log.error("Forwarder not initialized");
 84  
         }
 85  2
     }
 86  
 
 87  
     public void setForwarder(Forwarder forwarder) {
 88  3
         this.forwarder = forwarder;
 89  3
     }
 90  
     
 91  
     public void shutdown() {        
 92  0
     }
 93  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.