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;
11 * CollectionSpaceServiceContextListener is a ServletContextListener that helps initialize
12 * the services layer at deployment and undeployment times
14 public class CollectionSpaceServiceContextListener implements ServletContextListener {
17 public void contextInitialized(ServletContextEvent event) {
20 // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
22 ServletContext servletContext = event.getServletContext();
23 ServiceMain svcMain = ServiceMain.getInstance(servletContext);
26 System.out.print("About to retrieveAllWorkspaceIds - Pausing 4:5 seconds for you to attached the debugger");
27 long startTime, currentTime;
28 currentTime = startTime = System.currentTimeMillis();
29 long stopTime = startTime + 5 * 1000; //5 seconds
31 if (currentTime % 1000 == 0) {
32 System.out.print(".");
34 currentTime = System.currentTimeMillis();
35 } while (currentTime < stopTime);
38 System.out.println("Resuming cspace services initialization.");
41 svcMain.retrieveAllWorkspaceIds();
44 System.out.print("About to firePostInitHandlers - Pausing 5:5 seconds for you to attached the debugger");
45 long startTime, currentTime;
46 currentTime = startTime = System.currentTimeMillis();
47 long stopTime = startTime + 5 * 1000; //5 seconds
49 if (currentTime % 1000 == 0) {
50 System.out.print(".");
52 currentTime = System.currentTimeMillis();
53 } while (currentTime < stopTime);
56 System.out.println("Resuming cspace services initialization.");
60 // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
61 // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
63 svcMain.firePostInitHandlers();
66 System.out.print("Finished to firePostInitHandlers - Pausing 6:5 seconds for you to attached the debugger");
67 long startTime, currentTime;
68 currentTime = startTime = System.currentTimeMillis();
69 long stopTime = startTime + 5 * 1000; //5 seconds
71 if (currentTime % 1000 == 0) {
72 System.out.print(".");
74 currentTime = System.currentTimeMillis();
75 } while (currentTime < stopTime);
78 System.out.println("Resuming cspace services initialization.");
81 } catch (Exception e) {
84 System.err.println("[ERROR] The CollectionSpace Services could not initialize. Please see the log files for details.");
85 throw new RuntimeException(e);
90 public void contextDestroyed(ServletContextEvent event) {
91 //ServiceMain.getInstance().release();