NIHVIVO-336 Modify the listeners to use StartupStatus instead of AbortStartup

This commit is contained in:
j2blake 2011-09-25 17:15:34 +00:00
parent a24e2b691c
commit 6cfd65efb7
31 changed files with 136 additions and 212 deletions

View file

@ -17,7 +17,7 @@ import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Load the initial configuration of PermissionSets and Permissions. * Load the initial configuration of PermissionSets and Permissions.
@ -38,10 +38,7 @@ public class PermissionSetsLoader implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
String ns = ConfigurationProperties.getBean(ctx).getProperty( String ns = ConfigurationProperties.getBean(ctx).getProperty(
@ -57,8 +54,7 @@ public class PermissionSetsLoader implements ServletContextListener {
wrapper.createPermissionSet(URI_DBA, "Site Admin"); wrapper.createPermissionSet(URI_DBA, "Site Admin");
} catch (Exception e) { } catch (Exception e) {
log.error("could not run PermissionSetsLoader" + e); log.error("could not run PermissionSetsLoader" + e);
AbortStartup.abortStartup(ctx); ss.fatal(this, "could not run PermissionSetsLoader" + e);
throw new RuntimeException(e);
} }
} }

View file

@ -21,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* If the user has an IsRootUser identifier, they can do anything! * If the user has an IsRootUser identifier, they can do anything!
@ -64,10 +64,7 @@ public class RootUserPolicy implements PolicyIface {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
UserAccountsDao uaDao = getUserAccountsDao(ctx); UserAccountsDao uaDao = getUserAccountsDao(ctx);
@ -82,8 +79,8 @@ public class RootUserPolicy implements PolicyIface {
} catch (Exception e) { } catch (Exception e) {
log.error("could not run " + this.getClass().getSimpleName() log.error("could not run " + this.getClass().getSimpleName()
+ ": " + e); + ": " + e);
AbortStartup.abortStartup(ctx); ss.fatal(this, "could not run " + this.getClass().getSimpleName()
throw new RuntimeException(e); + ": " + e);
} }
} }

View file

@ -27,7 +27,7 @@ import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Assists the role-based policies in determining whether a property or resource * Assists the role-based policies in determining whether a property or resource
@ -342,10 +342,7 @@ public class PropertyRestrictionPolicyHelper {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
OntModel model = (OntModel) ctx.getAttribute("jenaOntModel"); OntModel model = (OntModel) ctx.getAttribute("jenaOntModel");
@ -360,8 +357,8 @@ public class PropertyRestrictionPolicyHelper {
} catch (Exception e) { } catch (Exception e) {
log.error("could not run PropertyRestrictionPolicyHelper$Setup: " log.error("could not run PropertyRestrictionPolicyHelper$Setup: "
+ e); + e);
AbortStartup.abortStartup(ctx); ss.fatal(this, "could not run PropertyRestrictionPolicyHelper$Setup: "
throw new RuntimeException(e); + e);
} }
} }

View file

@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.policy.EditRestrictedDataByRoleLeve
import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
import edu.cornell.mannlib.vitro.webapp.auth.policy.UseRestrictedPagesByRoleLevelPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.UseRestrictedPagesByRoleLevelPolicy;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Set up the common policy family, with Identifier factory. * Set up the common policy family, with Identifier factory.
@ -29,10 +29,7 @@ public class CommonPolicyFamilySetup implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
ServletPolicyList.addPolicy(ctx, ServletPolicyList.addPolicy(ctx,
@ -54,8 +51,8 @@ public class CommonPolicyFamilySetup implements ServletContextListener {
} catch (Exception e) { } catch (Exception e) {
log.error("could not run " + this.getClass().getSimpleName() + ": " log.error("could not run " + this.getClass().getSimpleName() + ": "
+ e); + e);
AbortStartup.abortStartup(ctx); ss.fatal(this, "could not run " + this.getClass().getSimpleName() + ": "
throw new RuntimeException(e); + e);
} }
} }

View file

@ -18,7 +18,7 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Reads the configuration properties from a file and stores them in the servlet * Reads the configuration properties from a file and stores them in the servlet
@ -79,18 +79,20 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
try { try {
InputStream stream = null; InputStream stream = null;
try { try {
stream = locatePropertiesFile(); stream = locatePropertiesFile();
ConfigurationProperties.setBean(ctx,
new ConfigurationPropertiesImpl(stream)); ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(
stream);
ConfigurationProperties.setBean(ctx, bean);
ss.info(this, "Loaded " + bean.getPropertyMap().size()
+ " properties.");
} finally { } finally {
if (stream != null) { if (stream != null) {
try { try {
@ -102,8 +104,7 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
AbortStartup.abortStartup(ctx); ss.fatal(this, e.getMessage(), e);
throw new RuntimeException(e);
} }
} }

View file

@ -26,6 +26,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean.LevelRevisionInfo; import edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean.LevelRevisionInfo;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* <pre> * <pre>
@ -72,6 +73,7 @@ public class RevisionInfoSetup implements ServletContextListener {
bean = parseRevisionInformation(lines); bean = parseRevisionInformation(lines);
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
StartupStatus.getBean(context).warning(this, e.getMessage(), e);
bean = DUMMY_BEAN; bean = DUMMY_BEAN;
} }

View file

@ -11,20 +11,13 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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 edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import freemarker.template.Configuration;
public class FreemarkerSetup implements ServletContextListener { public class FreemarkerSetup implements ServletContextListener {
private static final Log log = LogFactory.getLog(FreemarkerSetup.class); private static final Log log = LogFactory.getLog(FreemarkerSetup.class);
public void contextInitialized(ServletContextEvent event) { public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
ServletContext sc = event.getServletContext(); ServletContext sc = event.getServletContext();
sc.setAttribute("themeToConfigMap", new HashMap<String, FreemarkerConfiguration>()); sc.setAttribute("themeToConfigMap", new HashMap<String, FreemarkerConfiguration>());
BaseTemplateModel.setServletContext(sc); BaseTemplateModel.setServletContext(sc);

View file

@ -16,7 +16,6 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener; import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
@ -34,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
public class VClassGroupCache { public class VClassGroupCache {
private static final Log log = LogFactory.getLog(VClassGroupCache.class); private static final Log log = LogFactory.getLog(VClassGroupCache.class);
@ -69,7 +68,7 @@ public class VClassGroupCache {
this.context = context; this.context = context;
this._groupList = null; this._groupList = null;
if (AbortStartup.isStartupAborted(context)) { if (StartupStatus.getBean(context).isStartupAborted()) {
_cacheRebuildThread = null; _cacheRebuildThread = null;
return; return;
} }

View file

@ -17,7 +17,7 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* A factory that creates Freemarker-based email messages. * A factory that creates Freemarker-based email messages.
@ -154,18 +154,25 @@ public class FreemarkerEmailFactory {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
ctx.setAttribute(ATTRIBUTE_NAME, FreemarkerEmailFactory factory = new FreemarkerEmailFactory(ctx);
new FreemarkerEmailFactory(ctx)); ctx.setAttribute(ATTRIBUTE_NAME, factory);
if (factory.isConfigured()) {
ss.info(this, "The system is configured to "
+ "send mail to users.");
} else {
ss.info(this, "Configuration parameters are missing: "
+ "the system will not send mail to users.");
}
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
AbortStartup.abortStartup(ctx); ss.warning(this,
throw new RuntimeException(e); "Failed to initialize FreemarkerEmailFactory. "
+ "The system will not be able to send email "
+ "to users.", e);
} }
} }

View file

@ -15,6 +15,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Initializes the file storage system, and stores a reference in the servlet * Initializes the file storage system, and stores a reference in the servlet
@ -50,15 +51,18 @@ public class FileStorageSetup implements ServletContextListener {
*/ */
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
try { try {
File baseDirectory = figureBaseDir(sce); File baseDirectory = figureBaseDir(sce);
Collection<String> fileNamespace = confirmDefaultNamespace(sce); Collection<String> fileNamespace = confirmDefaultNamespace(sce);
FileStorage fs = new FileStorageImpl(baseDirectory, fileNamespace); FileStorage fs = new FileStorageImpl(baseDirectory, fileNamespace);
ServletContext sc = sce.getServletContext(); ctx.setAttribute(ATTRIBUTE_NAME, fs);
sc.setAttribute(ATTRIBUTE_NAME, fs);
} catch (Exception e) { } catch (Exception e) {
log.fatal("Failed to initialize the file system.", e); log.fatal("Failed to initialize the file system.", e);
ss.fatal(this, "Failed to initialize the file system.", e);
} }
} }

View file

@ -38,7 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForObjectP
import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForTypeStatements; import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForTypeStatements;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener; import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
public class SolrSetup implements javax.servlet.ServletContextListener{ public class SolrSetup implements javax.servlet.ServletContextListener{
private static final Log log = LogFactory.getLog(SolrSetup.class.getName()); private static final Log log = LogFactory.getLog(SolrSetup.class.getName());
@ -47,12 +47,10 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) { ServletContext context = sce.getServletContext();
return; StartupStatus ss = StartupStatus.getBean(context);
}
try { try {
ServletContext context = sce.getServletContext();
/* setup the http connection with the solr server */ /* setup the http connection with the solr server */
String solrServerUrl = ConfigurationProperties.getBean(sce).getProperty("vitro.local.solr.url"); String solrServerUrl = ConfigurationProperties.getBean(sce).getProperty("vitro.local.solr.url");
@ -122,8 +120,10 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
ModelContext.registerListenerForChanges(ctx, srl); ModelContext.registerListenerForChanges(ctx, srl);
log.info("Setup of Solr index completed."); log.info("Setup of Solr index completed.");
ss.info(this, "Setup of Solr index completed.");
} catch (Throwable e) { } catch (Throwable e) {
log.error("could not setup local solr server",e); log.error("could not setup local solr server",e);
ss.fatal(this, "could not setup local solr server",e);
} }
} }

View file

@ -1,37 +0,0 @@
/* $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;
/**
* Provide a mechanism so a ServletContextListener can set a flag that tells
* other ServletContextListeners not to run.
*
* The listener that detects a problem should still throw an exception, so
* Tomcat will declare that the startup has failed and mark the application as
* not runnable. However, Tomcat will still run the other listeners before
* giving up. Hence, the need for this flag.
*
* If the other listeners are looking for this flag, they can (and should)
* decide to simply exit rather than attempting to initialize.
*/
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

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

View file

@ -31,10 +31,6 @@ public class AttachSubmodels implements ServletContextListener {
public void contextInitialized( ServletContextEvent sce ) { public void contextInitialized( ServletContextEvent sce ) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
if (true) { if (true) {
(new FileGraphSetup()).contextInitialized(sce); (new FileGraphSetup()).contextInitialized(sce);

View file

@ -14,12 +14,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.ThemeUtils;
public class DefaultThemeSetup implements ServletContextListener { public class DefaultThemeSetup implements ServletContextListener {
// Set default theme based on themes present on the file system // Set default theme based on themes present on the file system
@Override
public void contextInitialized(ServletContextEvent event) { public void contextInitialized(ServletContextEvent event) {
if (AbortStartup.isStartupAborted(event.getServletContext())) {
return;
}
// Find the themes directory in the file system // Find the themes directory in the file system
ServletContext sc = event.getServletContext(); ServletContext sc = event.getServletContext();
boolean doSort = true; boolean doSort = true;
@ -36,9 +32,9 @@ public class DefaultThemeSetup implements ServletContextListener {
String defaultThemeDir = "themes/" + defaultTheme + "/"; String defaultThemeDir = "themes/" + defaultTheme + "/";
// Define as a static variable of Portal so getThemeDir() method of portal can access it. // Define as a static variable of Portal so getThemeDir() method of portal can access it.
ApplicationBean.DEFAULT_THEME_DIR_FROM_CONTEXT = defaultThemeDir; ApplicationBean.DEFAULT_THEME_DIR_FROM_CONTEXT = defaultThemeDir;
} }
@Override
public void contextDestroyed(ServletContextEvent event) { public void contextDestroyed(ServletContextEvent event) {
// nothing to do here // nothing to do here
} }

View file

@ -43,10 +43,6 @@ public class FileGraphSetup implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
boolean aboxChanged = false; // indicates whether any ABox file graph model has changed boolean aboxChanged = false; // indicates whether any ABox file graph model has changed
boolean tboxChanged = false; // indicates whether any TBox file graph model has changed boolean tboxChanged = false; // indicates whether any TBox file graph model has changed
OntModelSelector baseOms = null; OntModelSelector baseOms = null;

View file

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

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup; package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -52,7 +51,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker; import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker; import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils; import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils;
public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener { public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener {
@ -61,12 +60,8 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
try { try {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -75,18 +70,11 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
" seconds to set up SDB store"); " seconds to set up SDB store");
} catch (SQLException sqle) { } catch (SQLException sqle) {
// SQL exceptions are fatal and should halt startup // SQL exceptions are fatal and should halt startup
AbortStartup.abortStartup(ctx);
log.error("Error using SQL database; startup aborted.", sqle); log.error("Error using SQL database; startup aborted.", sqle);
// print to catalina.out for good measure ss.fatal(this, "Error using SQL database; startup aborted.", sqle);
System.out.println("Error using SQL database; startup aborted.");
sqle.printStackTrace();
throw new Error(this.getClass().getName() + "failed");
} catch (Throwable t) { } catch (Throwable t) {
log.error("Throwable in " + this.getClass().getName(), t); log.error("Throwable in " + this.getClass().getName(), t);
// printing the error because Tomcat doesn't print context listener ss.fatal(this, "Throwable in " + this.getClass().getName(), t);
// errors the same way it prints other errors at startup
t.printStackTrace();
throw new Error(this.getClass().getName() + "failed");
} }
} }

View file

@ -23,6 +23,7 @@ import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
implements ServletContextListener { implements ServletContextListener {
@ -33,10 +34,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
if (AbortStartup.isStartupAborted(ctx)) {
return;
}
// user accounts Model // user accounts Model
try { try {
@ -59,6 +57,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
} }
} catch (Throwable t) { } catch (Throwable t) {
log.error("Unable to load user accounts model from DB", t); log.error("Unable to load user accounts model from DB", t);
ss.fatal(this, "Unable to load user accounts model from DB", t);
} }
// display, editing and navigation Model // display, editing and navigation Model
@ -77,6 +76,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
initializeDisplayLoadedAtStartup(ctx, displayModel); initializeDisplayLoadedAtStartup(ctx, displayModel);
} catch (Throwable t) { } catch (Throwable t) {
log.error("Unable to load user application configuration model", t); log.error("Unable to load user application configuration model", t);
ss.fatal(this, "Unable to load user application configuration model", t);
} }
//display tbox - currently reading in every time //display tbox - currently reading in every time
@ -94,6 +94,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
log.debug("Loaded file " + APPPATH_LOAD + "displayTBOX.n3 into display tbox model"); log.debug("Loaded file " + APPPATH_LOAD + "displayTBOX.n3 into display tbox model");
} catch (Throwable t) { } catch (Throwable t) {
log.error("Unable to load user application configuration model TBOX", t); log.error("Unable to load user application configuration model TBOX", t);
ss.fatal(this, "Unable to load user application configuration model TBOX", t);
} }
//Display Display model, currently empty, create if doesn't exist but no files to load //Display Display model, currently empty, create if doesn't exist but no files to load
@ -112,6 +113,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
log.debug("Loaded file " + APPPATH_LOAD + "displayDisplay.n3 into display display model"); log.debug("Loaded file " + APPPATH_LOAD + "displayDisplay.n3 into display display model");
} catch (Throwable t) { } catch (Throwable t) {
log.error("Unable to load user application configuration model Display Model", t); log.error("Unable to load user application configuration model Display Model", t);
ss.fatal(this, "Unable to load user application configuration model Display Model", t);
} }
} }

View file

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

View file

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

View file

@ -22,11 +22,6 @@ public class PelletReasonerSetup implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
if (true) { if (true) {
(new SimpleReasonerSetup()).contextInitialized(sce); (new SimpleReasonerSetup()).contextInitialized(sce);
return; return;

View file

@ -20,11 +20,6 @@ public class PelletReasonerSetupComplete implements ServletContextListener {
private static final Log log = LogFactory.getLog(PelletReasonerSetupComplete.class.getName()); private static final Log log = LogFactory.getLog(PelletReasonerSetupComplete.class.getName());
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try { try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel"); OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");

View file

@ -20,11 +20,6 @@ public class PelletReasonerSetupPseudocomplete implements ServletContextListener
private static final Log log = LogFactory.getLog(PelletReasonerSetupComplete.class.getName()); private static final Log log = LogFactory.getLog(PelletReasonerSetupComplete.class.getName());
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try { try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel"); OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");

View file

@ -21,13 +21,7 @@ public class PelletReasonerSetupPseudocompleteIgnoreDataproperties implements
private static final Log log = LogFactory.getLog(PelletReasonerSetupPseudocompleteIgnoreDataproperties.class.getName()); private static final Log log = LogFactory.getLog(PelletReasonerSetupPseudocompleteIgnoreDataproperties.class.getName());
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try { try {
OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel"); OntModel memoryModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel"); OntModel baseModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel"); OntModel inferenceModel = (OntModel) sce.getServletContext().getAttribute("inferenceOntModel");
@ -57,7 +51,6 @@ public class PelletReasonerSetupPseudocompleteIgnoreDataproperties implements
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
} }
public void contextDestroyed(ServletContextEvent arg0) { public void contextDestroyed(ServletContextEvent arg0) {

View file

@ -41,13 +41,7 @@ public class RunSparqlConstructs implements ServletContextListener {
private static Random random = new Random(System.currentTimeMillis()); private static Random random = new Random(System.currentTimeMillis());
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try { try {
WebappDaoFactory wadf = (WebappDaoFactory) sce.getServletContext().getAttribute("webappDaoFactory"); WebappDaoFactory wadf = (WebappDaoFactory) sce.getServletContext().getAttribute("webappDaoFactory");
String namespace = (wadf != null && wadf.getDefaultNamespace() != null) String namespace = (wadf != null && wadf.getDefaultNamespace() != null)
? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE; ? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE;

View file

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

View file

@ -68,13 +68,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
private static final String NEW_TBOX_ANNOTATIONS_DIR = "/WEB-INF/ontologies/user/tbox/"; private static final String NEW_TBOX_ANNOTATIONS_DIR = "/WEB-INF/ontologies/user/tbox/";
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try { try {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
String logFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate", "log"); String logFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate", "log");

View file

@ -20,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup; import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageAliasAdder; import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageAliasAdder;
import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageUpdater; import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageUpdater;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Check that the conditions are met for updating uploaded files. If everything * Check that the conditions are met for updating uploaded files. If everything
@ -48,14 +49,9 @@ public class UpdateUploadedFiles implements ServletContextListener {
*/ */
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
return;
}
try {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
try {
WebappDaoFactory wadf = (WebappDaoFactory) ctx WebappDaoFactory wadf = (WebappDaoFactory) ctx
.getAttribute("assertionsWebappDaoFactory"); .getAttribute("assertionsWebappDaoFactory");
if (wadf == null) { if (wadf == null) {
@ -142,6 +138,7 @@ public class UpdateUploadedFiles implements ServletContextListener {
fsaa.update(); fsaa.update();
} catch (Exception e) { } catch (Exception e) {
log.fatal("Unknown problem", e); log.fatal("Unknown problem", e);
StartupStatus.getBean(ctx).fatal(this, "Unknown problem", e);
} }
} }
} }

View file

@ -37,6 +37,7 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Convert any existing User resources (up to rel 1.2) in the UserAccounts Model * Convert any existing User resources (up to rel 1.2) in the UserAccounts Model
@ -60,9 +61,7 @@ public class UpdateUserAccounts implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
if (AbortStartup.isStartupAborted(ctx)) { StartupStatus ss = StartupStatus.getBean(ctx);
return;
}
try { try {
Updater updater = new Updater(ctx); Updater updater = new Updater(ctx);
@ -70,8 +69,8 @@ public class UpdateUserAccounts implements ServletContextListener {
updater.update(); updater.update();
} }
} catch (Exception e) { } catch (Exception e) {
AbortStartup.abortStartup(ctx);
log.fatal("Failed to update user accounts information", e); log.fatal("Failed to update user accounts information", e);
ss.fatal(this, "Failed to update user accounts information", e);
} }
} }

View file

@ -11,11 +11,16 @@ import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* Accumulates a list of messages from the StartupManager, and from the context * Accumulates a list of messages from the StartupManager, and from the context
* listeners that the run during startup. * listeners that the run during startup.
*/ */
public class StartupStatus { public class StartupStatus {
private static final Log log = LogFactory.getLog(StartupStatus.class);
private static final String ATTRIBUTE_NAME = "STARTUP_STATUS"; private static final String ATTRIBUTE_NAME = "STARTUP_STATUS";
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -143,20 +148,67 @@ public class StartupStatus {
private final String message; private final String message;
private final String cause; private final String cause;
private boolean unexpectedArguments;
public StatusItem(Level level, ServletContextListener source, public StatusItem(Level level, ServletContextListener source,
String message, Throwable cause) { String message, Throwable cause) {
this.level = level; this.level = figureLevel(level);
this.sourceName = source.getClass().getName(); this.sourceName = figureSourceName(source);
this.shortSourceName = source.getClass().getSimpleName(); this.shortSourceName = figureShortSourceName(source);
this.message = message; this.message = message;
this.cause = figureCauseString(cause);
if (cause == null) { if (unexpectedArguments) {
this.cause = ""; log.error("Unexpected arguments to "
+ StatusItem.class.getName() + ": level=" + level
+ ", source=" + source + ", message=" + message
+ ", cause=" + cause);
}
}
/** Level should never be null: we have a problem. */
private Level figureLevel(Level newLevel) {
if (newLevel == null) {
unexpectedArguments = true;
return Level.FATAL;
} else {
return newLevel;
}
}
private String figureSourceName(ServletContextListener source) {
if (source == null) {
unexpectedArguments = true;
return "UNKNOWN SOURCE";
} else {
return source.getClass().getName();
}
}
/**
* Don't just use getSimpleName(): on an inner class we'd like to see
* the parent also.
*/
private String figureShortSourceName(ServletContextListener source) {
if (source == null) {
unexpectedArguments = true;
return "UNKNOWN_SOURCE";
} else {
String sourceClassName = source.getClass().getName();
int lastPeriodHere = sourceClassName.lastIndexOf('.');
return sourceClassName.substring(lastPeriodHere + 1);
}
}
/** Cause may be null - that's not unexpected. */
private String figureCauseString(Throwable newCause) {
if (newCause == null) {
return "";
} else { } else {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
cause.printStackTrace(pw); newCause.printStackTrace(pw);
this.cause = sw.toString(); return sw.toString();
} }
} }