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