Delete old history

This commit is contained in:
Jesse Boyd 2016-04-20 10:06:35 +10:00
parent 01d5601b5b
commit bdec0b7ef4
3 changed files with 41 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.general.PlotSquaredFeature;
import com.boydti.fawe.util.Lag;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
@ -43,6 +44,7 @@ import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import javax.management.InstanceAlreadyExistsException;
import javax.management.Notification;
import javax.management.NotificationEmitter;
@ -143,12 +145,13 @@ public class Fawe {
private Fawe(final IFawe implementation) {
this.IMP = implementation;
this.thread = Thread.currentThread();
/*
* Implementation dependent stuff
*/
this.setupConfigs();
MainUtil.deleteOlder(new File(IMP.getDirectory(), "history"), TimeUnit.DAYS.toMillis(Settings.DELETE_HISTORY_AFTER_DAYS));
this.setupCommands();
// TODO command event - queue?

View File

@ -21,6 +21,7 @@ public class Settings {
public static long MEM_FREE = 95;
public static boolean ENABLE_HARD_LIMIT = true;
public static boolean STORE_HISTORY_ON_DISK = false;
public static int DELETE_HISTORY_AFTER_DAYS = 7;
public static int COMPRESSION_LEVEL = 0;
public static int BUFFER_SIZE = 531441;
public static boolean METRICS = true;
@ -79,6 +80,7 @@ public class Settings {
options.put("history.compress", false);
options.put("history.chunk-wait-ms", CHUNK_WAIT);
options.put("history.buffer-size", BUFFER_SIZE);
options.put("history.delete-after-days", DELETE_HISTORY_AFTER_DAYS);
options.put("region-restrictions", REGION_RESTRICTIONS);
options.put("queue.extra-time-ms", ALLOCATE);
options.put("queue.target-size", QUEUE_SIZE);
@ -112,6 +114,7 @@ public class Settings {
REGION_RESTRICTIONS = config.getBoolean("region-restrictions");
METRICS = config.getBoolean("metrics");
COMPRESSION_LEVEL = config.getInt("history.compression-level", config.getBoolean("history.compress") ? 1 : 0);
DELETE_HISTORY_AFTER_DAYS = config.getInt("history.delete-after-days");
BUFFER_SIZE = config.getInt("history.buffer-size", BUFFER_SIZE);
CHUNK_WAIT = config.getInt("history.chunk-wait-ms");
ALLOCATE = config.getInt("queue.extra-time-ms");

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.util;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.EndTag;
import com.sk89q.jnbt.ListTag;
@ -33,16 +34,47 @@ public class MainUtil {
}
Fawe.debug(s);
}
public static void iterateFiles(File directory, RunnableVal<File> task) {
if (directory.exists()) {
File[] files = directory.listFiles();
if (null != files) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
iterateFiles(files[i], task);
} else {
task.run(files[i]);
}
}
}
}
}
public static void deleteOlder(File directory, final long timeDiff) {
final long now = System.currentTimeMillis();
iterateFiles(directory, new RunnableVal<File>() {
@Override
public void run(File file) {
long age = now - file.lastModified();
if (age > timeDiff) {
System.out.println("Deleting file: " + file);
file.delete();
}
}
});
}
public static boolean deleteDirectory(File directory) {
if (directory.exists()) {
File[] files = directory.listFiles();
if (null != files) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
File file = files[i];
if (file.isDirectory()) {
deleteDirectory(files[i]);
} else {
files[i].delete();
System.out.println("Deleting file: " + file);
file.delete();
}
}
}