NIHVIVO-2873 (have threads pay attention to shutdown state)
This commit is contained in:
parent
bc7164bc55
commit
999659dbcf
5 changed files with 41 additions and 27 deletions
|
@ -302,7 +302,8 @@ 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.isSimpleReasonerSetupComplete(getServletContext())) {
|
SimpleReasoner simpleReasoner = (SimpleReasoner) getServletContext().getAttribute(SimpleReasoner.class.getName());
|
||||||
|
if (customTemplate == null && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
||||||
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,13 +32,14 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
String messageStr = "";
|
String messageStr = "";
|
||||||
try {
|
try {
|
||||||
if (!SimpleReasoner.isSimpleReasonerSetupComplete(vreq.getSession().getServletContext())) {
|
|
||||||
|
Object simpleReasoner = vreq.getSession().getServletContext().getAttribute(SimpleReasoner.class.getName());
|
||||||
|
|
||||||
|
if ((simpleReasoner instanceof SimpleReasoner) && !((SimpleReasoner)simpleReasoner).isABoxReasoningAsynchronous()) {
|
||||||
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");
|
||||||
|
|
||||||
Object simpleReasoner = vreq.getSession().getServletContext().getAttribute(SimpleReasoner.class.getName());
|
|
||||||
|
|
||||||
if (simpleReasoner instanceof SimpleReasoner) {
|
if (simpleReasoner instanceof SimpleReasoner) {
|
||||||
|
|
||||||
if (((SimpleReasoner)simpleReasoner).isRecomputing()) {
|
if (((SimpleReasoner)simpleReasoner).isRecomputing()) {
|
||||||
|
|
|
@ -62,8 +62,8 @@ 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 = false, batchMode2 = false;
|
||||||
private boolean stopRequested;
|
private boolean stopRequested = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||||
|
@ -1158,7 +1158,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception while recomputing ABox inference model", e);
|
log.error("Exception while computing mostSpecificType annotations", e);
|
||||||
inferenceRebuildModel.removeAll(); // don't do this in the finally, it's needed in the case
|
inferenceRebuildModel.removeAll(); // don't do this in the finally, it's needed in the case
|
||||||
// where there isn't an exception
|
// where there isn't an exception
|
||||||
return;
|
return;
|
||||||
|
@ -1227,14 +1227,12 @@ 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 boolean isSimpleReasonerSetupComplete(ServletContext ctx) {
|
public boolean isABoxReasoningAsynchronous() {
|
||||||
Object string = ctx.getAttribute("SimpleReasonerSetupState");
|
if (batchMode1 || batchMode2) {
|
||||||
|
return true;
|
||||||
if (string instanceof String) {
|
} else {
|
||||||
return true;
|
return false;
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1271,25 +1269,31 @@ public class SimpleReasoner extends StatementListener {
|
||||||
log.info("starting DeltaComputer.run");
|
log.info("starting DeltaComputer.run");
|
||||||
Model retractions = aBoxDeltaModeler1.getRetractions();
|
Model retractions = aBoxDeltaModeler1.getRetractions();
|
||||||
boolean finished = (retractions.size() == 0);
|
boolean finished = (retractions.size() == 0);
|
||||||
|
boolean abort = false;
|
||||||
String qualifier = "(1)";
|
String qualifier = "(1)";
|
||||||
|
|
||||||
while (!finished && !stopRequested) {
|
while (!finished && !stopRequested) {
|
||||||
retractions.enterCriticalSection(Lock.READ);
|
retractions.enterCriticalSection(Lock.READ);
|
||||||
|
StmtIterator iter = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("run: started computing inferences for batch " + qualifier + " update");
|
log.info("run: started computing inferences for batch " + qualifier + " update");
|
||||||
StmtIterator iter = retractions.listStatements();
|
iter = retractions.listStatements();
|
||||||
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext() && !stopRequested) {
|
||||||
Statement stmt = iter.next();
|
Statement stmt = iter.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
removedABoxTypeAssertion(stmt, inferenceModel);
|
removedABoxTypeAssertion(stmt, inferenceModel);
|
||||||
setMostSpecificTypes(stmt.getSubject(), inferenceModel, new HashSet<String>());
|
setMostSpecificTypes(stmt.getSubject(), inferenceModel, new HashSet<String>());
|
||||||
//TODO update this part when subproperty inferencing is added.
|
//TODO update this part when subproperty inferencing is added.
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
abort = true;
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("exception while computing inferences for batch " + qualifier + " update: " + e.getMessage());
|
log.error("exception in batch mode ",e);
|
||||||
|
//log.error("exception while computing inferences for batch " + qualifier + " update: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
num++;
|
num++;
|
||||||
|
@ -1303,12 +1307,23 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
iter.close();
|
||||||
retractions.removeAll();
|
retractions.removeAll();
|
||||||
retractions.leaveCriticalSection();
|
retractions.leaveCriticalSection();
|
||||||
log.info("finished computing inferences for batch " + qualifier + " update");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (abort) {
|
||||||
|
log.info("a NullPointerException was received while computing inferences in batch " + qualifier + " mode. Halting inference computation.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stopRequested) {
|
||||||
|
log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("finished computing inferences for batch " + qualifier + " update");
|
||||||
|
|
||||||
if (batchMode1 && (aBoxDeltaModeler2.getRetractions().size() > 0)) {
|
if (batchMode1 && (aBoxDeltaModeler2.getRetractions().size() > 0)) {
|
||||||
retractions = aBoxDeltaModeler2.getRetractions();
|
retractions = aBoxDeltaModeler2.getRetractions();
|
||||||
batchMode2 = true;
|
batchMode2 = true;
|
||||||
|
@ -1327,11 +1342,6 @@ 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) {
|
||||||
|
@ -1356,7 +1366,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* This is called when the system shuts down.
|
* This is called when the system shuts down.
|
||||||
*/
|
*/
|
||||||
public void setStopRequested() {
|
public void setStopRequested() {
|
||||||
stopRequested = true;
|
this.stopRequested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stmtString(Statement statement) {
|
public static String stmtString(Statement statement) {
|
||||||
|
|
|
@ -127,7 +127,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
||||||
sce.getServletContext().setAttribute("SimpleReasonerSetupState","complete");
|
|
||||||
|
|
||||||
log.info("Simple reasoner connected for the ABox");
|
log.info("Simple reasoner connected for the ABox");
|
||||||
|
|
||||||
|
@ -138,9 +137,11 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
log.info("received contextDestroyed notification");
|
||||||
SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
|
SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
|
||||||
|
|
||||||
if (simpleReasoner != null) {
|
if (simpleReasoner != null) {
|
||||||
|
log.info("sending stop request to SimpleReasoner");
|
||||||
simpleReasoner.setStopRequested();
|
simpleReasoner.setStopRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,8 @@ 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.isSimpleReasonerSetupComplete(getServletContext())) {
|
SimpleReasoner simpleReasoner = (SimpleReasoner)getServletContext().getAttribute(SimpleReasoner.class.getName());
|
||||||
|
if (!isVClass && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
||||||
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