Allow data directory to be configured using a command-line parameter.
This commit is contained in:
parent
63f8b3a74e
commit
98a7b6d6d6
@ -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>
|
11
Plugins/.idea/libraries/commons_cli_1_3_1.xml
Normal file
11
Plugins/.idea/libraries/commons_cli_1_3_1.xml
Normal 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>
|
BIN
Plugins/Libraries/commons-cli-1.3.1.jar
Normal file
BIN
Plugins/Libraries/commons-cli-1.3.1.jar
Normal file
Binary file not shown.
@ -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>
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user