1 23 package com.sun.enterprise.jbi.serviceengine.install; 24 import java.io.IOException ; 25 import javax.management.InstanceNotFoundException ; 26 import javax.management.MBeanException ; 27 import javax.management.MBeanServerConnection ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectInstance ; 30 import javax.management.ObjectName ; 31 import javax.management.ReflectionException ; 32 import javax.management.RuntimeMBeanException ; 33 import javax.management.RuntimeOperationsException ; 34 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException; 35 36 40 public class MBeanHelper { 41 42 private static final String OBJ_NAME_PREFIX ="com.sun.jbi:JbiName="; 43 44 private static final String SERVICE_NAME =",ServiceName="; 45 46 private static final String CONTROL_TYPE =",ControlType="; 47 48 private static final String COMPONENT_TYPE=",ComponentType=System"; 49 50 private static final String ADMIN_SERVICE_CONTROL_TYPE = 51 "AdministrationService"; 52 53 public static final String INSTALLATION_SERVICE = "InstallationService"; 54 55 public static final String ADMIN_SERVICE = "AdminService"; 56 57 public static final String CONFIGURATION_SERVICE = "Configuration"; 58 59 61 public static final String FRAMEWORK = "Framework"; 62 63 public static final String ESB_INSTALLATION_SERVICE = 64 "com.sun.jbi.esb:ServiceType=Installation"; 65 66 public static final String ESB_LIFECYCLE_SERVICE = 67 "com.sun.jbi.esb:ServiceType=LifeCycle"; 68 69 private MBeanServerConnection mbeanServer; 70 71 72 public MBeanHelper(MBeanServerConnection mbeanServer) { 73 this.mbeanServer = mbeanServer; 74 } 75 76 public ObjectName getObjectName(String domainName, String serviceName) 77 throws ServiceEngineException{ 78 if(serviceName != null && domainName != null) { 79 String objName = OBJ_NAME_PREFIX + domainName + SERVICE_NAME; 80 String 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 getObjectName(String stringifiedObjName) throws ServiceEngineException { 96 97 if(stringifiedObjName != null) { 98 try { 99 ObjectInstance objInstance = 100 mbeanServer.getObjectInstance(new ObjectName (stringifiedObjName)); 101 return objInstance.getObjectName(); 102 } catch(MalformedObjectNameException e) { 103 throw new ServiceEngineException(e.getMessage()); 104 } catch(InstanceNotFoundException infe) { 105 throw new ServiceEngineException(infe.getMessage()); 106 } catch(IOException ioe) { 107 throw new ServiceEngineException(ioe.getMessage()); 108 } 109 } else 110 throw new ServiceEngineException(" Null object name"); 111 112 } 113 public Object invokeMBeanOperation(ObjectName objName, 114 String operationName, Object [] params, String [] signature) 115 throws ServiceEngineException { 116 Object result = null; 117 118 try { 119 result = mbeanServer.invoke(objName,operationName, 120 params, signature); 121 } catch (InstanceNotFoundException notFoundEx) { 122 throw new ServiceEngineException(notFoundEx); 123 } catch ( ReflectionException rEx){ 124 throw new ServiceEngineException(rEx); 125 } catch ( MBeanException mbeanEx ) { 126 throw ServiceEngineException.filterExceptions(mbeanEx); 127 } catch (RuntimeMBeanException rtEx){ 128 throw ServiceEngineException.filterExceptions(rtEx); 129 } catch (RuntimeOperationsException rtOpEx){ 130 throw ServiceEngineException.filterExceptions(rtOpEx); 131 } catch (Exception ex ) { 132 throw ServiceEngineException.filterExceptions(ex); 133 } 134 135 return result; 136 137 } 138 139 public boolean isMBeanRegistered(String mBeanName) throws ServiceEngineException { 140 try { 141 return mbeanServer.isRegistered(new ObjectName (mBeanName)); 142 } catch(Exception ex) { 143 throw ServiceEngineException.filterExceptions(ex); 144 } 145 } 146 147 } 148 | Popular Tags |