package kz.cafe.statistics;

import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

public class ClientCounters{

   public static final ConcurrentHashMap<Class<?>, AtomicLong> mapSumTime =
                                                     new ConcurrentHashMap<Class<?>, AtomicLong>();


   public static final ConcurrentHashMap<Class<?>, AtomicLong> mapRequestCountes =
                                                     new ConcurrentHashMap<Class<?>, AtomicLong>();



   public static void addRequestTime(Class<?> agent, long time){
      AtomicLong atomlSumTime = mapSumTime.get(agent);

      if(atomlSumTime == null){
         atomlSumTime = new AtomicLong(0);
         mapSumTime.put(agent, atomlSumTime);
      }

      atomlSumTime.addAndGet(time);



      AtomicLong atomlRequestCounter = mapRequestCountes.get(agent);

      if(atomlRequestCounter == null){
         atomlRequestCounter = new AtomicLong(0);
         mapRequestCountes.put(agent, atomlRequestCounter);
      }

      atomlRequestCounter.incrementAndGet();
   }
}
