Coverage report

  %line %branch
net.sf.infrared.agent.transport.impl.PooledAggregator
0% 
0% 

 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:  binil.thomas (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.agent.transport.impl;
 23  
 
 24  
 import net.sf.infrared.agent.transport.Aggregator;
 25  
 import net.sf.infrared.agent.transport.Forwarder;
 26  
 import net.sf.infrared.base.model.OperationStatistics;
 27  
 import net.sf.infrared.base.util.LoggingFactory;
 28  
 
 29  
 import org.apache.log4j.Logger;
 30  
 
 31  
 import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
 32  
 import EDU.oswego.cs.dl.util.concurrent.Executor;
 33  
 import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
 34  
 
 35  
 /**
 36  
  * 
 37  
  * @author binil.thomas
 38  
  */
 39  0
 public class PooledAggregator implements Aggregator {
 40  0
     private static final Logger log = LoggingFactory.getLogger(PooledAggregator.class);
 41  
 
 42  
     private PooledExecutor executor;
 43  
 
 44  
     private Aggregator aggregator;
 45  
 
 46  0
     public PooledAggregator(Aggregator aggregator, int bufferLength, class="keyword">int maxThreads) {
 47  0
         this.aggregator = aggregator;
 48  
 
 49  0
         executor = new PooledExecutor(class="keyword">new BoundedBuffer(bufferLength), maxThreads);
 50  0
         executor.setKeepAliveTime(1000 * 60 * 5); // 5 minutes
 51  0
         executor.discardOldestWhenBlocked();
 52  0
     }
 53  
 
 54  
     public void aggregate(final OperationStatistics stats) {
 55  
         try {
 56  0
             executor.execute(new Runnable() {
 57  
                 public void run() {
 58  
                     aggregator.aggregate(stats);
 59  
                 }
 60  
             });
 61  
 
 62  0
             if (log.isDebugEnabled()) {
 63  0
                 log.debug("Scheduled " + stats + " for merging");
 64  
             }
 65  0
         } catch (InterruptedException e) {
 66  0
             log.error("Error in aggregate, ignoring", e);
 67  0
         }
 68  0
     }
 69  
 
 70  
     public void flush() {
 71  0
         aggregator.flush();
 72  0
     }
 73  
 
 74  
     public void setForwarder(Forwarder forwarder) {
 75  0
         aggregator.setForwarder(forwarder);
 76  0
     }
 77  
     
 78  
     public void shutdown() {
 79  0
         executor.shutdownNow();
 80  0
         aggregator.shutdown();
 81  0
     }
 82  
 }

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