Coverage Report - org.galagosearch.tupleflow.execution.NetworkedCounterManager
 
Classes in this File Line Coverage Branch Coverage Complexity
NetworkedCounterManager
0%
0/26
0%
0/8
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 
 3  
 package org.galagosearch.tupleflow.execution;
 4  
 
 5  
 import java.util.HashMap;
 6  
 import org.galagosearch.tupleflow.Counter;
 7  
 
 8  
 /**
 9  
  *
 10  
  * @author trevor
 11  
  */
 12  0
 public class NetworkedCounterManager implements Runnable {
 13  0
     HashMap<String, NetworkedCounter> counters = new HashMap<String, NetworkedCounter>();
 14  0
     boolean stop = false;
 15  0
     int sleepInterval = 1000;
 16  
     Thread thread;
 17  
 
 18  
     public synchronized Counter newCounter(
 19  
             String counterName, String stageName, String instance, String url) {
 20  0
         String key = String.format("%s-%s-%s", counterName, stageName, instance);
 21  0
         if (counters.containsKey(key))
 22  0
             return counters.get(key);
 23  0
         NetworkedCounter counter = new NetworkedCounter(counterName, stageName, instance, url);
 24  0
         counters.put(key, counter);
 25  0
         return counter;
 26  
     }
 27  
 
 28  
     public void start() {
 29  0
         thread = new Thread(this);
 30  0
         thread.start();
 31  0
     }
 32  
 
 33  
     public synchronized void stop() {
 34  0
         stop = true;
 35  0
         if (thread != null)
 36  0
             thread.interrupt();
 37  0
     }
 38  
 
 39  
     public void run() {
 40  
         while (true) {
 41  0
             synchronized(this) {
 42  0
                 for (NetworkedCounter counter : counters.values()) {
 43  0
                     counter.flush();
 44  
                 }
 45  
 
 46  0
                 if (stop) break;
 47  0
             }
 48  
 
 49  
             try {
 50  0
                 Thread.sleep(sleepInterval);
 51  0
             } catch (InterruptedException ex) {
 52  
                 // it's probably time to flush and quit now
 53  0
             }
 54  
         }
 55  0
     }
 56  
 }