]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
f7c0c251e95447413995ee4263a1aeeb7c860044
[tmp/jakarta-migration.git] /
1 /**
2  * Copyright 2009 University of California at Berkeley
3  */
4 package org.collectionspace.services.common;
5
6 import javax.servlet.ServletContext;
7 import javax.servlet.ServletContextEvent;
8 import javax.servlet.ServletContextListener;
9
10 /**
11  * CollectionSpaceServiceContextListener is a ServletContextListener that helps initialize
12  * the services layer at deployment and undeployment times
13  */
14 public class CollectionSpaceServiceContextListener implements ServletContextListener {
15
16     @Override
17     public void contextInitialized(ServletContextEvent event) {
18         try {
19                 //
20                 // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
21                 //
22                 ServletContext servletContext = event.getServletContext();
23             ServiceMain svcMain = ServiceMain.getInstance(servletContext);
24             
25                 {
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
30                         do {
31                                 if (currentTime % 1000 == 0) {
32                                         System.out.print(".");
33                                 }
34                                 currentTime = System.currentTimeMillis();
35                         } while (currentTime < stopTime);
36                                 
37                         System.out.println();
38                         System.out.println("Resuming cspace services initialization.");
39                 }
40             
41             svcMain.retrieveAllWorkspaceIds();
42
43                 {
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
48                         do {
49                                 if (currentTime % 1000 == 0) {
50                                         System.out.print(".");
51                                 }
52                                 currentTime = System.currentTimeMillis();
53                         } while (currentTime < stopTime);
54                                 
55                         System.out.println();
56                         System.out.println("Resuming cspace services initialization.");
57                 }
58             
59                 //
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.
62                 //
63                 svcMain.firePostInitHandlers();
64             
65                 {
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
70                         do {
71                                 if (currentTime % 1000 == 0) {
72                                         System.out.print(".");
73                                 }
74                                 currentTime = System.currentTimeMillis();
75                         } while (currentTime < stopTime);
76                                 
77                         System.out.println();
78                         System.out.println("Resuming cspace services initialization.");
79                 }
80                 
81         } catch (Exception e) {
82             e.printStackTrace();
83             //fail here
84             System.err.println("[ERROR] The CollectionSpace Services could not initialize.  Please see the log files for details.");
85             throw new RuntimeException(e);
86         }
87     }
88
89     @Override
90     public void contextDestroyed(ServletContextEvent event) {
91         //ServiceMain.getInstance().release();
92     }
93 }