001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ToolsRuntimeService.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.runtime;
030:
031: import javax.jbi.JBIException;
032: import javax.management.MBeanServer;
033: import javax.management.StandardMBean;
034:
035: import com.sun.esb.management.api.administration.AdministrationService;
036: import com.sun.esb.management.api.configuration.ConfigurationService;
037: import com.sun.esb.management.api.deployment.DeploymentService;
038: import com.sun.esb.management.api.installation.InstallationService;
039: import com.sun.esb.management.api.performance.PerformanceMeasurementService;
040: import com.sun.esb.management.api.runtime.RuntimeManagementService;
041: import com.sun.jbi.EnvironmentContext;
042: import com.sun.jbi.ServiceLifecycle;
043: import com.sun.jbi.ui.common.JBIJMXObjectNames;
044: import com.sun.jbi.ui.runtime.mbeans.JBIAdminCommandsUIMBean;
045: import com.sun.jbi.ui.runtime.mbeans.UIMBeanFactory;
046:
047: /**
048: * Tools Runtime as a JBI Internal service
049: *
050: * @author graj
051: */
052: public class ToolsRuntimeService implements ServiceLifecycle {
053: /** context */
054: private EnvironmentContext mEnvContext;
055:
056: /** Creates a new instance of ToolsRuntimeService */
057: public ToolsRuntimeService() {
058: this .mEnvContext = null;
059: }
060:
061: /**
062: * inits service
063: *
064: * @param aContext
065: * contex
066: * @throws JBIException
067: * on error
068: */
069: public void initService(EnvironmentContext aContext)
070: throws JBIException {
071: this .mEnvContext = aContext;
072: }
073:
074: /**
075: * starts service
076: *
077: * @throws JBIException
078: * on error
079: */
080: public void startService() throws JBIException {
081: // register the ui mbeans here
082: registerJavaCAPSManagementServiceMBeans();
083: registerJbiAdminUiMBeans();
084: // other initialization here.
085: }
086:
087: /**
088: * stops service
089: *
090: * @throws JBIException
091: * on error
092: */
093: public void stopService() throws JBIException {
094: // unregister the ui mbeans here
095: unregisterJbiAdminUiMBeans();
096: unregisterJavaCAPSManagementServiceMBeans();
097: // other release of resources here.
098: }
099:
100: /**
101: * registers the ui mbeans
102: *
103: * @throws JBIException
104: * on error
105: */
106: private void registerJbiAdminUiMBeans() throws JBIException {
107: MBeanServer mbeanServer = null;
108: JBIAdminCommandsUIMBean jbiAdminCommandsUIMBeanImpl = null;
109: StandardMBean mbean = null;
110: try {
111: mbeanServer = this .mEnvContext.getMBeanServer();
112: } catch (Exception ex) {
113:
114: throw new JBIException(ex);
115: }
116:
117: try {
118: // ///////////////////////////////////////////
119: // -- The Original ESB MBean --
120: // ///////////////////////////////////////////
121: jbiAdminCommandsUIMBeanImpl = this
122: .createJBIAdminCommandsUIMBean(this .mEnvContext);
123:
124: mbean = new StandardMBean(jbiAdminCommandsUIMBeanImpl,
125: JBIAdminCommandsUIMBean.class);
126:
127: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
128: .getJbiAdminUiMBeanObjectName());
129:
130: } catch (Exception ex) {
131:
132: throw new JBIException(ex);
133: }
134:
135: try {
136: // ///////////////////////////////////////////
137: // -- The Reference Implementation MBean --
138: // ///////////////////////////////////////////
139: jbiAdminCommandsUIMBeanImpl = this
140: .createReferenceJBIAdminCommandsUIMBean(this .mEnvContext);
141:
142: mbean = new StandardMBean(jbiAdminCommandsUIMBeanImpl,
143: JBIAdminCommandsUIMBean.class);
144:
145: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
146: .getJbiReferenceAdminUiMBeanObjectName());
147:
148: } catch (Exception ex) {
149:
150: throw new JBIException(ex);
151: }
152: }
153:
154: /**
155: * unregisters the ui mbean
156: *
157: * @throws JBIException
158: * on error
159: */
160: private void unregisterJbiAdminUiMBeans() throws JBIException {
161: MBeanServer mbeanServer = null;
162: try {
163: // ///////////////////////////////////////////
164: // -- The Original ESB MBean --
165: // ///////////////////////////////////////////
166: mbeanServer = this .mEnvContext.getMBeanServer();
167: } catch (Exception ex) {
168: throw new JBIException(ex);
169: }
170:
171: try {
172: mbeanServer.unregisterMBean(JBIJMXObjectNames
173: .getJbiAdminUiMBeanObjectName());
174: } catch (Exception ex) {
175: throw new JBIException(ex);
176: }
177:
178: try {
179: // ///////////////////////////////////////////
180: // -- The Reference Implementation MBean --
181: // ///////////////////////////////////////////
182: mbeanServer.unregisterMBean(JBIJMXObjectNames
183: .getJbiReferenceAdminUiMBeanObjectName());
184: } catch (Exception ex) {
185: throw new JBIException(ex);
186: }
187:
188: }
189:
190: /**
191: * registers the Java CAPS Common Management MBeans
192: *
193: * @throws JBIException
194: * on error
195: */
196: private void registerJavaCAPSManagementServiceMBeans()
197: throws JBIException {
198: MBeanServer mbeanServer = null;
199: AdministrationService administrationServiceMBeanImpl = null;
200: ConfigurationService configurationServiceMBeanImpl = null;
201: DeploymentService deploymentServiceMBeanImpl = null;
202: InstallationService installationServiceMBeanImpl = null;
203: RuntimeManagementService runtimeManagementMBeanImpl = null;
204: PerformanceMeasurementService performanceMeasurementMBeanImpl = null;
205:
206: StandardMBean mbean = null;
207: try {
208: mbeanServer = this .mEnvContext.getMBeanServer();
209: } catch (Exception ex) {
210: throw new JBIException(ex);
211: }
212:
213: try {
214: // ///////////////////////////////////////////
215: // -- The Administration Service MBean --
216: // ///////////////////////////////////////////
217: administrationServiceMBeanImpl = this
218: .createJavaCAPSAdministrationServiceMBean(this .mEnvContext);
219: mbean = new StandardMBean(administrationServiceMBeanImpl,
220: AdministrationService.class);
221: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
222: .getJavaCapsAdministrationServiceMBeanObjectName());
223: } catch (Exception ex) {
224: throw new JBIException(ex);
225: }
226:
227: try {
228: // ///////////////////////////////////////////
229: // -- The Configuration Service MBean --
230: // ///////////////////////////////////////////
231: configurationServiceMBeanImpl = this
232: .createJavaCAPSConfigurationServiceMBean(this .mEnvContext);
233: mbean = new StandardMBean(configurationServiceMBeanImpl,
234: ConfigurationService.class);
235: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
236: .getJavaCapsConfigurationServiceMBeanObjectName());
237: } catch (Exception ex) {
238: throw new JBIException(ex);
239: }
240:
241: try {
242: // ///////////////////////////////////////////
243: // -- The Deployment Service MBean --
244: // ///////////////////////////////////////////
245: deploymentServiceMBeanImpl = this
246: .createJavaCAPSDeploymentServiceMBean(this .mEnvContext);
247: mbean = new StandardMBean(deploymentServiceMBeanImpl,
248: DeploymentService.class);
249: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
250: .getJavaCapsDeploymentServiceMBeanObjectName());
251: } catch (Exception ex) {
252: throw new JBIException(ex);
253: }
254:
255: try {
256: // ///////////////////////////////////////////
257: // -- The Installation Service MBean --
258: // ///////////////////////////////////////////
259: installationServiceMBeanImpl = this
260: .createJavaCAPSInstallationServiceMBean(this .mEnvContext);
261: mbean = new StandardMBean(installationServiceMBeanImpl,
262: InstallationService.class);
263: mbeanServer.registerMBean(mbean, JBIJMXObjectNames
264: .getJavaCapsInstallationServiceMBeanObjectName());
265: } catch (Exception ex) {
266: throw new JBIException(ex);
267: }
268:
269: try {
270: // ////////////////////////////////////////////////
271: // -- The Runtime Management Service MBean --
272: // ////////////////////////////////////////////////
273: runtimeManagementMBeanImpl = this
274: .createJavaCAPSRuntimeManagementServiceMBean(this .mEnvContext);
275: mbean = new StandardMBean(runtimeManagementMBeanImpl,
276: RuntimeManagementService.class);
277: mbeanServer
278: .registerMBean(
279: mbean,
280: JBIJMXObjectNames
281: .getJavaCapsRuntimeManagementServiceMBeanObjectName());
282: } catch (Exception ex) {
283: throw new JBIException(ex);
284: }
285:
286: try {
287: // ////////////////////////////////////////////////
288: // -- The Performance Measurement Service MBean --
289: // ////////////////////////////////////////////////
290: performanceMeasurementMBeanImpl = this
291: .createJavaCAPSPerformanceMeasurementServiceMBean(this .mEnvContext);
292: mbean = new StandardMBean(performanceMeasurementMBeanImpl,
293: PerformanceMeasurementService.class);
294: mbeanServer
295: .registerMBean(
296: mbean,
297: JBIJMXObjectNames
298: .getJavaCapsPerformanceMeasurementServiceMBeanObjectName());
299: } catch (Exception ex) {
300: throw new JBIException(ex);
301: }
302: }
303:
304: /**
305: * unregisters the Java CAPS Common Management MBeans
306: *
307: * @throws JBIException
308: * on error
309: */
310: private void unregisterJavaCAPSManagementServiceMBeans()
311: throws JBIException {
312: MBeanServer mbeanServer = null;
313: try {
314: mbeanServer = this .mEnvContext.getMBeanServer();
315: } catch (Exception ex) {
316: throw new JBIException(ex);
317: }
318:
319: try {
320: mbeanServer.unregisterMBean(JBIJMXObjectNames
321: .getJavaCapsAdministrationServiceMBeanObjectName());
322: } catch (Exception ex) {
323: throw new JBIException(ex);
324: }
325:
326: try {
327: mbeanServer.unregisterMBean(JBIJMXObjectNames
328: .getJavaCapsConfigurationServiceMBeanObjectName());
329: } catch (Exception ex) {
330: throw new JBIException(ex);
331: }
332:
333: try {
334: mbeanServer.unregisterMBean(JBIJMXObjectNames
335: .getJavaCapsDeploymentServiceMBeanObjectName());
336: } catch (Exception ex) {
337: throw new JBIException(ex);
338: }
339:
340: try {
341: mbeanServer.unregisterMBean(JBIJMXObjectNames
342: .getJavaCapsInstallationServiceMBeanObjectName());
343: } catch (Exception ex) {
344: throw new JBIException(ex);
345: }
346:
347: try {
348: mbeanServer
349: .unregisterMBean(JBIJMXObjectNames
350: .getJavaCapsRuntimeManagementServiceMBeanObjectName());
351: } catch (Exception ex) {
352: throw new JBIException(ex);
353: }
354:
355: try {
356: mbeanServer
357: .unregisterMBean(JBIJMXObjectNames
358: .getJavaCapsPerformanceMeasurementServiceMBeanObjectName());
359: } catch (Exception ex) {
360: throw new JBIException(ex);
361: }
362: }
363:
364: /**
365: * Create Java CAPS Common Management Service MBean
366: * @param aContext
367: * @return
368: * @throws JBIException
369: */
370: protected ConfigurationService createJavaCAPSConfigurationServiceMBean(
371: EnvironmentContext aContext) throws JBIException {
372: return UIMBeanFactory.getInstance()
373: .createJavaCAPSConfigurationServiceMBean(aContext);
374: }
375:
376: /**
377: * Create Java CAPS Common Management Service MBean
378: * @param aContext
379: * @return
380: * @throws JBIException
381: */
382: protected DeploymentService createJavaCAPSDeploymentServiceMBean(
383: EnvironmentContext aContext) throws JBIException {
384: return UIMBeanFactory.getInstance()
385: .createJavaCAPSDeploymentServiceMBean(aContext);
386: }
387:
388: /**
389: * Create Java CAPS Common Management Service MBean
390: * @param aContext
391: * @return
392: * @throws JBIException
393: */
394: protected InstallationService createJavaCAPSInstallationServiceMBean(
395: EnvironmentContext aContext) throws JBIException {
396: return UIMBeanFactory.getInstance()
397: .createJavaCAPSInstallationServiceMBean(aContext);
398: }
399:
400: /**
401: * Create Java CAPS Common Management Service MBean
402: * @param aContext
403: * @return
404: * @throws JBIException
405: */
406: protected RuntimeManagementService createJavaCAPSRuntimeManagementServiceMBean(
407: EnvironmentContext aContext) throws JBIException {
408: return UIMBeanFactory.getInstance()
409: .createJavaCAPSRuntimeManagementServiceMBean(aContext);
410: }
411:
412: /**
413: * Create Java CAPS Common Management Service MBean
414: * @param aContext
415: * @return
416: * @throws JBIException
417: */
418: protected PerformanceMeasurementService createJavaCAPSPerformanceMeasurementServiceMBean(
419: EnvironmentContext aContext) throws JBIException {
420: return UIMBeanFactory.getInstance()
421: .createJavaCAPSPerformanceMeasurementServiceMBean(
422: aContext);
423: }
424:
425: /**
426: * Create Java CAPS Common Management Service MBean
427: * @param aContext
428: * @return
429: * @throws JBIException
430: */
431: protected AdministrationService createJavaCAPSAdministrationServiceMBean(
432: EnvironmentContext aContext) throws JBIException {
433: return UIMBeanFactory.getInstance()
434: .createJavaCAPSAdministrationServiceMBean(aContext);
435: }
436:
437: /**
438: *
439: * @param aContext
440: * @return
441: * @throws JBIException
442: */
443: protected JBIAdminCommandsUIMBean createJBIAdminCommandsUIMBean(
444: EnvironmentContext aContext) throws JBIException {
445: return UIMBeanFactory.getInstance()
446: .createJBIAdminCommandsUIMBean(aContext);
447: }
448:
449: /**
450: * The Reference Implementation MBean
451: *
452: * @param aContext
453: * @return
454: * @throws JBIException
455: */
456: protected JBIAdminCommandsUIMBean createReferenceJBIAdminCommandsUIMBean(
457: EnvironmentContext aContext) throws JBIException {
458: return UIMBeanFactory.getReferenceInstance()
459: .createJBIAdminCommandsUIMBean(aContext);
460: }
461: }
|