allowing servlet context listeners to prevent other context listeners from running

This commit is contained in:
bjl23 2011-02-03 19:50:11 +00:00
parent cedbc8ff05
commit 3bfc823e41
22 changed files with 180 additions and 57 deletions

View file

@ -9,6 +9,8 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
/**
* Setups context so that Identifiers for Individuals associated with Users are
* added to requests.
@ -22,6 +24,11 @@ public class UserToIndIdentifierFactorySetup implements ServletContextListener{
private static final Log log = LogFactory.getLog(UserToIndIdentifierFactorySetup.class.getName());
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
ServletContext sc = sce.getServletContext();
ServletIdentifierBundleFactory
.addIdentifierBundleFactory(sc, new UserToIndIdentifierFactory());

View file

@ -11,6 +11,7 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import freemarker.template.Configuration;
@ -20,6 +21,10 @@ public class FreemarkerSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
ServletContext sc = event.getServletContext();
sc.setAttribute("themeToConfigMap", new HashMap<String, Configuration>());
BaseTemplateModel.setServletContext(sc);

View file

@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
/**
@ -68,6 +69,11 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
* created.
*/
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
ServletContext context = sce.getServletContext();

View file

@ -0,0 +1,25 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import javax.servlet.ServletContext;
public class AbortStartup {
private static final String ATTRIBUTE_NAME = AbortStartup.class.getName();
/**
* Sets a context attribute to prevent other context listeners from running.
*/
public static void abortStartup(ServletContext context) {
context.setAttribute(ATTRIBUTE_NAME, new Boolean(true));
}
/**
* Checks whether a previous context listener has caused startup to be aborted.
*/
public static boolean isStartupAborted(ServletContext context) {
return (context.getAttribute(ATTRIBUTE_NAME) != null);
}
}

View file

@ -42,6 +42,11 @@ public class AssembleModelsSetup implements ServletContextListener {
private String SYNTAX = "N3";
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
OntModel jenaOntModel = null;
try {
jenaOntModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");

View file

@ -28,6 +28,11 @@ public class AttachSubmodels implements ServletContextListener {
private static final Log log = LogFactory.getLog( AttachSubmodels.class );
public void contextInitialized( ServletContextEvent sce ) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
//FIXME refactor this

View file

@ -16,6 +16,10 @@ public class DefaultThemeSetup implements ServletContextListener {
// Set default theme based on themes present on the file system
public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
// Find the themes directory in the file system
ServletContext sc = event.getServletContext();
boolean doSort = true;

View file

@ -41,6 +41,10 @@ public class FileGraphSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
OntModelSelectorImpl baseOms = (OntModelSelectorImpl) sce.getServletContext().getAttribute("baseOntModelSelector");
Store kbStore = (Store) sce.getServletContext().getAttribute("kbStore");

View file

@ -25,6 +25,11 @@ public class HeapDefragement implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent arg0) {
if (AbortStartup.isStartupAborted(arg0.getServletContext())) {
return;
}
try{
log.info("Calling System.gc() to defragement the heap.");
long start = System.currentTimeMillis();

View file

@ -44,6 +44,11 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
private static final Log log = LogFactory.getLog(JenaDataSourceSetup.class.getName());
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
String tripleStoreTypeStr =

View file

@ -60,6 +60,11 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
private static final Log log = LogFactory.getLog(JenaDataSourceSetupSDB.class);
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
// JenaPersistentDataSourceSetup should have already set this up - it just sets

View file

@ -28,6 +28,10 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
Model dbModel;
OntModel memModel = ModelFactory.createOntologyModel(
this.DB_ONT_MODEL_SPEC);

View file

@ -13,6 +13,11 @@ import com.hp.hpl.jena.rdf.model.Model;
public class NamespacePrefixMapSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
HashMap<String,String> prefixToNamespace = new HashMap<String,String>();
HashMap<String,String> namespaceToPrefix = new HashMap<String,String>();
Model model = (Model) sce.getServletContext().getAttribute("jenaOntModel");

View file

@ -61,6 +61,11 @@ public class NightlyDefragement implements ServletContextListener, Runnable {
@Override
public void contextInitialized(ServletContextEvent arg0) {
if (AbortStartup.isStartupAborted(arg0.getServletContext())) {
return;
}
lastRun = new DateTime().minusHours( 400 );
if( nightlyDefragement != null ){
log.warn("NightlyDefragement listener has already been setup. Check your web.xml for duplicate listeners.");

View file

@ -26,6 +26,10 @@ public class PelletReasonerSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
//FIXME refactor this

View file

@ -21,36 +21,40 @@ public class PelletReasonerSetupComplete implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel");
if (!baseModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
log.error("Not connecting Pellet reasoner - base model is not an OWL model");
return;
}
// Set various options
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;
// Pellet 2.0-RC5 is buggy with incremental reasoning through Jena
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
//PelletOptions.USE_INCREMENTAL_DELETION = true;
ReasonerConfiguration config = ReasonerConfiguration.COMPLETE;
config.setIncrementalReasongingEnabled(false);
PelletListener pelletListener = new PelletListener(memoryModel,baseModel,inferenceModel,config);
sce.getServletContext().setAttribute("pelletListener",pelletListener);
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
log.debug("Reasoner connected");
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel");
if (!baseModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
log.error("Not connecting Pellet reasoner - base model is not an OWL model");
return;
}
// Set various options
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;
// Pellet 2.0-RC5 is buggy with incremental reasoning through Jena
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
//PelletOptions.USE_INCREMENTAL_DELETION = true;
ReasonerConfiguration config = ReasonerConfiguration.COMPLETE;
config.setIncrementalReasongingEnabled(false);
PelletListener pelletListener = new PelletListener(memoryModel,baseModel,inferenceModel,config);
sce.getServletContext().setAttribute("pelletListener",pelletListener);
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
log.debug("Reasoner connected");
} catch (Throwable t) {
t.printStackTrace();

View file

@ -21,37 +21,41 @@ public class PelletReasonerSetupPseudocomplete implements ServletContextListener
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel");
if (!baseModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
log.error("Not connecting Pellet reasoner - base model is not an OWL model");
return;
}
// Set various options
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;
// Pellet 2.0-RC5 is buggy with incremental reasoning through Jena
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
//PelletOptions.USE_INCREMENTAL_DELETION = true;
ReasonerConfiguration config = ReasonerConfiguration.PSEUDOCOMPLETE;
config.setIncrementalReasongingEnabled(false);
PelletListener pelletListener = new PelletListener(memoryModel,baseModel,inferenceModel,config);
sce.getServletContext().setAttribute("pelletListener",pelletListener);
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
log.debug("Reasoner connected");
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel");
if (!baseModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
log.error("Not connecting Pellet reasoner - base model is not an OWL model");
return;
}
// Set various options
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;
// Pellet 2.0-RC5 is buggy with incremental reasoning through Jena
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
//PelletOptions.USE_INCREMENTAL_DELETION = true;
ReasonerConfiguration config = ReasonerConfiguration.PSEUDOCOMPLETE;
config.setIncrementalReasongingEnabled(false);
PelletListener pelletListener = new PelletListener(memoryModel,baseModel,inferenceModel,config);
sce.getServletContext().setAttribute("pelletListener",pelletListener);
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
log.debug("Reasoner connected");
} catch (Throwable t) {
t.printStackTrace();
}

View file

@ -22,6 +22,10 @@ public class PelletReasonerSetupPseudocompleteIgnoreDataproperties implements
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");

View file

@ -42,6 +42,10 @@ public class RunSparqlConstructs implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
WebappDaoFactory wadf = (WebappDaoFactory) sce.getServletContext().getAttribute("webappDaoFactory");

View file

@ -47,6 +47,10 @@ public class SimpleReasonerSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
// set up Pellet reasoning for the TBox

View file

@ -65,6 +65,10 @@ public class UpdateKnowledgeBase implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
ServletContext ctx = sce.getServletContext();

View file

@ -48,6 +48,11 @@ public class UpdateUploadedFiles implements ServletContextListener {
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
ServletContext ctx = sce.getServletContext();