KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > bridge > JavaEEServiceEngineLifeCycle


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.jbi.serviceengine.bridge;
24
25 import com.sun.appserv.server.ServerLifecycle;
26 import com.sun.appserv.server.ServerLifecycleException;
27 import com.sun.enterprise.server.ServerContext;
28 import com.sun.enterprise.jbi.serviceengine.install.Installer;
29 import com.sun.logging.LogDomains;
30 import com.sun.enterprise.server.ApplicationServer;
31 import com.sun.enterprise.jbi.serviceengine.install.ServiceEngineObjectFactoryImpl;
32 import com.sun.enterprise.server.event.ApplicationLoaderEventNotifier;
33 import com.sun.enterprise.webservice.ServiceEngineUtil;
34 import java.net.InetAddress JavaDoc;
35 import java.io.File JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39 /**
40  *
41  * @author Manisha Umbarje
42  */

43 public class JavaEEServiceEngineLifeCycle implements ServerLifecycle {
44     
45     
46     private static Logger JavaDoc logger = LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
47     public String JavaDoc DEFAULT_COMPONENT_NAME ="JavaEEServiceEngine";
48     
49     
50     /** Creates a new instance of JavaEEServiceEngineLifeCycle */
51     public JavaEEServiceEngineLifeCycle() {
52     }
53     
54     /**
55      * Server is initializing subsystems and setting up the runtime environment.
56      * Prepare for the beginning of active use of the public methods of this
57      * subsystem. This method is called before any of the public methods of
58      * this subsystem are utilized.
59      *
60      * @param sc ServerContext the server runtime context.
61      *
62      * @exception IllegalStateException if this subsystem has already been
63      * started
64      * @exception ServerLifecycleException if this subsystem detects a fatal
65      * error that prevents this subsystem from being used
66      */

67     public void onInitialization(ServerContext sc)
68     throws ServerLifecycleException {
69         logger.log(Level.FINEST, "se_lifecycle_initializing");
70         /*ApplicationLoaderEventNotifier.getInstance().
71                         addListener(ApplicationLoaderEventListenerImpl.getInstance());*/

72         
73     }
74     
75     /**
76      * Server is starting up applications
77      *
78      * @param sc ServerContext the server runtime context.
79      *
80      * @exception ServerLifecycleException if this subsystem detects a fatal
81      * error that prevents this subsystem from being used
82      */

83     public void onStartup(ServerContext sc)
84     throws ServerLifecycleException {
85         logger.log(Level.FINEST, "se_lifecycle_starting");
86     }
87     /**
88      * Server has complted loading the applications and is ready to serve requests.
89      *
90      * @param sc ServerContext the server runtime context.
91      *
92      * @exception ServerLifecycleException if this subsystem detects a fatal
93      * error that prevents this subsystem from being used
94      */

95     public void onReady(ServerContext sc) throws ServerLifecycleException {
96         
97         
98         
99         Installer installer =
100                 ServiceEngineObjectFactoryImpl.getInstance().
101                 createInstaller();
102         if(installer.isJBIInstalled()) {
103             installer.setComponentName(DEFAULT_COMPONENT_NAME);
104             try {
105                 boolean installedFlag = installer.isComponentInstalled();
106                 logger.log(Level.FINE, "Is Java EE Service Engine installed " + installedFlag);
107                 
108                 if(ServiceEngineUtil.isServiceEngineEnabled()) {
109                     //Assumption here is if service engine is already installed,
110
// It will be resumed in its state by the JBI framework
111
if(!installedFlag) {
112                         installer.install(null);
113                         installer.start();
114                     }
115                 }else {
116                     logger.log(Level.FINEST, "Java EE Service Engine is disabled");
117                     if(installedFlag) {
118                         // If service engine is disabled, stop the service engine
119
try {
120                             installer.stop();
121                         } catch(Exception JavaDoc e) {
122                         }
123                     }
124                 }
125             } catch (Throwable JavaDoc e) {
126                 e.printStackTrace();
127             }
128         }
129     }
130     /**
131      * Server is shutting down applications
132      *
133      * @exception ServerLifecycleException if this subsystem detects a fatal
134      * error that prevents this subsystem from being used
135      */

136     public void onShutdown()
137     throws ServerLifecycleException {
138     }
139     /**
140      * Server is terminating the subsystems and the runtime environment.
141      * Gracefully terminate the active use of the public methods of this
142      * subsystem. This method should be the last one called on a given
143      * instance of this subsystem.
144      *
145      * @exception ServerLifecycleException if this subsystem detects a fatal
146      * error that prevents this subsystem from being used
147      */

148     public void onTermination()
149     throws ServerLifecycleException {
150         
151     }
152 }
153
Popular Tags