Coverage report

  %line %branch
net.sf.infrared.collector.impl.CollectorImpl
12% 
70% 

 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:  subin.p (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.collector.impl;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.util.Collection;
 26  
 import java.util.Date;
 27  
 import java.util.Set;
 28  
 import net.sf.infrared.base.model.StatisticsSnapshot;
 29  
 
 30  
 import org.apache.log4j.Logger;
 31  
 
 32  
 import net.sf.infrared.base.model.ApplicationStatistics;
 33  
 import net.sf.infrared.base.util.LoggingFactory;
 34  
 import net.sf.infrared.collector.StatisticsRepository;
 35  
 import net.sf.infrared.collector.Collector;
 36  
 import net.sf.infrared.collector.CollectorConfig;
 37  
 import net.sf.infrared.collector.impl.persistence.Persister;
 38  
 import net.sf.infrared.collector.impl.transport.AgentListener;
 39  
 
 40  1
 public class CollectorImpl implements Collector {
 41  2
     private static final Logger log = LoggingFactory.getLogger(CollectorImpl.class);
 42  
 
 43  
     private StatisticsRepository statsRepository;
 44  
 
 45  
     private AgentListener agentListener;
 46  
 
 47  
     private Persister persister;
 48  
 
 49  
     public boolean start(CollectorConfig cfg) {
 50  0
         statsRepository = new StatisticsRepository();
 51  
 
 52  
         try {
 53  0
             this.agentListener = new AgentListener(cfg, statsRepository);
 54  0
             agentListener.start();
 55  0
         } catch (IOException e) {
 56  0
             log.error("Failed to initialise the AgentListener : IOException", e);
 57  0
             return false;
 58  0
         }
 59  
 
 60  0
         persister = new Persister(cfg, statsRepository);
 61  0
         persister.start();
 62  
         
 63  0
         log.debug("Started the Collector instance successfully");
 64  0
         log.debug("The persist interval for the collector is configured at :" 
 65  
                 + cfg.getPersistInterval() + " milliseconds");
 66  
         
 67  0
         return true;
 68  
     }
 69  
 
 70  
     public boolean shutdown() {
 71  0
         if (agentListener != null) {
 72  0
             agentListener.requestShutdown();
 73  
         }
 74  
 
 75  0
         if (persister != null) {
 76  0
             persister.shutdown();
 77  
         }
 78  
 
 79  0
         log.debug("Shutdown Collector successfully");
 80  0
         return true;
 81  
     }
 82  
 
 83  
     public StatisticsSnapshot fetchStats(Collection appNames, Collection instanceIds) {
 84  0
         if (appNames == null || instanceIds == class="keyword">null)
 85  0
             throw new IllegalArgumentException(
 86  
                     "The list of application names and instanceIds cannot be null");
 87  
 
 88  0
         StatisticsSnapshot snapshot = statsRepository.fetchStatsSinceStartup(appNames, instanceIds);
 89  0
         if (log.isDebugEnabled()) {
 90  0
             log.debug("Fetched SnapShot (from memory) for applications[" + appNames + 
 91  
                     "] and instances[" + instanceIds + "]");
 92  
         }
 93  0
         return snapshot;
 94  
     }
 95  
 
 96  
     public StatisticsSnapshot fetchStatsFromDB(Collection appNames, Collection instanceIds,
 97  
             Date from, Date to) {
 98  1
         if (appNames == null || instanceIds == class="keyword">null)
 99  0
             throw new IllegalArgumentException(
 100  
                     "The list of application names and instanceIds cannot be null");
 101  
 
 102  1
         if (from == null)
 103  1
             throw new IllegalArgumentException("The from date for the fetch cannot be null");
 104  
 
 105  0
         if (to == null)
 106  0
             to = new Date();
 107  
 
 108  0
         StatisticsSnapshot snapshot = statsRepository.fetchStatsFromDB(appNames, instanceIds, from, to);
 109  0
         if (log.isDebugEnabled()) {
 110  0
             log.debug("Fetched SnapShot (from DB) for applications[" + appNames + 
 111  
                     "] and instances[" + instanceIds + "]");
 112  
         }
 113  0
         return snapshot;
 114  
     }
 115  
     
 116  
     public Set getApplicationNames() {
 117  0
         return statsRepository.getApplicationNames();        
 118  
     }    
 119  
     
 120  
     
 121  
     public Set getInstanceNames(Set applicationNames){
 122  0
         return statsRepository.getInstanceNames(applicationNames);
 123  
     }
 124  
     
 125  
     public void clearStats() {
 126  0
         statsRepository.clearStatsSinceStartup();
 127  0
     }
 128  
 }

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