minor log message tweaks
This commit is contained in:
parent
a5c0758371
commit
c7b6e7a75e
2 changed files with 215 additions and 218 deletions
|
@ -278,7 +278,10 @@ public class KnowledgeBaseUpdater {
|
||||||
required = true;
|
required = true;
|
||||||
if (JenaDataSourceSetupBase.isFirstStartup()) {
|
if (JenaDataSourceSetupBase.isFirstStartup()) {
|
||||||
assertSuccess();
|
assertSuccess();
|
||||||
log.info("The application is starting with an empty DB, an indication will be added to the DB that a knowledge base migration to the current version is not required.");
|
log.info("The application is starting with an empty database. " +
|
||||||
|
"An indication will be added to the database that a " +
|
||||||
|
"knowledge base migration to the current version is " +
|
||||||
|
"not required.");
|
||||||
required = false;
|
required = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,54 +35,54 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
public class SimpleReasonerSetup implements ServletContextListener {
|
public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(SimpleReasonerSetup.class.getName());
|
private static final Log log = LogFactory.getLog(SimpleReasonerSetup.class.getName());
|
||||||
|
|
||||||
public static final String FILE_OF_PLUGINS = "/WEB-INF/resources/reasoner_plugins.txt";
|
public static final String FILE_OF_PLUGINS = "/WEB-INF/resources/reasoner_plugins.txt";
|
||||||
|
|
||||||
// Models used during a full recompute of the ABox
|
// Models used during a full recompute of the ABox
|
||||||
static final String JENA_INF_MODEL_REBUILD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-rebuild";
|
static final String JENA_INF_MODEL_REBUILD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-rebuild";
|
||||||
static final String JENA_INF_MODEL_SCRATCHPAD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-scratchpad";
|
static final String JENA_INF_MODEL_SCRATCHPAD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-scratchpad";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
try {
|
try {
|
||||||
// set up Pellet reasoning for the TBox
|
// set up Pellet reasoning for the TBox
|
||||||
|
|
||||||
OntModelSelector assertionsOms = ModelContext.getBaseOntModelSelector(sce.getServletContext());
|
OntModelSelector assertionsOms = ModelContext.getBaseOntModelSelector(sce.getServletContext());
|
||||||
OntModelSelector inferencesOms = ModelContext.getInferenceOntModelSelector(sce.getServletContext());
|
OntModelSelector inferencesOms = ModelContext.getInferenceOntModelSelector(sce.getServletContext());
|
||||||
OntModelSelector unionOms = ModelContext.getUnionOntModelSelector(sce.getServletContext());
|
OntModelSelector unionOms = ModelContext.getUnionOntModelSelector(sce.getServletContext());
|
||||||
|
|
||||||
WebappDaoFactoryJena wadf = (WebappDaoFactoryJena) sce.getServletContext().getAttribute("webappDaoFactory");
|
WebappDaoFactoryJena wadf = (WebappDaoFactoryJena) sce.getServletContext().getAttribute("webappDaoFactory");
|
||||||
|
|
||||||
if (!assertionsOms.getTBoxModel().getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
|
if (!assertionsOms.getTBoxModel().getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
|
||||||
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");
|
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set various Pellet options for incremental consistency checking, etc.
|
// Set various Pellet options for incremental consistency checking, etc.
|
||||||
PelletOptions.DL_SAFE_RULES = true;
|
PelletOptions.DL_SAFE_RULES = true;
|
||||||
PelletOptions.USE_COMPLETION_QUEUE = true;
|
PelletOptions.USE_COMPLETION_QUEUE = true;
|
||||||
PelletOptions.USE_TRACING = true;
|
PelletOptions.USE_TRACING = true;
|
||||||
PelletOptions.TRACK_BRANCH_EFFECTS = true;
|
PelletOptions.TRACK_BRANCH_EFFECTS = true;
|
||||||
PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
||||||
PelletOptions.USE_INCREMENTAL_DELETION = true;
|
PelletOptions.USE_INCREMENTAL_DELETION = true;
|
||||||
|
|
||||||
PelletListener pelletListener = new PelletListener(unionOms.getTBoxModel(),assertionsOms.getTBoxModel(),inferencesOms.getTBoxModel(),ReasonerConfiguration.DEFAULT);
|
PelletListener pelletListener = new PelletListener(unionOms.getTBoxModel(),assertionsOms.getTBoxModel(),inferencesOms.getTBoxModel(),ReasonerConfiguration.DEFAULT);
|
||||||
sce.getServletContext().setAttribute("pelletListener",pelletListener);
|
sce.getServletContext().setAttribute("pelletListener",pelletListener);
|
||||||
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
|
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
|
||||||
|
|
||||||
if (wadf != null) {
|
if (wadf != null) {
|
||||||
wadf.setPelletListener(pelletListener);
|
wadf.setPelletListener(pelletListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Pellet reasoner connected for the TBox");
|
log.info("Pellet reasoner connected for the TBox");
|
||||||
|
|
||||||
// set up simple reasoning for the ABox
|
// set up simple reasoning for the ABox
|
||||||
|
|
||||||
ServletContext ctx = sce.getServletContext();
|
ServletContext ctx = sce.getServletContext();
|
||||||
BasicDataSource bds = JenaDataSourceSetupBase
|
BasicDataSource bds = JenaDataSourceSetupBase
|
||||||
.getApplicationDataSource(ctx);
|
.getApplicationDataSource(ctx);
|
||||||
String dbType = ConfigurationProperties.getBean(ctx).getProperty( // database type
|
String dbType = ConfigurationProperties.getBean(ctx).getProperty( // database type
|
||||||
"VitroConnection.DataSource.dbtype","MySQL");
|
"VitroConnection.DataSource.dbtype","MySQL");
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,129 +100,123 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
dbType, ctx);
|
dbType, ctx);
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
||||||
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
List<ReasonerPlugin> pluginList = new ArrayList<ReasonerPlugin>();
|
List<ReasonerPlugin> pluginList = new ArrayList<ReasonerPlugin>();
|
||||||
List<String> pluginClassnameList = this.readFileOfListeners(ctx);
|
List<String> pluginClassnameList = this.readFileOfListeners(ctx);
|
||||||
for (String classname : pluginClassnameList) {
|
for (String classname : pluginClassnameList) {
|
||||||
try {
|
try {
|
||||||
ReasonerPlugin plugin = (ReasonerPlugin) Class.forName(
|
ReasonerPlugin plugin = (ReasonerPlugin) Class.forName(
|
||||||
classname).getConstructors()[0].newInstance();
|
classname).getConstructors()[0].newInstance();
|
||||||
pluginList.add(plugin);
|
pluginList.add(plugin);
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
ss.info(this, "Could not instantiate reasoner plugin " + classname);
|
ss.info(this, "Could not instantiate reasoner plugin " + classname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
simpleReasoner.setPluginList(pluginList);
|
simpleReasoner.setPluginList(pluginList);
|
||||||
|
|
||||||
|
|
||||||
if (isRecomputeRequired(sce.getServletContext())) {
|
if (isRecomputeRequired(sce.getServletContext())) {
|
||||||
log.info("ABox inference recompute required.");
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
int sleeps = 0;
|
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
||||||
while (sleeps < 1000 && pelletListener.isReasoning()) {
|
log.info("mostSpecificType computation required. It will be done in a separate thread.");
|
||||||
if ((sleeps % 30) == 0) {
|
waitForTBoxReasoning(pelletListener);
|
||||||
log.info("Waiting for initial TBox reasoning to complete");
|
new Thread(new MostSpecificTypeRecomputer(simpleReasoner),"MostSpecificTypeComputer").start();
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
|
||||||
sleeps++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JenaDataSourceSetupBase.isFirstStartup()) {
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
||||||
simpleReasoner.recompute();
|
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
|
||||||
} else {
|
assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener);
|
||||||
log.info("starting ABox inference recompute in a separate thread.");
|
|
||||||
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecomputer").start();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
log.info("Simple reasoner connected for the ABox");
|
||||||
log.info("mostSpecificType computation required. It will be done in a separate thread.");
|
|
||||||
|
|
||||||
int sleeps = 0;
|
} catch (Throwable t) {
|
||||||
while (sleeps < 1000 && pelletListener.isReasoning()) {
|
t.printStackTrace();
|
||||||
if ((sleeps % 30) == 0) {
|
}
|
||||||
log.info("Waiting for initial TBox reasoning to complete");
|
}
|
||||||
}
|
|
||||||
Thread.sleep(100);
|
|
||||||
sleeps++;
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread(new MostSpecificTypeRecomputer(simpleReasoner),"MostSpecificTypeComputer").start();
|
private void waitForTBoxReasoning(PelletListener pelletListener)
|
||||||
}
|
throws InterruptedException {
|
||||||
|
int sleeps = 0;
|
||||||
|
while (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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
@Override
|
||||||
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener);
|
log.info("received contextDestroyed notification");
|
||||||
|
|
||||||
log.info("Simple reasoner connected for the ABox");
|
SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
|
||||||
|
if (simpleReasoner != null) {
|
||||||
|
log.info("sending stop request to SimpleReasoner");
|
||||||
|
simpleReasoner.setStopRequested();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Throwable t) {
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getSimpleReasonerTBoxListenerFromContext(sce.getServletContext());
|
||||||
t.printStackTrace();
|
if (simpleReasonerTBoxListener != null) {
|
||||||
}
|
log.info("sending stop request to simpleReasonerTBoxListener");
|
||||||
}
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
|
||||||
log.info("received contextDestroyed notification");
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
|
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
||||||
if (simpleReasoner != null) {
|
Object simpleReasoner = ctx.getAttribute(SimpleReasoner.class.getName());
|
||||||
log.info("sending stop request to SimpleReasoner");
|
|
||||||
simpleReasoner.setStopRequested();
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getSimpleReasonerTBoxListenerFromContext(sce.getServletContext());
|
if (simpleReasoner instanceof SimpleReasoner) {
|
||||||
if (simpleReasonerTBoxListener != null) {
|
return (SimpleReasoner) simpleReasoner;
|
||||||
log.info("sending stop request to simpleReasonerTBoxListener");
|
} else {
|
||||||
simpleReasonerTBoxListener.setStopRequested();
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public static SimpleReasonerTBoxListener getSimpleReasonerTBoxListenerFromContext(ServletContext ctx) {
|
||||||
|
Object simpleReasonerTBoxListener = ctx.getAttribute(SimpleReasonerTBoxListener.class.getName());
|
||||||
|
|
||||||
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
if (simpleReasonerTBoxListener instanceof SimpleReasonerTBoxListener) {
|
||||||
Object simpleReasoner = ctx.getAttribute(SimpleReasoner.class.getName());
|
return (SimpleReasonerTBoxListener) simpleReasonerTBoxListener;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (simpleReasoner instanceof SimpleReasoner) {
|
private static final String RECOMPUTE_REQUIRED_ATTR =
|
||||||
return (SimpleReasoner) simpleReasoner;
|
SimpleReasonerSetup.class.getName() + ".recomputeRequired";
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SimpleReasonerTBoxListener getSimpleReasonerTBoxListenerFromContext(ServletContext ctx) {
|
public static void setRecomputeRequired(ServletContext ctx) {
|
||||||
Object simpleReasonerTBoxListener = ctx.getAttribute(SimpleReasonerTBoxListener.class.getName());
|
ctx.setAttribute(RECOMPUTE_REQUIRED_ATTR, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (simpleReasonerTBoxListener instanceof SimpleReasonerTBoxListener) {
|
private static boolean isRecomputeRequired(ServletContext ctx) {
|
||||||
return (SimpleReasonerTBoxListener) simpleReasonerTBoxListener;
|
return (ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR) != null);
|
||||||
} else {
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String RECOMPUTE_REQUIRED_ATTR =
|
private static final String MSTCOMPUTE_REQUIRED_ATTR =
|
||||||
SimpleReasonerSetup.class.getName() + ".recomputeRequired";
|
|
||||||
|
|
||||||
public static void setRecomputeRequired(ServletContext ctx) {
|
|
||||||
ctx.setAttribute(RECOMPUTE_REQUIRED_ATTR, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isRecomputeRequired(ServletContext ctx) {
|
|
||||||
return (ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR) != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String MSTCOMPUTE_REQUIRED_ATTR =
|
|
||||||
SimpleReasonerSetup.class.getName() + ".MSTComputeRequired";
|
SimpleReasonerSetup.class.getName() + ".MSTComputeRequired";
|
||||||
|
|
||||||
public static void setMSTComputeRequired(ServletContext ctx) {
|
public static void setMSTComputeRequired(ServletContext ctx) {
|
||||||
ctx.setAttribute(MSTCOMPUTE_REQUIRED_ATTR, true);
|
ctx.setAttribute(MSTCOMPUTE_REQUIRED_ATTR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isMSTComputeRequired(ServletContext ctx) {
|
private static boolean isMSTComputeRequired(ServletContext ctx) {
|
||||||
return (ctx.getAttribute(MSTCOMPUTE_REQUIRED_ATTR) != null);
|
return (ctx.getAttribute(MSTCOMPUTE_REQUIRED_ATTR) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ABoxRecomputer implements Runnable {
|
private class ABoxRecomputer implements Runnable {
|
||||||
|
|
||||||
|
@ -246,58 +240,58 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
simpleReasoner.computeMostSpecificType();
|
simpleReasoner.computeMostSpecificType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the names of the plugin classes classes.
|
* Read the names of the plugin classes classes.
|
||||||
*
|
*
|
||||||
* If there is a problem, set a fatal error, and return an empty list.
|
* If there is a problem, set a fatal error, and return an empty list.
|
||||||
*/
|
*/
|
||||||
private List<String> readFileOfListeners(ServletContext ctx) {
|
private List<String> readFileOfListeners(ServletContext ctx) {
|
||||||
List<String> list = new ArrayList<String>();
|
List<String> list = new ArrayList<String>();
|
||||||
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
try {
|
try {
|
||||||
is = ctx.getResourceAsStream(FILE_OF_PLUGINS);
|
is = ctx.getResourceAsStream(FILE_OF_PLUGINS);
|
||||||
br = new BufferedReader(new InputStreamReader(is));
|
br = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while (null != (line = br.readLine())) {
|
while (null != (line = br.readLine())) {
|
||||||
String trimmed = line.trim();
|
String trimmed = line.trim();
|
||||||
if (!trimmed.isEmpty() && !trimmed.startsWith("#")) {
|
if (!trimmed.isEmpty() && !trimmed.startsWith("#")) {
|
||||||
list.add(trimmed);
|
list.add(trimmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// ignore the lack of file
|
// ignore the lack of file
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
ss.fatal(this,
|
ss.fatal(this,
|
||||||
"Failed while processing the list of startup listeners: "
|
"Failed while processing the list of startup listeners: "
|
||||||
+ FILE_OF_PLUGINS, e);
|
+ FILE_OF_PLUGINS, e);
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
try {
|
try {
|
||||||
is.close();
|
is.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Classnames of reasoner plugins = " + list);
|
log.debug("Classnames of reasoner plugins = " + list);
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue