org.jlot.stats.client.StatsDumper Maven / Gradle / Ivy
package org.jlot.stats.client;
import java.util.Map;
import org.jlot.client.remote.StatsPushRestCommand;
import org.jlot.core.form.StatsForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StatsDumper implements Runnable
{
private StatsHarvester statsHarvester;
private StatsPushRestCommand statsPushRestCommand;
private String projectName;
private static final Logger logger = LoggerFactory.getLogger(StatsDumper.class);
public StatsDumper ( String projectName, StatsHarvester statsHarvester, StatsPushRestCommand statsPushRestCommand )
{
this.projectName = projectName;
this.statsHarvester = statsHarvester;
this.statsPushRestCommand = statsPushRestCommand;
}
public void dumpStats ( )
{
try
{
Map map = statsHarvester.getMap();
logger.info("Sending stats, size: {}", map.size());
StatsForm statsForm = new StatsForm();
statsForm.setProjectName(projectName);
statsForm.setTokenStats(map);
statsPushRestCommand.execute(statsForm);
statsHarvester.reset();
}
catch (Throwable e)
{
logger.error(e.getMessage(), e);
}
}
@Override
public void run ( )
{
dumpStats();
}
}