changing behavior of reasoning wrt migration
This commit is contained in:
parent
6dbd2faa8e
commit
500bb456c3
6 changed files with 70 additions and 46 deletions
|
@ -12,4 +12,6 @@ public interface ChangeRecord {
|
|||
|
||||
public void writeChanges();
|
||||
|
||||
public boolean hasRecordedChanges();
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class KnowledgeBaseUpdater {
|
|||
this.record = new SimpleChangeRecord(settings.getAddedDataFile(), settings.getRemovedDataFile());
|
||||
}
|
||||
|
||||
public void update(ServletContext servletContext) throws IOException {
|
||||
public boolean update(ServletContext servletContext) throws IOException {
|
||||
|
||||
if (this.logger == null) {
|
||||
this.logger = new SimpleChangeLogger(settings.getLogFile(), settings.getErrorLogFile());
|
||||
|
@ -85,7 +85,7 @@ public class KnowledgeBaseUpdater {
|
|||
long elapsedSecs = (System.currentTimeMillis() - startTime)/1000;
|
||||
log.info("Finished knowledge base migration in " + elapsedSecs + " second" + (elapsedSecs != 1 ? "s" : ""));
|
||||
|
||||
return;
|
||||
return record.hasRecordedChanges();
|
||||
}
|
||||
|
||||
private void performUpdate(ServletContext servletContext) throws Exception {
|
||||
|
|
|
@ -26,6 +26,9 @@ public class SimpleChangeRecord implements ChangeRecord {
|
|||
private File additionsFile;
|
||||
private File retractionsFile;
|
||||
|
||||
private int additionsCount = 0;
|
||||
private int retractionsCount = 0;
|
||||
|
||||
public SimpleChangeRecord(
|
||||
String additionsFile, String retractionsFile) {
|
||||
this.additionsFile = new File(additionsFile);
|
||||
|
@ -46,11 +49,12 @@ public class SimpleChangeRecord implements ChangeRecord {
|
|||
|
||||
public void recordAdditions(Model incrementalAdditions) {
|
||||
additionsModel.add(incrementalAdditions);
|
||||
|
||||
additionsCount += incrementalAdditions.size();
|
||||
}
|
||||
|
||||
public void recordRetractions(Model incrementalRetractions) {
|
||||
retractionsModel.add(incrementalRetractions);
|
||||
retractionsCount += incrementalRetractions.size();
|
||||
}
|
||||
|
||||
private void write(Model model, File file) {
|
||||
|
@ -72,4 +76,8 @@ public class SimpleChangeRecord implements ChangeRecord {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasRecordedChanges() {
|
||||
return additionsCount > 0 || retractionsCount > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,19 +110,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
}
|
||||
simpleReasoner.setPluginList(pluginList);
|
||||
|
||||
|
||||
if (isRecomputeRequired(sce.getServletContext())) {
|
||||
log.info("ABox inference recompute required.");
|
||||
waitForTBoxReasoning(pelletListener);
|
||||
if (JenaDataSourceSetupBase.isFirstStartup()) {
|
||||
simpleReasoner.recompute();
|
||||
} else {
|
||||
log.info("starting ABox inference recompute in a separate thread.");
|
||||
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecomputer").start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
||||
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
|
||||
assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener);
|
||||
|
@ -135,17 +122,21 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void waitForTBoxReasoning(PelletListener pelletListener)
|
||||
public static void waitForTBoxReasoning(ServletContextEvent sce)
|
||||
throws InterruptedException {
|
||||
int sleeps = 0;
|
||||
// sleep at least once to make sure the TBox reasoning gets started
|
||||
while ((0 == sleeps) || ((sleeps < 1000) && pelletListener.isReasoning())) {
|
||||
if ((sleeps % 10) == 0) { // print message at 10 second intervals
|
||||
log.info("Waiting for initial TBox reasoning to complete");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
sleeps++;
|
||||
}
|
||||
PelletListener pelletListener = (PelletListener) sce.getServletContext().getAttribute("pelletListener");
|
||||
if (pelletListener == null) {
|
||||
return ;
|
||||
}
|
||||
int sleeps = 0;
|
||||
// sleep at least once to make sure the TBox reasoning gets started
|
||||
while ((0 == sleeps) || ((sleeps < 1000) && pelletListener.isReasoning())) {
|
||||
if ((sleeps % 10) == 0) { // print message at 10 second intervals
|
||||
log.info("Waiting for initial TBox reasoning to complete");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
sleeps++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,7 +184,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
ctx.setAttribute(RECOMPUTE_REQUIRED_ATTR, true);
|
||||
}
|
||||
|
||||
private static boolean isRecomputeRequired(ServletContext ctx) {
|
||||
public static boolean isRecomputeRequired(ServletContext ctx) {
|
||||
return (ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR) != null);
|
||||
}
|
||||
|
||||
|
@ -208,19 +199,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
return (ctx.getAttribute(MSTCOMPUTE_REQUIRED_ATTR) != null);
|
||||
}
|
||||
|
||||
private class ABoxRecomputer implements Runnable {
|
||||
|
||||
private SimpleReasoner simpleReasoner;
|
||||
|
||||
public ABoxRecomputer(SimpleReasoner simpleReasoner) {
|
||||
this.simpleReasoner = simpleReasoner;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
simpleReasoner.recompute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the names of the plugin classes classes.
|
||||
*
|
||||
|
|
|
@ -41,9 +41,9 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
|
||||
import edu.cornell.mannlib.vitro.webapp.ontology.update.UpdateSettings;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.reasoner.ABoxRecomputer;
|
||||
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
|
||||
/**
|
||||
|
@ -76,11 +76,15 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
ServletContext ctx = sce.getServletContext();
|
||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||
|
||||
boolean migrationChangesMade = false;
|
||||
|
||||
try {
|
||||
UpdateSettings settings = new UpdateSettings();
|
||||
putReportingPathsIntoSettings(ctx, settings);
|
||||
putNonReportingPathsIntoSettings(ctx, settings);
|
||||
|
||||
SimpleReasonerSetup.waitForTBoxReasoning(sce);
|
||||
|
||||
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
||||
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
||||
settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getBaseOntModelSelector());
|
||||
|
@ -139,7 +143,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
} else {
|
||||
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
|
||||
log.info("Data migration required");
|
||||
ontologyUpdater.update(ctx);
|
||||
migrationChangesMade = ontologyUpdater.update(ctx);
|
||||
if (tryMigrateDisplay) {
|
||||
try {
|
||||
migrateDisplayModel(settings);
|
||||
|
@ -161,6 +165,38 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
} catch (Throwable t) {
|
||||
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", t);
|
||||
}
|
||||
|
||||
if (SimpleReasonerSetup.isRecomputeRequired(sce.getServletContext())) {
|
||||
log.info("ABox inference recompute required.");
|
||||
|
||||
SimpleReasoner simpleReasoner = (SimpleReasoner) sce.getServletContext()
|
||||
.getAttribute(SimpleReasoner.class.getName());
|
||||
if (simpleReasoner != null) {
|
||||
if (JenaDataSourceSetupBase.isFirstStartup() || migrationChangesMade) {
|
||||
simpleReasoner.recompute();
|
||||
} else {
|
||||
log.info("starting ABox inference recompute in a separate thread.");
|
||||
new Thread(
|
||||
new ABoxRecomputer(
|
||||
simpleReasoner),"ABoxRecomputer").start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ABoxRecomputer implements Runnable {
|
||||
|
||||
private SimpleReasoner simpleReasoner;
|
||||
|
||||
public ABoxRecomputer(SimpleReasoner simpleReasoner) {
|
||||
this.simpleReasoner = simpleReasoner;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
simpleReasoner.recompute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.UserModelSetup
|
|||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ModelMakerSetup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil$Setup
|
||||
|
@ -38,6 +36,8 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup
|
|||
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase
|
||||
|
||||
# Must run after JenaDataSourceSetup
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.ThemeInfoSetup
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue