All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.highway2urhell.service.GatherService Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.highway2urhell.service;

import com.highway2urhell.CoreEngine;
import com.highway2urhell.domain.H2hConfig;
import com.highway2urhell.domain.ThunderData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class GatherService {
    private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
    private static GatherService instance;
    private Map mapThunderData;

    public static GatherService getInstance() {
        if (instance == null) {
            synchronized (GatherService.class) {
                if (instance == null) {
                    instance = new GatherService();
                }
            }
        }
        return instance;
    }

    private GatherService() {
        mapThunderData = new HashMap();
    }
    
    public void gatherPerformance(String fullMethodName,long timeExec){
    	 H2hConfig hc = CoreEngine.getInstance().getConfig();
         switch (hc.getTimer()) {
             case MEMORY:
            	 LOGGER.info(" fullMethodName "+fullMethodName+" timeExec "+timeExec);
             	 break;
             case REMOTE:
                 long timerConfig = CoreEngine.getInstance().getConfig().getHigherTime().longValue();
                 if(timeExec>timerConfig) {
                     int tExec = (int) timeExec;
                     ThunderExporterService.getInstance().sendRemotePerformance(fullMethodName, tExec);
                 }
                 break;
             default:
                 LOGGER.info("No config for Timer");
         }
    }

    public void gatherInvocation(String fullMethodName) {
        H2hConfig hc = CoreEngine.getInstance().getConfig();
        switch (hc.getOutputSystem()) {
            case MEMORY:
                ThunderData td = mapThunderData.get(fullMethodName);
                if (td == null) {
                    // first time
                    td = new ThunderData(fullMethodName);
                    mapThunderData.put(fullMethodName, td);
                }
                td.incrementCounter();
                break;
            case REMOTE:
                ThunderExporterService.getInstance().sendRemoteBreaker(fullMethodName);
                break;
            default:
                throw new IllegalStateException(hc.getOutputSystem()
                        + " is not supported");
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy