2 * Copyright 2009 University of California at Berkeley
4 package org.collectionspace.services.common;
6 import javax.servlet.ServletContext;
7 import javax.servlet.ServletContextEvent;
8 import javax.servlet.ServletContextListener;
10 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
13 * CollectionSpaceServiceContextListener is a ServletContextListener that helps initialize
14 * the services layer at deployment and undeployment times
16 public class CollectionSpaceServiceContextListener implements ServletContextListener {
19 public void contextInitialized(ServletContextEvent event) {
22 // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
24 ServletContext servletContext = event.getServletContext();
25 ServiceMain svcMain = ServiceMain.getInstance(servletContext);
27 svcMain.retrieveAllWorkspaceIds();
29 // Create required indexes (aka indices) in tables not associated
30 // with any specific tenant.
31 svcMain.createRequiredIndices();
33 // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
34 // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
36 svcMain.firePostInitHandlers();
38 } catch (Throwable e) {
41 System.err.println("[ERROR] ***");
42 System.err.println("[ERROR] The CollectionSpace Services could not initialize. Please see the log files for details.");
43 System.err.println("[ERROR] ***");
44 // throw new RuntimeException(e);
49 public void contextDestroyed(ServletContextEvent event) {
50 ServiceMain instance = null;
53 ServiceMain.getInstance();
54 } catch (Throwable t) {
55 // Do nothing. Error already logged by the Services layer
57 if (instance != null) {
60 System.err.println("ERROR: The CollectionSpace Services layer failed to startup successfully. Look in the tomcat logs and cspace-services logs for details.");
62 JpaStorageUtils.releaseEntityManagerFactories();