diff --git a/src/main/java/org/dataone/cn/indexer/IndexWorker.java b/src/main/java/org/dataone/cn/indexer/IndexWorker.java index cfc67ad0..d7a8b2c4 100644 --- a/src/main/java/org/dataone/cn/indexer/IndexWorker.java +++ b/src/main/java/org/dataone/cn/indexer/IndexWorker.java @@ -99,8 +99,7 @@ public class IndexWorker { private String specifiedThreadNumberStr = null; private int specifiedThreadNumber = 0; private ExecutorService executor = null; - private ScheduledExecutorService scheduler; - + /** * Commandline main for the IndexWorker to be started. * @param args @@ -114,6 +113,7 @@ public static void main(String[] args) throws IOException, TimeoutException, Ser loadExternalPropertiesFile(propertyFile); IndexWorker worker = new IndexWorker(); worker.start(); + startLivenessProbe(); } /** @@ -228,25 +228,9 @@ public IndexWorker(Boolean initialize) throws IOException, TimeoutException, Ser initIndexParsers(); ObjectManager.getInstance(); OntologyModelService.getInstance(); - startLivenessProbe(); } } - private void startLivenessProbe() { - scheduler = Executors.newScheduledThreadPool(1); - Runnable task = () -> { - Path path = Paths.get("./livenessprobe"); - try { - Files.createFile(path); - Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); - logger.info("IndexWorker.startLivenessProbe - starting livenessProbe"); - } catch (IOException e) { - logger.error("IndexWorker.startLivenessProbe - failed to touch file: " + path, e); - } - }; - scheduler.scheduleAtFixedRate(task, 0, 10, TimeUnit.SECONDS); - } - /** * Initialize the RabbitMQ service * @throws IOException @@ -379,7 +363,7 @@ public void run() { }; boolean autoAck = false; rabbitMQchannel.basicConsume(INDEX_QUEUE_NAME, autoAck, consumer); - logger.info("IndexWorker.start - Calling basicConsume and waiting for the comming messages"); + logger.info("IndexWorker.start - Calling basicConsume and waiting for the coming messages"); } /** @@ -496,6 +480,20 @@ private void indexOjbect(IndexQueueMessageParser parser, long deliveryTag, boole public void stop() throws IOException, TimeoutException { rabbitMQchannel.close(); rabbitMQconnection.close(); - logger.info("IndexWorker.stop - stop the index queue conection."); + logger.info("IndexWorker.stop - stop the index queue connection."); + } + + private static void startLivenessProbe() { + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + Path path = Paths.get("./livenessprobe"); + Runnable task = () -> { + try { + Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis())); + } catch (IOException e) { + logger.error("IndexWorker.startLivenessProbe - failed to update file: " + path, e); + } + }; + scheduler.scheduleAtFixedRate(task, 0, 10, TimeUnit.SECONDS); + logger.info("IndexWorker.startLivenessProbe - livenessProbe started"); } }