diff --git a/src/main/java/ch/dissem/bitmessage/server/CleanupJob.java b/src/main/java/ch/dissem/bitmessage/server/CleanupJob.java new file mode 100644 index 0000000..8b93cea --- /dev/null +++ b/src/main/java/ch/dissem/bitmessage/server/CleanupJob.java @@ -0,0 +1,28 @@ +package ch.dissem.bitmessage.server; + +import ch.dissem.bitmessage.BitmessageContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.TimerTask; + +/** + * Created by chrigu on 04.10.15. + */ +public class CleanupJob extends TimerTask { + private static final Logger LOG = LoggerFactory.getLogger(CleanupJob.class); + private final BitmessageContext ctx; + + public CleanupJob(BitmessageContext ctx) { + this.ctx = ctx; + } + + @Override + public void run() { + try { + ctx.cleanup(); + } catch (Throwable t) { + LOG.error("Problem while cleaning inventory", t); + } + } +} diff --git a/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java b/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java index e2af31d..18e5b46 100644 --- a/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java +++ b/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java @@ -41,10 +41,10 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.Timer; @CrossOrigin @RestController @@ -52,6 +52,8 @@ import java.util.Set; public class JabitServerApplication { private static final Logger LOG = LoggerFactory.getLogger(JabitServerApplication.class); + private static final long HOUR = 60 * 60 * 1000l; // in ms + private static final String CONFIG_FILE = "config.properties"; private static final String PROPERTY_PORT = "port"; @@ -145,9 +147,12 @@ public class JabitServerApplication { .networkHandler(new DefaultNetworkHandler()) .security(new BouncySecurity()) .port(port) + .listener(plaintext -> { + }) .build(); - ctx.startup(plaintext -> { - }); + ctx.startup(); + + new Timer().scheduleAtFixedRate(new CleanupJob(ctx), 1 * HOUR, 24 * HOUR); } public static void main(String[] args) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..5f53708 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +logging.file=jabit.log +logging.level.*=ERROR +logging.level.ch.dissem.*=WARN \ No newline at end of file