KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ManagedStandaloneConnectorModule


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
24 package com.sun.enterprise.admin.server.core.mbean.config;
25
26 //JMX imports
27
import javax.management.Attribute JavaDoc;
28
29 //Config imports
30
import com.sun.enterprise.config.ConfigException;
31 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
32 import com.sun.enterprise.config.serverbeans.ServerTags;
33 import com.sun.enterprise.config.serverbeans.EjbModule;
34
35 //Admin imports
36
import com.sun.enterprise.admin.common.ObjectNames;
37 import com.sun.enterprise.admin.common.EntityStatus;
38 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
39 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
40 import com.sun.enterprise.admin.common.exception.J2EEConnectorModuleException;
41
42 //for jsr77
43
import com.sun.enterprise.instance.InstanceEnvironment;
44 import com.sun.enterprise.admin.event.AdminEvent;
45 import com.sun.enterprise.admin.event.AdminEventCache;
46 import com.sun.enterprise.admin.event.AdminEventResult;
47 import com.sun.enterprise.admin.event.ModuleDeployEvent;
48 import com.sun.enterprise.admin.event.BaseDeployEvent;
49 import com.sun.enterprise.admin.event.AdminEventMulticaster;
50 import com.sun.enterprise.admin.server.core.channel.RMIClient;
51 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
52 import com.sun.enterprise.admin.common.Status;
53 import com.sun.enterprise.admin.common.MBeanServerFactory;
54 import javax.management.MBeanServer JavaDoc;
55 import javax.management.ObjectName JavaDoc;
56 import com.sun.enterprise.server.ApplicationServer;
57 import com.sun.enterprise.server.ServerContext;
58
59
60 /**
61     A class that represents a Standalone Managed J2EE Connector module. Note that this is a
62     standalone J2EE module, because it is deployed independently and not
63     as a part of an application. Such a Connector Module has certain additional
64     manageable interface.
65     <p>
66     When a Connector is deployed, an instance of this MBean is created in
67     the MBeanServer. The MBean is deregistered when the module is removed.
68     <p>
69     ObjectName of this MBean is:
70         ias:type=StandaloneConnectorModule, ModuleName=<moduleName>
71 */

72
73 public class ManagedStandaloneConnectorModule extends ConfigMBeanBase
74     implements ConfigAttributeName.StandaloneConnectorModule
75 {
76     private static final String JavaDoc[][] MAPLIST =
77     {
78         {kName , ATTRIBUTE + ServerTags.NAME},
79         {kLocation , ATTRIBUTE + ServerTags.LOCATION},
80 //ms1 {kEnabled , ATTRIBUTE + ServerTags.ENABLED},
81
{kDescription , ATTRIBUTE + PSEUDO_ATTR_DESCRIPTION},
82     };
83
84     private static final String JavaDoc[] ATTRIBUTES =
85     {
86         kName + ", String, R" ,
87         kLocation + ", String, RW" ,
88 //ms1 kEnabled + ", boolean, RW" ,
89
kDescription + ", String, RW" ,
90     };
91
92     private static final String JavaDoc[] OPERATIONS =
93     {
94         "getStatus(), INFO",
95         "enable(), ACTION",
96         "disable(), ACTION",
97         "start(), ACTION",
98         "stop(), ACTION",
99         "getState(), INFO"
100     };
101
102     /**
103         Default constructor sets MBean description tables
104     */

105     public ManagedStandaloneConnectorModule() throws MBeanConfigException
106     {
107         this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
108     }
109
110     public ManagedStandaloneConnectorModule(String JavaDoc instanceName, String JavaDoc moduleName)
111         throws MBeanConfigException
112     {
113         this(); //set description tables
114
initialize(ObjectNames.kConnectorModule, new String JavaDoc[]{instanceName, moduleName});
115     }
116     /**
117      * Returns the Status of this module.
118      * @throws J2EEConnectorModuleException if the status can't be retrieved.
119     */

120     public EntityStatus getStatus() throws J2EEConnectorModuleException
121     {
122         EntityStatus status = null;
123         try
124         {
125             boolean isModuleEnabled = true; //FIXME for RI only
126
// Object value = super.getAttribute(kEnabled);
127
// boolean isModuleEnabled = ((Boolean)value).booleanValue();
128
status = new EntityStatus();
129             if (isModuleEnabled)
130             {
131                 status.setEnabled();
132             }
133             else
134             {
135                 status.setDisabled();
136             }
137         }
138         catch (Exception JavaDoc e)
139         {
140             sLogger.throwing(getClass().getName(), "getStatus", e);
141             throw new J2EEConnectorModuleException(e.getMessage());
142         }
143         return status;
144     }
145
146     /**
147      * Disables this module.
148      * @throws J2EEConnectorModuleException if there is some error during
149      * disabling.
150     */

151     public void disable() throws J2EEConnectorModuleException
152     {
153         return; //FIXME for RI only;
154
/* try
155         {
156             super.setAttribute(new Attribute(kEnabled, new Boolean(false)));
157             super.getConfigContext().flush();
158         }
159         catch (Exception e)
160         {
161             sLogger.throwing(getClass().getName(), "disable", e);
162             throw new J2EEConnectorModuleException(e.getMessage());
163         }
164 */

165     }
166
167
168     /**
169      * Disables the application. Difference between this method
170      * and disable is persistence of the state. Disable method persists
171      * the state and this method does not persist the state.
172      */

173     public void stop() throws J2EEConnectorModuleException {
174         try {
175             String JavaDoc moduleName = (String JavaDoc)this.getAttribute(kName);
176             multicastAdminEvent(moduleName, BaseDeployEvent.DISABLE);
177         } catch (Exception JavaDoc e) {
178             sLogger.throwing(getClass().getName(), "stop", e);
179             throw new J2EEConnectorModuleException(e.getMessage());
180         }
181     }
182
183     /**
184      * Gets the jsr77 state corresponding to this module
185      */

186     public Integer JavaDoc getState() throws J2EEConnectorModuleException {
187         try {
188             String JavaDoc moduleName = (String JavaDoc)this.getAttribute(kName);
189             MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
190             ServerContext serverContext = ApplicationServer.getServerContext();
191             ObjectName JavaDoc objName = new ObjectName JavaDoc(
192                 serverContext.getDefaultDomainName() + ":" +
193                 "j2eeType=ResourceAdapterModule," +
194                 "name=" + ((String JavaDoc)this.getAttribute(kName)) + "," +
195         "J2EEApplication=" + "null" + "," +
196         "J2EEServer=" + serverContext.getInstanceName());
197             Integer JavaDoc intObj = (Integer JavaDoc) mbs.getAttribute(objName, "state");
198         return intObj;
199         } catch (Exception JavaDoc e) {
200             sLogger.throwing(getClass().getName(), "getState", e);
201             throw new J2EEConnectorModuleException(e.getMessage());
202         }
203     }
204
205
206
207     /**
208      * Enables this module.
209      * @throws J2EEConnectorModuleException if there is some error during
210      * enablement.
211     */

212     public void enable() throws J2EEConnectorModuleException
213     {
214         return; //FIXME for RI only;
215
/* try
216         {
217             super.setAttribute(new Attribute(kEnabled, new Boolean(true)));
218             super.getConfigContext().flush();
219         }
220         catch (Exception e)
221         {
222             sLogger.throwing(getClass().getName(), "enable", e);
223             throw new J2EEConnectorModuleException(e.getMessage());
224         }
225 */

226     }
227
228     /**
229      * Enables the application. Difference between this method
230      * and enable is persistence of the state. Enable method persists
231      * the state and this method does not persist the state.
232      */

233     public void start() throws J2EEConnectorModuleException {
234         try {
235             String JavaDoc moduleName = (String JavaDoc)this.getAttribute(kName);
236             multicastAdminEvent(moduleName, BaseDeployEvent.ENABLE);
237         } catch (Exception JavaDoc e) {
238             sLogger.throwing(getClass().getName(), "start", e);
239             throw new J2EEConnectorModuleException(e.getMessage());
240         }
241     }
242
243     /**
244      * Multicasts the admin event so that the application gets loaded
245      * dynamically without the need for reconfig.
246      */

247     private void multicastAdminEvent(String JavaDoc entityName, String JavaDoc actionCode)
248                         throws J2EEConnectorModuleException {
249         String JavaDoc instanceName = super.getServerInstanceName();
250         InstanceEnvironment instEnv = new InstanceEnvironment(instanceName);
251         /*
252         try {
253                 instEnv.applyServerXmlChanges(false);
254         } catch (Exception e) {
255             sLogger.throwing(getClass().getName(), "getBeansByType", e);
256             throw new J2EEConnectorModuleException(e.getMessage());
257         }
258          **/

259         AdminEvent event = new ModuleDeployEvent(instanceName, entityName,
260                                 ModuleDeployEvent.TYPE_CONNECTOR, actionCode);
261         //AdminEventCache.populateConfigChange(super.getConfigContext(), event);
262
RMIClient serverInstancePinger = AdminChannel.getRMIClient(instanceName);
263         if (serverInstancePinger.getInstanceStatusCode() != Status.kInstanceRunningCode) {
264                     return;
265         }
266         AdminEventResult multicastResult = AdminEventMulticaster.multicastEvent(event);
267         if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) {
268                 AdminEventCache cache = AdminEventCache.getInstance(instanceName);
269                     cache.setRestartNeeded(true);
270         }
271     }
272 }
273
Popular Tags