KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > install > MBeanHelper


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.install;
24 import java.io.IOException JavaDoc;
25 import javax.management.InstanceNotFoundException JavaDoc;
26 import javax.management.MBeanException JavaDoc;
27 import javax.management.MBeanServerConnection JavaDoc;
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.ObjectInstance JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31 import javax.management.ReflectionException JavaDoc;
32 import javax.management.RuntimeMBeanException JavaDoc;
33 import javax.management.RuntimeOperationsException JavaDoc;
34 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
35
36 /**
37  *
38  * @author Manisha Umbarje
39  */

40 public class MBeanHelper {
41     
42     private static final String JavaDoc OBJ_NAME_PREFIX ="com.sun.jbi:JbiName=";
43     
44     private static final String JavaDoc SERVICE_NAME =",ServiceName=";
45     
46     private static final String JavaDoc CONTROL_TYPE =",ControlType=";
47     
48     private static final String JavaDoc COMPONENT_TYPE=",ComponentType=System";
49     
50     private static final String JavaDoc ADMIN_SERVICE_CONTROL_TYPE =
51             "AdministrationService";
52     
53     public static final String JavaDoc INSTALLATION_SERVICE = "InstallationService";
54     
55     public static final String JavaDoc ADMIN_SERVICE = "AdminService";
56     
57     public static final String JavaDoc CONFIGURATION_SERVICE = "Configuration";
58     
59     // Esb related MBeans
60

61     public static final String JavaDoc FRAMEWORK = "Framework";
62     
63     public static final String JavaDoc ESB_INSTALLATION_SERVICE =
64             "com.sun.jbi.esb:ServiceType=Installation";
65     
66     public static final String JavaDoc ESB_LIFECYCLE_SERVICE =
67             "com.sun.jbi.esb:ServiceType=LifeCycle";
68     
69     private MBeanServerConnection JavaDoc mbeanServer;
70     
71     /** Creates a new instance of ObjectNames */
72     public MBeanHelper(MBeanServerConnection JavaDoc mbeanServer) {
73         this.mbeanServer = mbeanServer;
74     }
75     
76     public ObjectName JavaDoc getObjectName(String JavaDoc domainName, String JavaDoc serviceName)
77     throws ServiceEngineException{
78         if(serviceName != null && domainName != null) {
79             String JavaDoc objName = OBJ_NAME_PREFIX + domainName + SERVICE_NAME;
80             String JavaDoc controlType = "";
81             if(serviceName.equals(INSTALLATION_SERVICE)) {
82                 controlType = serviceName;
83             } else if(serviceName.equals(ADMIN_SERVICE)) {
84                 controlType = ADMIN_SERVICE_CONTROL_TYPE;
85             } else if(serviceName.equals(FRAMEWORK)) {
86                 controlType = CONFIGURATION_SERVICE;
87             }
88             objName = objName + serviceName + CONTROL_TYPE +
89                     controlType + COMPONENT_TYPE;
90             return getObjectName(objName);
91         }
92         throw new ServiceEngineException("Either JBI Instance name or Service name or both null");
93     }
94     
95     public ObjectName JavaDoc getObjectName(String JavaDoc stringifiedObjName) throws ServiceEngineException {
96         
97         if(stringifiedObjName != null) {
98             try {
99                 ObjectInstance JavaDoc objInstance =
100                         mbeanServer.getObjectInstance(new ObjectName JavaDoc(stringifiedObjName));
101                 return objInstance.getObjectName();
102             } catch(MalformedObjectNameException JavaDoc e) {
103                 throw new ServiceEngineException(e.getMessage());
104             } catch(InstanceNotFoundException JavaDoc infe) {
105                 throw new ServiceEngineException(infe.getMessage());
106             } catch(IOException JavaDoc ioe) {
107                 throw new ServiceEngineException(ioe.getMessage());
108             }
109         } else
110             throw new ServiceEngineException(" Null object name");
111         
112     }
113     public Object JavaDoc invokeMBeanOperation(ObjectName JavaDoc objName,
114             String JavaDoc operationName, Object JavaDoc[] params, String JavaDoc[] signature)
115             throws ServiceEngineException {
116         Object JavaDoc result = null;
117         
118         try {
119             result = mbeanServer.invoke(objName,operationName,
120                     params, signature);
121         } catch (InstanceNotFoundException JavaDoc notFoundEx) {
122             throw new ServiceEngineException(notFoundEx);
123         } catch ( ReflectionException JavaDoc rEx){
124             throw new ServiceEngineException(rEx);
125         } catch ( MBeanException JavaDoc mbeanEx ) {
126             throw ServiceEngineException.filterExceptions(mbeanEx);
127         } catch (RuntimeMBeanException JavaDoc rtEx){
128             throw ServiceEngineException.filterExceptions(rtEx);
129         } catch (RuntimeOperationsException JavaDoc rtOpEx){
130             throw ServiceEngineException.filterExceptions(rtOpEx);
131         } catch (Exception JavaDoc ex ) {
132             throw ServiceEngineException.filterExceptions(ex);
133         }
134         
135         return result;
136         
137     }
138     
139     public boolean isMBeanRegistered(String JavaDoc mBeanName) throws ServiceEngineException {
140         try {
141             return mbeanServer.isRegistered(new ObjectName JavaDoc(mBeanName));
142         } catch(Exception JavaDoc ex) {
143             throw ServiceEngineException.filterExceptions(ex);
144         }
145     }
146     
147 }
148
Popular Tags