NIHVIVO-2873 (threads in SimpleReasoner) (not completed yet)
This commit is contained in:
parent
ac769c7601
commit
756ced4996
5 changed files with 117 additions and 50 deletions
|
@ -302,7 +302,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
// If still no custom template defined, and inferencing is asynchronous (under RDB), check
|
// If still no custom template defined, and inferencing is asynchronous (under RDB), check
|
||||||
// the superclasses of the vclass for a custom template specification.
|
// the superclasses of the vclass for a custom template specification.
|
||||||
if (customTemplate == null && SimpleReasoner.isABoxReasoningAsynchronous(getServletContext())) {
|
if (customTemplate == null && SimpleReasoner.isSimpleReasonerSetupComplete(getServletContext())) {
|
||||||
log.debug("Checking superclasses for custom template specification because ABox reasoning is asynchronous");
|
log.debug("Checking superclasses for custom template specification because ABox reasoning is asynchronous");
|
||||||
for (VClass directVClass : directClasses) {
|
for (VClass directVClass : directClasses) {
|
||||||
VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
|
VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||||
|
|
|
@ -32,14 +32,16 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
String messageStr = "";
|
String messageStr = "";
|
||||||
try {
|
try {
|
||||||
SimpleReasoner simpleReasoner = SimpleReasoner
|
if (!SimpleReasoner.isSimpleReasonerSetupComplete(vreq.getSession().getServletContext())) {
|
||||||
.getSimpleReasonerFromServletContext(
|
|
||||||
vreq.getSession().getServletContext());
|
|
||||||
if (simpleReasoner == null) {
|
|
||||||
messageStr = "No SimpleReasoner has been set up.";
|
messageStr = "No SimpleReasoner has been set up.";
|
||||||
} else {
|
} else {
|
||||||
String signal = (String) vreq.getParameter("signal");
|
String signal = (String) vreq.getParameter("signal");
|
||||||
if (simpleReasoner.isRecomputing()) {
|
|
||||||
|
Object simpleReasoner = vreq.getSession().getServletContext().getAttribute(SimpleReasoner.class.getName());
|
||||||
|
|
||||||
|
if (simpleReasoner instanceof SimpleReasoner) {
|
||||||
|
|
||||||
|
if (((SimpleReasoner)simpleReasoner).isRecomputing()) {
|
||||||
messageStr =
|
messageStr =
|
||||||
"The SimpleReasoner is currently in the process of " +
|
"The SimpleReasoner is currently in the process of " +
|
||||||
"recomputing inferences.";
|
"recomputing inferences.";
|
||||||
|
@ -51,11 +53,14 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
|
||||||
getServletContext().setAttribute("restart", "yes");
|
getServletContext().setAttribute("restart", "yes");
|
||||||
}
|
}
|
||||||
else if(signal!=null && signal.equals("Recompute")){
|
else if(signal!=null && signal.equals("Recompute")){
|
||||||
new Thread(new Recomputer(simpleReasoner)).start();
|
new Thread(new Recomputer(((SimpleReasoner)simpleReasoner))).start();
|
||||||
messageStr = "Recomputation of inferences started";
|
messageStr = "Recomputation of inferences started";
|
||||||
getServletContext().setAttribute("restart", "showButton");
|
getServletContext().setAttribute("restart", "showButton");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.equals("The attribute with name " + SimpleReasoner.class.getName() + " is not an instance of SimpleReasoner");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
private CumulativeDeltaModeler aBoxDeltaModeler1 = null;
|
private CumulativeDeltaModeler aBoxDeltaModeler1 = null;
|
||||||
private CumulativeDeltaModeler aBoxDeltaModeler2 = null;
|
private CumulativeDeltaModeler aBoxDeltaModeler2 = null;
|
||||||
private boolean batchMode1, batchMode2;
|
private boolean batchMode1, batchMode2;
|
||||||
|
private boolean stopRequested;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||||
|
@ -82,6 +83,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
this.batchMode2 = false;
|
this.batchMode2 = false;
|
||||||
aBoxDeltaModeler1 = new CumulativeDeltaModeler();
|
aBoxDeltaModeler1 = new CumulativeDeltaModeler();
|
||||||
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
||||||
|
stopRequested = false;
|
||||||
|
|
||||||
aboxModel.getBaseModel().register(this);
|
aboxModel.getBaseModel().register(this);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +105,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
||||||
this.batchMode1 = false;
|
this.batchMode1 = false;
|
||||||
this.batchMode2 = false;
|
this.batchMode2 = false;
|
||||||
|
stopRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -964,6 +967,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((numStmts % 8000) == 0) {
|
if ((numStmts % 8000) == 0) {
|
||||||
log.info("Still computing class-based ABox inferences...");
|
log.info("Still computing class-based ABox inferences...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during recomputeABox. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1047,6 +1055,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((num % 8000) == 0) {
|
if ((num % 8000) == 0) {
|
||||||
log.info("Still updating ABox inference model (removing outdated inferences)...");
|
log.info("Still updating ABox inference model (removing outdated inferences)...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during recomputeABox. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
@ -1081,6 +1094,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((num % 8000) == 0) {
|
if ((num % 8000) == 0) {
|
||||||
log.info("Still updating ABox inference model (adding new inferences)...");
|
log.info("Still updating ABox inference model (adding new inferences)...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during recomputeABox. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
@ -1133,6 +1151,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((numStmts % 8000) == 0) {
|
if ((numStmts % 8000) == 0) {
|
||||||
log.info("Still computing mostSpecificType annotations...");
|
log.info("Still computing mostSpecificType annotations...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during recomputeMostSpecificType. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while recomputing ABox inference model", e);
|
log.error("Exception while recomputing ABox inference model", e);
|
||||||
|
@ -1174,6 +1197,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((numStmts % 8000) == 0) {
|
if ((numStmts % 8000) == 0) {
|
||||||
log.info("Still updating ABox inference model with mostSpecificType annotations...");
|
log.info("Still updating ABox inference model with mostSpecificType annotations...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during recomputeMostSpecificType. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
@ -1199,20 +1227,16 @@ public class SimpleReasoner extends StatementListener {
|
||||||
log.info("ABox inference model updated with mostSpecificType annotations");
|
log.info("ABox inference model updated with mostSpecificType annotations");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
public static boolean isSimpleReasonerSetupComplete(ServletContext ctx) {
|
||||||
Object simpleReasoner = ctx.getAttribute("simpleReasoner");
|
Object string = ctx.getAttribute("SimpleReasonerSetupState");
|
||||||
|
|
||||||
if (simpleReasoner instanceof SimpleReasoner) {
|
if (string instanceof String) {
|
||||||
return (SimpleReasoner) simpleReasoner;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isABoxReasoningAsynchronous(ServletContext ctx) {
|
|
||||||
return (getSimpleReasonerFromServletContext(ctx) == null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void notifyEvent(Model model, Object event) {
|
public synchronized void notifyEvent(Model model, Object event) {
|
||||||
|
|
||||||
|
@ -1232,7 +1256,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("received BulkUpdateEvent(end)");
|
log.info("received BulkUpdateEvent(end)");
|
||||||
new Thread(new DeltaComputer()).start();
|
new Thread(new DeltaComputer(),"DeltaComputer").start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1249,7 +1273,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
boolean finished = (retractions.size() == 0);
|
boolean finished = (retractions.size() == 0);
|
||||||
String qualifier = "(1)";
|
String qualifier = "(1)";
|
||||||
|
|
||||||
while (!finished) {
|
while (!finished && !stopRequested) {
|
||||||
retractions.enterCriticalSection(Lock.READ);
|
retractions.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1272,6 +1296,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if ((num % 6000) == 0) {
|
if ((num % 6000) == 0) {
|
||||||
log.info("still computing inferences for batch " + qualifier + " update...");
|
log.info("still computing inferences for batch " + qualifier + " update...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
retractions.removeAll();
|
retractions.removeAll();
|
||||||
|
@ -1298,6 +1327,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
batchMode2 = false;
|
batchMode2 = false;
|
||||||
log.info("finished processing retractions in batch mode");
|
log.info("finished processing retractions in batch mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aBoxDeltaModeler1.getRetractions().size() > 0) {
|
if (aBoxDeltaModeler1.getRetractions().size() > 0) {
|
||||||
|
@ -1318,6 +1352,13 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called when the system shuts down.
|
||||||
|
*/
|
||||||
|
public void setStopRequested() {
|
||||||
|
stopRequested = true;
|
||||||
|
}
|
||||||
|
|
||||||
public static String stmtString(Statement statement) {
|
public static String stmtString(Statement statement) {
|
||||||
return " [subject = " + statement.getSubject().getURI() +
|
return " [subject = " + statement.getSubject().getURI() +
|
||||||
"] [property = " + statement.getPredicate().getURI() +
|
"] [property = " + statement.getPredicate().getURI() +
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
// the simple reasoner will register itself as a listener to the ABox assertions
|
// the simple reasoner will register itself as a listener to the ABox assertions
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(unionOms.getTBoxModel(), assertionsOms.getABoxModel(), inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
SimpleReasoner simpleReasoner = new SimpleReasoner(unionOms.getTBoxModel(), assertionsOms.getABoxModel(), inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
||||||
|
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
||||||
|
|
||||||
if (isRecomputeRequired(sce.getServletContext())) {
|
if (isRecomputeRequired(sce.getServletContext())) {
|
||||||
log.info("ABox inference recompute required");
|
log.info("ABox inference recompute required");
|
||||||
|
@ -109,7 +110,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
sleeps++;
|
sleeps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new ABoxRecomputer(simpleReasoner,false)).start();
|
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecompuer").start();
|
||||||
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
||||||
log.info("mostSpecificType computation required");
|
log.info("mostSpecificType computation required");
|
||||||
|
|
||||||
|
@ -122,12 +123,11 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
sleeps++;
|
sleeps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new ABoxRecomputer(simpleReasoner,true)).start();
|
new Thread(new MostSpecificTypeRecomputer(simpleReasoner),"MostSpecificTypeComputer").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
||||||
|
sce.getServletContext().setAttribute("SimpleReasonerSetupState","complete");
|
||||||
sce.getServletContext().setAttribute("simpleReasoner",simpleReasoner);
|
|
||||||
|
|
||||||
log.info("Simple reasoner connected for the ABox");
|
log.info("Simple reasoner connected for the ABox");
|
||||||
|
|
||||||
|
@ -137,8 +137,22 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
// nothing to do
|
SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
|
||||||
|
|
||||||
|
if (simpleReasoner != null) {
|
||||||
|
simpleReasoner.setStopRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
||||||
|
Object simpleReasoner = ctx.getAttribute(SimpleReasoner.class.getName());
|
||||||
|
|
||||||
|
if (simpleReasoner instanceof SimpleReasoner) {
|
||||||
|
return (SimpleReasoner) simpleReasoner;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String RECOMPUTE_REQUIRED_ATTR =
|
private static final String RECOMPUTE_REQUIRED_ATTR =
|
||||||
|
@ -166,19 +180,26 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
private class ABoxRecomputer implements Runnable {
|
private class ABoxRecomputer implements Runnable {
|
||||||
|
|
||||||
private SimpleReasoner simpleReasoner;
|
private SimpleReasoner simpleReasoner;
|
||||||
private boolean justMST;
|
|
||||||
|
|
||||||
public ABoxRecomputer(SimpleReasoner simpleReasoner, boolean justMST) {
|
public ABoxRecomputer(SimpleReasoner simpleReasoner) {
|
||||||
this.simpleReasoner = simpleReasoner;
|
this.simpleReasoner = simpleReasoner;
|
||||||
this.justMST = justMST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (justMST) {
|
|
||||||
simpleReasoner.recomputeMostSpecificType();
|
|
||||||
} else {
|
|
||||||
simpleReasoner.recompute();
|
simpleReasoner.recompute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MostSpecificTypeRecomputer implements Runnable {
|
||||||
|
|
||||||
|
private SimpleReasoner simpleReasoner;
|
||||||
|
|
||||||
|
public MostSpecificTypeRecomputer(SimpleReasoner simpleReasoner) {
|
||||||
|
this.simpleReasoner = simpleReasoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
simpleReasoner.recomputeMostSpecificType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
boolean isVClass = individual.isVClass(vClassUri);
|
boolean isVClass = individual.isVClass(vClassUri);
|
||||||
// If reasoning is asynchronous (under RDB), this inference may not have been made yet.
|
// If reasoning is asynchronous (under RDB), this inference may not have been made yet.
|
||||||
// Check the superclasses of the individual's vclass.
|
// Check the superclasses of the individual's vclass.
|
||||||
if (!isVClass && SimpleReasoner.isABoxReasoningAsynchronous(getServletContext())) {
|
if (!isVClass && SimpleReasoner.isSimpleReasonerSetupComplete(getServletContext())) {
|
||||||
log.debug("Checking superclasses to see if individual is a " + vClassUri + " because reasoning is asynchronous");
|
log.debug("Checking superclasses to see if individual is a " + vClassUri + " because reasoning is asynchronous");
|
||||||
List<VClass> directVClasses = individual.getVClasses(true);
|
List<VClass> directVClasses = individual.getVClasses(true);
|
||||||
for (VClass directVClass : directVClasses) {
|
for (VClass directVClass : directVClasses) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue