KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > util > StartStopCallback


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.management.util;
24
25 import com.sun.enterprise.admin.server.core.mbean.config.*;
26 import com.sun.enterprise.management.model.*;
27 import com.sun.enterprise.ManagementObjectManager;
28 import javax.management.*;
29
30
31 /**
32  * J2EEModuleCallBack will invoke corresponding methods in this class.
33  * Instantiates the mBean of corresponding module or application and
34  * invokes the start or stop method appropriately.
35  *
36  * @version 1.0 26mar2003
37  * @author Sreenivas Munnangi
38  */

39 public class StartStopCallback {
40     private static boolean debug = false;
41
42     /**
43      * Invokes appropriate start method based on j2ee type.
44      * If trying to start a module which is part of an application
45      * then it will throw exception.
46      */

47     public void startModule(J2EEDeployedObjectMdl modObject)
48         throws MBeanException {
49
50         if (debug) {
51             return;
52         }
53
54         String JavaDoc moduleID = modObject.getname();
55         String JavaDoc j2eeType = modObject.getj2eeType();
56         String JavaDoc serverName = modObject.getJ2EEServer();
57
58         // check if trying to start a module which is part of the application
59
if ((!j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) &&
60                 (!standAlone(modObject))) {
61             throw new MBeanException(
62                   new Exception JavaDoc(
63                   "cannot start individual module, start the application itself"));
64         }
65
66         if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_EJB_MODULE)) {
67             startEJBModule(moduleID, serverName);
68         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_WEB_MODULE)) {
69             startWEBModule(moduleID, serverName);
70         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_RAR_MODULE)) {
71             startRARModule(moduleID, serverName);
72         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_ACC_MODULE)) {
73             return;
74         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) {
75             startApplication(moduleID, serverName);
76         }
77     }
78
79     /**
80      * Invokes appropriate stop method based on j2ee type.
81      * If trying to stop a module which is part of an application
82      * then it will throw exception.
83      */

84     public void stopModule(J2EEDeployedObjectMdl modObject)
85         throws MBeanException {
86
87         if (debug) {
88             return;
89         }
90
91         String JavaDoc moduleID = modObject.getname();
92         String JavaDoc j2eeType = modObject.getj2eeType();
93         String JavaDoc serverName = modObject.getJ2EEServer();
94
95         // check if trying to stop a module which is part of the application
96
if ((!j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) &&
97                 (!standAlone(modObject))) {
98             throw new MBeanException(
99                 new Exception JavaDoc(
100                 "cannot stop individual module, stop the application itself"));
101         }
102
103         if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_EJB_MODULE)) {
104             stopEJBModule(moduleID, serverName);
105         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_WEB_MODULE)) {
106             stopWEBModule(moduleID, serverName);
107         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_RAR_MODULE)) {
108             stopRARModule(moduleID, serverName);
109         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_ACC_MODULE)) {
110             return;
111         } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) {
112             stopApplication(moduleID, serverName);
113         }
114     }
115
116     /* Start ejb module */
117     private void startEJBModule(String JavaDoc moduleID, String JavaDoc serverName)
118         throws MBeanException {
119         try {
120             ManagedStandaloneJ2EEEjbJarModule msejbModule = new ManagedStandaloneJ2EEEjbJarModule(serverName,
121                     moduleID);
122             msejbModule.start();
123         } catch (Exception JavaDoc e) {
124             throw new MBeanException(e);
125         }
126     }
127
128     /* Stop ejb module */
129     private void stopEJBModule(String JavaDoc moduleID, String JavaDoc serverName)
130         throws MBeanException {
131
132         try {
133             ManagedStandaloneJ2EEEjbJarModule msejbModule = new ManagedStandaloneJ2EEEjbJarModule(serverName,
134                     moduleID);
135             msejbModule.stop();
136         } catch (Exception JavaDoc e) {
137             throw new MBeanException(e);
138         }
139     }
140
141     /* Start web module */
142     private void startWEBModule(String JavaDoc moduleID, String JavaDoc serverName)
143         throws MBeanException {
144
145         try {
146             ManagedStandaloneJ2EEWebModule mswebModule = new ManagedStandaloneJ2EEWebModule(serverName,
147                     moduleID);
148             mswebModule.start();
149         } catch (Exception JavaDoc e) {
150             throw new MBeanException(e);
151         }
152     }
153
154     /* Stop web module */
155     private void stopWEBModule(String JavaDoc moduleID, String JavaDoc serverName)
156         throws MBeanException {
157
158         try {
159             ManagedStandaloneJ2EEWebModule mswebModule = new ManagedStandaloneJ2EEWebModule(serverName,
160                     moduleID);
161             mswebModule.stop();
162         } catch (Exception JavaDoc e) {
163             throw new MBeanException(e);
164         }
165     }
166
167     /* Start connector module */
168     private void startRARModule(String JavaDoc moduleID, String JavaDoc serverName)
169         throws MBeanException {
170
171         try {
172             ManagedStandaloneConnectorModule mscModule = new ManagedStandaloneConnectorModule(serverName,
173                     moduleID);
174             mscModule.start();
175         } catch (Exception JavaDoc e) {
176             throw new MBeanException(e);
177         }
178     }
179
180     /* Stop connector module */
181     private void stopRARModule(String JavaDoc moduleID, String JavaDoc serverName)
182         throws MBeanException {
183
184         try {
185             ManagedStandaloneConnectorModule mscModule = new ManagedStandaloneConnectorModule(serverName,
186                     moduleID);
187             mscModule.stop();
188         } catch (Exception JavaDoc e) {
189             throw new MBeanException(e);
190         }
191     }
192
193     /* Start application */
194     private void startApplication(String JavaDoc appID, String JavaDoc serverName)
195         throws MBeanException {
196
197         try {
198             ManagedJ2EEApplication mApp = new ManagedJ2EEApplication(serverName,
199                     appID);
200             mApp.start();
201         } catch (Exception JavaDoc e) {
202             throw new MBeanException(e);
203         }
204     }
205
206     /* Stop application */
207     private void stopApplication(String JavaDoc appID, String JavaDoc serverName)
208         throws MBeanException {
209
210         try {
211             ManagedJ2EEApplication mApp = new ManagedJ2EEApplication(serverName,
212                     appID);
213             mApp.stop();
214         } catch (Exception JavaDoc e) {
215             throw new MBeanException(e);
216         }
217     }
218
219     /* Is it a stand-alone module or part of application */
220     private boolean standAlone(J2EEDeployedObjectMdl modObject)
221         throws MBeanException {
222
223         try {
224             ObjectName objName = new ObjectName(modObject.getobjectName());
225             String JavaDoc appName = objName.getKeyProperty("J2EEApplication");
226
227             if ((appName == null) || (appName.length() < 1) ||
228                     (appName.equals("null")) || (appName.equals("NULL")) ||
229                     (appName.equals(""))) {
230                 return true;
231             }
232         } catch (Exception JavaDoc e) {
233             throw new MBeanException(e);
234         }
235
236         return false;
237     }
238 }
239
Popular Tags