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

org.jlot.stats.client.StatsConfig Maven / Gradle / Ivy

package org.jlot.stats.client;

import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.jlot.client.config.JlotClient;
import org.jlot.client.remote.StatsPushRestCommand;

public class StatsConfig
{
	private String						server;
	private String						projectName;
	private String						username;
	private String						password;
	private StatsDumper					statsDumper;
	private long						delayInSeconds	= 30;
	private JlotClient					jlotClient		= new JlotClient();
	private ScheduledExecutorService	executor;

	public void stop ( )
	{
		MessageSourceStatsAspect.setActive(false);
		if (jlotClient.isStarted())
		{
			jlotClient.stop();
		}
		if (executor != null)
		{
			executor.shutdown();
		}
	}

	public void start ( )
	{
		MessageSourceStatsAspect.setActive(true);
		if (!jlotClient.isStarted())
		{
			jlotClient.start(getProperties());
		}
		if (executor != null)
		{
			executor.shutdown();
		}
		StatsPushRestCommand statsPushRestCommand = jlotClient.getRestCommand(StatsPushRestCommand.class);
		StatsHarvester statsHarvester = MessageSourceStatsAspect.getStatsHarvester();
		this.statsDumper = new StatsDumper(projectName, statsHarvester, statsPushRestCommand);
		executor = Executors.newScheduledThreadPool(1);
		executor.scheduleWithFixedDelay(statsDumper, delayInSeconds, delayInSeconds, TimeUnit.SECONDS);
	}

	public long getDelayInSeconds ( )
	{
		return delayInSeconds;
	}

	public void setDelayInSeconds ( long delayInSeconds )
	{
		this.delayInSeconds = delayInSeconds;
	}

	public String getServer ( )
	{
		return server;
	}

	public void setServer ( String server )
	{
		this.server = server;
	}

	public String getProjectName ( )
	{
		return projectName;
	}

	public void setProjectName ( String projectName )
	{
		this.projectName = projectName;
	}

	public String getUsername ( )
	{
		return username;
	}

	public void setUsername ( String username )
	{
		this.username = username;
	}

	public String getPassword ( )
	{
		return password;
	}

	public void setPassword ( String password )
	{
		this.password = password;
	}

	public Properties getProperties ( )
	{
		// server.https\://localhost\:8444/[email protected]
		// server.https\://localhost\:8444/.password=*******

		Properties properties = new Properties();
		String serverPrefix = String.format("server.%s.", getServer());
		properties.put(serverPrefix + "password", getPassword());
		properties.put(serverPrefix + "email", getUsername());
		properties.put("projectName", getProjectName());
		properties.put("serverUrl", getServer());
		return properties;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy