KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > core > 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.core;
24 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
25 import com.sun.enterprise.webservice.ServiceEngineUtil;
26 import com.sun.logging.LogDomains;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.jbi.JBIException;
31 import javax.jbi.component.ComponentContext;
32 import javax.jbi.component.ComponentLifeCycle;
33
34
35 /**
36  * Provide initialization, start, stop, and shutdown processing. The JBI
37  * implementation queries the component for the implementation of this
38  * interface using the <code>Component.getComponentLifeCycle()</code> method.
39  * The methods in this interface comprise the life cycle contract between the
40  * JBI implementation and the component. The life cycle of a component begins
41  * with a call to the <code>init()</code> method on an instance of the
42  * component's implementation of this interface, and ends with the first call
43  * to the <code>shutDown()</code> method on that instance. Between these two
44  * calls, there can be any number of <code>stop()</code> and
45  * <code>start()</code> calls.
46  * @author Manisha Umbarje
47  */

48 public class JavaEEServiceEngineLifeCycle implements ComponentLifeCycle {
49     
50     /**
51      * This context provides access to data needed by all JBI components running in
52      * the JBI environment.
53      */

54     private JavaEEServiceEngineContext context;
55     private ComponentContext jbiContext;
56     private Thread JavaDoc managerThread;
57     
58     /**
59      * Internal handle to the logger instance
60      */

61     protected static Logger JavaDoc logger =
62             LogDomains.getLogger(LogDomains.SERVER_LOGGER);
63     
64     /** Creates a new instance of JavaEEServiceEngineLifeCycle */
65     public JavaEEServiceEngineLifeCycle() {
66     }
67     
68     /**
69      * Get the JMX <code>ObjectName</code> for any additional MBean for this
70      * component. If there is none, return <code>null</code>.
71      * @return the JMX object name of the additional MBean or <code>null</code>
72      * if there is no additional MBean.
73      */

74     public ObjectName JavaDoc getExtensionMBeanName(){
75         return null;
76     }
77     
78     /**
79      * Initialize the component. This performs initialization required by the
80      * component but does not make it ready to process messages. This method
81      * is called once for each life cycle of the component.
82      * @param context the component's context.
83      * @throws javax.jbi.JBIException if the component is unable to initialize.
84      */

85     public void init(ComponentContext jbiContext) throws JBIException {
86         this.jbiContext = jbiContext;
87     }
88     
89     /**
90      * Shut down the component. This performs cleanup before the component is
91      * terminated. Once this method has been called, <code>init()</code> must
92      * be called before the component can be started again with a call to
93      * <code>start()</code>.
94      * @throws javax.jbi.JBIException if the component is unable to shut down.
95      */

96     public void shutDown() throws JBIException {
97         
98     }
99     
100     /**
101      * Start the component. This makes the component ready to process messages.
102      * This method is called after <code>init()</code> completes when the JBI
103      * implementation is starting up, and when the component is being restarted
104      * after a previous call to <code>shutDown()</code>. If <code>stop()</code>
105      * was called previously but <code>shutDown()</code> was not, then
106      * <code>start()</code> can be called again without another call to
107      * <code>init()</code>.
108      * @throws javax.jbi.JBIException if the component is unable to start.
109      */

110     public void start() throws JBIException{
111         try {
112             if(ServiceEngineUtil.isServiceEngineEnabled()) {
113                 logger.log(Level.FINE, "Service Engine starting");
114                 context = JavaEEServiceEngineContext.getInstance();
115                 context.setJBIContext(jbiContext);
116                 context.initialize();
117                 
118                 // Starts all the threads such as thread accepting a message from
119
// DeliveryChannel and delivering it to WorkManager
120
managerThread = new Thread JavaDoc(context.getWorkManager());
121                 managerThread.start();
122                 logger.log(Level.INFO, "serviceengine.success_start");
123                 
124             } else {
125                 logger.log(Level.INFO,
126                         "Java EE Service Engine is not active as it is disabled " +
127                         "by setting the JVM flag com.sun.enterprise.jbi.se.disable to true");
128             }
129             
130             
131         }catch(Exception JavaDoc e) {
132             logger.log(Level.SEVERE, "serviceengine.error_start",
133                     new Object JavaDoc[]{e.getMessage()});
134                     throw new JBIException(e.getMessage());
135         }
136     }
137     
138     /**
139      * Stop the component. This makes the component stop accepting messages for
140      * processing. After a call to this method, <code>start()</code> can be
141      * called again without first calling <code>init()</code>.
142      * @throws javax.jbi.JBIException if the component is unable to stop.
143      */

144     public void stop() throws JBIException {
145         //Stop multiple threads involved in request processing by the
146
//JavaEEServiceEngine
147
try {
148             if(ServiceEngineUtil.isServiceEngineEnabled()) {
149                 context.getDeliveryChannel().close();
150                 context.getWorkManager().stop();
151                 managerThread.join();
152                 logger.log(Level.INFO, "serviceengine.success_stop");
153             }
154         } catch(Exception JavaDoc e) {
155             e.printStackTrace();
156             throw new JBIException(e.getMessage());
157         }
158     }
159     
160 }
161
Popular Tags