diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java index 23a9dd4d3..af74332a1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java @@ -3,6 +3,8 @@ package edu.cornell.mannlib.vitro.webapp.search.controller; import java.io.IOException; +import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -140,9 +142,29 @@ public class IndexController extends FreemarkerHttpServlet { Map body) { WorkLevelStamp stamp = builder.getWorkLevel(); body.put("worklevel", stamp.getLevel().toString()); + body.put("currentTask", figureCurrentTask(stamp.getFlags())); body.put("since", stamp.getSince()); + body.put("elapsed", formatElapsedTime(stamp.getSince())); body.put("hasPreviousBuild", stamp.getSince().getTime() > 0L); return new TemplateResponseValues(TEMPLATE_NAME, body); } + private String formatElapsedTime(Date since) { + long elapsedMillis = System.currentTimeMillis() - since.getTime(); + long seconds = (elapsedMillis / 1000L) % 60L; + long minutes = (elapsedMillis / 60000L) % 60L; + long hours = elapsedMillis / 3600000L; + return String.format("%02d:%02d:%02d", hours, minutes, seconds); + } + + private String figureCurrentTask(Collection flags) { + if (flags.contains(IndexBuilder.FLAG_REBUILDING)) { + return "rebuilt"; + } else if (flags.contains(IndexBuilder.FLAG_UPDATING)) { + return "updated"; + } else { + return ""; + } + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index a59500997..9a1edcda5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -64,6 +64,12 @@ public class IndexBuilder extends VitroBackgroundThread { /** Length of pause between when work comes into queue to when indexing starts */ public static final long WAIT_AFTER_NEW_WORK_INTERVAL = 500; //msec + /** Flag so we can tell that the index is being updated. */ + public static final String FLAG_UPDATING = "updating"; + + /** Flag so we can tell that the index is being rebuilt. */ + public static final String FLAG_REBUILDING = "rebuilding"; + /** Number of threads to use during indexing. */ protected int numberOfThreads = 10; @@ -152,12 +158,12 @@ public class IndexBuilder extends VitroBackgroundThread { while(! stopRequested ){ try{ if( reindexRequested ){ - setWorkLevel(WorkLevel.WORKING); + setWorkLevel(WorkLevel.WORKING, FLAG_REBUILDING); log.debug("full re-index requested"); indexRebuild(); setWorkLevel(WorkLevel.IDLE); }else if( !changedStmtQueue.isEmpty() ){ - setWorkLevel(WorkLevel.WORKING); + setWorkLevel(WorkLevel.WORKING, FLAG_UPDATING); Thread.sleep(WAIT_AFTER_NEW_WORK_INTERVAL); //wait a bit to let a bit more work to come into the queue log.debug("work found for IndexBuilder, starting update"); updatedIndex(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java index eb69092fc..bebd50ec0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java @@ -4,6 +4,9 @@ package edu.cornell.mannlib.vitro.webapp.utils.threads; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; @@ -47,9 +50,10 @@ public class VitroBackgroundThread extends Thread { allThreads.add(new WeakReference(this)); } - protected void setWorkLevel(WorkLevel level) { - log.debug("Set work level on '" + this.getName() + "' to " + level); - stamp = new WorkLevelStamp(level); + protected void setWorkLevel(WorkLevel level, String... flags) { + log.debug("Set work level on '" + this.getName() + "' to " + level + + ", flags=" + flags); + stamp = new WorkLevelStamp(level, flags); } public WorkLevelStamp getWorkLevel() { @@ -59,14 +63,19 @@ public class VitroBackgroundThread extends Thread { /** * An immutable object that holds both the current work level and the time * that it was set. + * + * Particular threads may want to assign additional state using zero or more + * "flags". */ public static class WorkLevelStamp { private final WorkLevel level; private final long since; + private final List flags; - public WorkLevelStamp(WorkLevel level) { + public WorkLevelStamp(WorkLevel level, String... flags) { this.level = level; this.since = System.currentTimeMillis(); + this.flags = Collections.unmodifiableList(Arrays.asList(flags)); } public WorkLevel getLevel() { @@ -76,5 +85,9 @@ public class VitroBackgroundThread extends Thread { public Date getSince() { return new Date(since); } + + public Collection getFlags() { + return flags; + } } } diff --git a/webapp/web/templates/freemarker/body/admin/searchIndex.ftl b/webapp/web/templates/freemarker/body/admin/searchIndex.ftl index 6dbac6070..232c28d73 100644 --- a/webapp/web/templates/freemarker/body/admin/searchIndex.ftl +++ b/webapp/web/templates/freemarker/body/admin/searchIndex.ftl @@ -4,7 +4,7 @@ Template for the page that controls the updating or rebuilding of the Search Index. --> -

Search Index Status

+

Search Index Status

<#if worklevel == "IDLE"> <#if hasPreviousBuild??> @@ -12,12 +12,16 @@
- - Add the latest changes to the index. -
- - Start with an empty index and build it completely. +

+ + Add the latest changes to the index. +

+

+ + Start with an empty index and build it completely. +

<#else> -

Active since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}

+

The search index is currently being ${currentTask}.

+

since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}