Allow data directory to be configured using a command-line parameter.

This commit is contained in:
Keir 2016-01-07 04:40:39 +00:00
parent 63f8b3a74e
commit 98a7b6d6d6
5 changed files with 52 additions and 6 deletions

View File

@ -7,6 +7,7 @@
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/gson-2.2.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-pool2-2.2.jar" path-in-jar="/" />
<element id="module-output" name="Mineplex.ServerData" />
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-cli-1.3.1.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="commons-cli-1.3.1">
<CLASSES>
<root url="jar://$PROJECT_DIR$/Libraries/commons-cli-1.3.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.ideaLibSources/commons-cli-1.3.1-sources.jar!/" />
</SOURCES>
</library>
</component>

Binary file not shown.

View File

@ -9,6 +9,7 @@
<orderEntry type="library" name="jedis" level="project" />
<orderEntry type="library" name="gson" level="project" />
<orderEntry type="library" name="commons-pool2" level="project" />
<orderEntry type="library" name="commons-cli-1.3.1" level="project" />
<orderEntry type="module" module-name="Mineplex.ServerData" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

View File

@ -4,14 +4,19 @@ import java.io.File;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* @author iKeirNez
@ -25,18 +30,46 @@ public class ReportServer
{
Logger logger = Logger.getLogger("ReportServer");
logger.info("Starting report server.");
new ReportServer(Utility.generatePool(ServerManager.getMasterConnection()), logger);
Options options = new Options();
Option dirOption = Option.builder("dataDir")
.hasArg()
.longOpt("dataDirectory")
.desc("Sets the data directory where the JSON files will be stored.")
.type(File.class)
.build();
options.addOption(dirOption);
try
{
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
File dataDirectory = (File) cmd.getParsedOptionValue(dirOption.getOpt());
if (dataDirectory == null)
{
dataDirectory = new File("data");
}
new ReportServer(Utility.generatePool(ServerManager.getMasterConnection()), dataDirectory, logger);
}
catch (ParseException e)
{
logger.log(Level.SEVERE, "Failed to parse arguments.", e);
}
}
private JedisPool _jedisPool;
private File _dataDirectory;
private Logger _logger;
private ScheduledExecutorService _executorService = Executors.newScheduledThreadPool(1);
private File _dataDirectory = new File("data");
public ReportServer(JedisPool jedisPool, Logger logger)
public ReportServer(JedisPool jedisPool, File dataDirectory, Logger logger)
{
_jedisPool = jedisPool;
_dataDirectory = dataDirectory;
_logger = logger;
if (_dataDirectory.exists() && !_dataDirectory.isDirectory())