2015-03-25 23:10:59 +01:00
|
|
|
package mineplex.chestConverter;
|
|
|
|
|
2015-05-17 10:28:44 +02:00
|
|
|
import java.io.IOException;
|
2015-03-25 23:10:59 +01:00
|
|
|
import java.text.SimpleDateFormat;
|
2015-05-13 09:00:37 +02:00
|
|
|
import java.util.ArrayList;
|
2015-03-25 23:10:59 +01:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
2015-05-13 09:00:37 +02:00
|
|
|
import java.util.List;
|
2015-05-17 10:28:44 +02:00
|
|
|
import java.util.logging.FileHandler;
|
|
|
|
import java.util.logging.Formatter;
|
|
|
|
import java.util.logging.LogRecord;
|
2015-03-25 23:10:59 +01:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
public class ChestConverter
|
|
|
|
{
|
|
|
|
private static ChestConverterRepository _repository = null;
|
|
|
|
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
|
|
|
|
2015-05-17 10:28:44 +02:00
|
|
|
private static Logger _logger = Logger.getLogger("Converter");
|
|
|
|
|
2015-03-25 23:10:59 +01:00
|
|
|
public static void main (String args[])
|
|
|
|
{
|
2015-05-17 10:28:44 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FileHandler fileHandler = new FileHandler("converter.log", true);
|
|
|
|
fileHandler.setFormatter(new Formatter()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public String format(LogRecord record)
|
|
|
|
{
|
|
|
|
return record.getMessage() + "\n";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_logger.addHandler(fileHandler);
|
|
|
|
_logger.setUseParentHandlers(false);
|
|
|
|
}
|
|
|
|
catch (SecurityException | IOException e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2015-03-25 23:10:59 +01:00
|
|
|
_repository = new ChestConverterRepository();
|
2015-05-22 23:33:25 +02:00
|
|
|
int lastId = 18279475;
|
2015-05-17 10:28:44 +02:00
|
|
|
int count = 50000;
|
|
|
|
int numOfRowsProcessed = lastId;
|
2015-05-13 09:00:37 +02:00
|
|
|
|
|
|
|
HashMap<String, Integer> tasks = _repository.getTaskList();
|
2015-03-25 23:10:59 +01:00
|
|
|
|
2015-05-17 10:28:44 +02:00
|
|
|
try
|
2015-03-25 23:10:59 +01:00
|
|
|
{
|
2015-05-17 10:28:44 +02:00
|
|
|
while (true)
|
2015-05-13 09:00:37 +02:00
|
|
|
{
|
2015-05-17 10:28:44 +02:00
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
HashMap<String, List<Integer>> playerMap = new HashMap<String, List<Integer>>();
|
2015-05-13 09:00:37 +02:00
|
|
|
|
2015-05-17 10:28:44 +02:00
|
|
|
|
|
|
|
List<AccountTask> taskList = _repository.getTasks(lastId, count);
|
|
|
|
|
|
|
|
if (taskList != null && taskList.size() > 0)
|
|
|
|
{
|
|
|
|
for (AccountTask task : taskList)
|
|
|
|
{
|
|
|
|
if (!playerMap.containsKey(task.UUID))
|
|
|
|
playerMap.put(task.UUID, new ArrayList<Integer>());
|
|
|
|
|
|
|
|
playerMap.get(task.UUID).add(tasks.get(task.Task));
|
|
|
|
|
|
|
|
if (task.Id > lastId)
|
|
|
|
lastId = task.Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
_repository.incrementClients(playerMap);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
numOfRowsProcessed += count;
|
|
|
|
log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds. Count = " + + numOfRowsProcessed);
|
|
|
|
Thread.sleep(100);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (numOfRowsProcessed > 17000000)
|
|
|
|
{
|
|
|
|
System.out.println("Count : " + numOfRowsProcessed);
|
|
|
|
_logger.info("Count : " + numOfRowsProcessed);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println("No greater than 17 mil");
|
|
|
|
_logger.info("No greater than 17 mil");
|
|
|
|
System.out.println("Count : " + numOfRowsProcessed);
|
|
|
|
_logger.info("Count : " + numOfRowsProcessed);
|
|
|
|
}
|
2015-03-25 23:10:59 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-17 10:28:44 +02:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_logger.info(e.getMessage());
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
System.out.println("Count : " + numOfRowsProcessed);
|
|
|
|
_logger.info("Count : " + numOfRowsProcessed);
|
|
|
|
}
|
2015-03-25 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void log(String message)
|
|
|
|
{
|
|
|
|
System.out.println("[" + _dateFormat.format(new Date()) + "] " + message);
|
|
|
|
}
|
|
|
|
}
|