001: package com.bostechcorp.cbesb.console.jmxclient;
002:
003: import java.io.FileInputStream;
004: import java.io.FileNotFoundException;
005: import java.io.IOException;
006: import java.io.InputStream;
007: import java.net.MalformedURLException;
008: import java.util.HashMap;
009: import java.util.Map;
010: import java.util.Properties;
011: import java.util.Set;
012: import java.util.Vector;
013:
014: import javax.management.MalformedObjectNameException;
015: import javax.management.ObjectName;
016: import javax.management.remote.JMXConnector;
017: import javax.management.remote.JMXConnectorFactory;
018: import javax.management.remote.JMXServiceURL;
019:
020: import org.apache.servicemix.jbi.framework.ComponentStatsMBean;
021:
022: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
023: import com.bostechcorp.cbesb.common.i18n.Messages;
024: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
025: import com.bostechcorp.cbesb.console.common.ServerSideException;
026:
027: //import com.bostechcorp.cbesb.runtime.ccsl.lib.ChainbuilderEsbExtension;
028: //import com.bostechcorp.cbesb.runtime.ccsl.lib.ChainbuilderEsbExtensionMBean;
029:
030: public class ServicemixJmxClient extends BaseJmxClient {
031: public static final String JMX_PROPERTY_FILE_NAME = "jmx.properties";
032: public static final String JMX_SERVICE_URL = "JMXServiceURL";
033: public static final String JMX_USER = "user";
034: public static final String JMX_PASSWORD = "password";
035:
036: private Properties properties;
037:
038: /*
039: * The constructor will establish an MBeanServer connection if it is
040: * successful.
041: */
042: public ServicemixJmxClient() throws Exception {
043: properties = getJmxPropertiesFromFile();
044: init("0", properties.getProperty(JMX_USER), properties
045: .getProperty(JMX_PASSWORD));
046: }
047:
048: /*
049: * Gets lists of Binding Components, Service Engines and Shared Libraries currently installed
050: * (non-Javadoc)
051: * @see com.bostechcorp.cbesb.console.jmxclient.BaseJmxClient#getSharedLibraryNames()
052: */
053: @SuppressWarnings("unchecked")
054: public String[] getSharedLibraryNames() throws ServerSideException {
055: Set<ObjectName> allObjNames;
056: try {
057: allObjNames = getServerConnection().queryNames(null, null);
058: } catch (IOException e) {
059: throw new ServerSideException((Messages
060: .get(CoreMessageConstants.NO_JMX_SERVER_ERROR)), e);
061: }
062: Vector<String> slNameVec = new Vector<String>();
063: for (ObjectName name : allObjNames) {
064: String strName = name.toString();
065: if (strName
066: .matches("org.apache.servicemix:.*Type=SharedLibrary.*"))
067: slNameVec.add(name.getKeyProperty("Name"));
068: }
069: return slNameVec.toArray(new String[0]);
070: }
071:
072: protected ObjectName getAdminServiceMbeanName()
073: throws MalformedObjectNameException {
074: return new ObjectName(
075: "org.apache.servicemix:ContainerName=ServiceMix,Type=SystemService,Name=ManagementContext");
076: }
077:
078: protected ObjectName getDeploymentServiceMbeanName()
079: throws MalformedObjectNameException {
080: return new ObjectName(
081: "org.apache.servicemix:ContainerName=ServiceMix,Type=SystemService,Name=DeploymentService");
082: }
083:
084: protected ObjectName getInstallationServiceMbeanName()
085: throws MalformedObjectNameException {
086: return new ObjectName(
087: "org.apache.servicemix:ContainerName=ServiceMix,Type=SystemService,Name=InstallationService");
088: }
089:
090: protected ObjectName getRegistryMbeanName()
091: throws MalformedObjectNameException {
092: return new ObjectName(
093: "org.apache.servicemix:ContainerName=ServiceMix,Type=SystemService,Name=Registry");
094: }
095:
096: protected ObjectName getInstallerMbeanName(String componentName)
097: throws MalformedObjectNameException {
098: // org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name=ChainBuilderESB-SE-Sequencing,SubType=Installer
099: return new ObjectName(
100: "org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name="
101: + componentName + ",SubType=Installer");
102: }
103:
104: public ObjectName getLifeCycleMbeanName(String componentName)
105: throws MalformedObjectNameException {
106: return new ObjectName(
107: "org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name="
108: + componentName + ",SubType=LifeCycle");
109: }
110:
111: public ObjectName getLifeCycleExtensionMbeanName(
112: String componentName) throws MalformedObjectNameException {
113: return new ObjectName(
114: "org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name="
115: + componentName + ",SubType=LifeCycleExtension");
116: }
117:
118: protected ObjectName getServiceUnitLifeCycleMbeanName(
119: String serviceUintName, String componentName)
120: throws MalformedObjectNameException {
121: return new ObjectName(
122: "org.apache.servicemix:ContainerName=ServiceMix,Type=ServiceUnit,Name="
123: + serviceUintName + ",SubType=" + componentName);
124: }
125:
126: protected ObjectName getSharedLibraryMbeanName(String libName)
127: throws MalformedObjectNameException {
128: return new ObjectName(
129: "org.apache.servicemix:ContainerName=ServiceMix,Type=SharedLibrary,Name="
130: + libName);
131: }
132:
133: protected ObjectName getSharedLibraryInstallerMbeanName(
134: String libName) throws MalformedObjectNameException {
135: // org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name=ChainBuilderESB-SE-Sequencing,SubType=Installer
136: return new ObjectName(
137: "org.apache.servicemix:ContainerName=ServiceMix,Type=SharedLibrary,Name="
138: + libName + ",SubType=Installer");
139: }
140:
141: public JMXServiceURL getServiceUrl() throws MalformedURLException {
142: //JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + "localhost" + ":" + port + "/jmxrmi");
143: JMXServiceURL url = new JMXServiceURL(properties
144: .getProperty(JMX_SERVICE_URL));
145: return url;
146: }
147:
148: public JMXConnector getJmxConnector(JMXServiceURL url)
149: throws ServerSideException {
150: log.info("Connecting to JBI Container at: " + url);
151: Map<String, String[]> m = new HashMap<String, String[]>();
152: String[] credInfo = new String[] { user, password };
153: m.put("jmx.remote.credentials", credInfo);
154: try {
155: return JMXConnectorFactory.connect(url, m);
156: } catch (IOException e) {
157: throw new ServerSideException(Messages
158: .get(CoreMessageConstants.NO_JMX_SERVER_ERROR), e);
159: }
160: }
161:
162: /**
163: * Reads the JMX properties from jmx.properties File
164: * @return
165: * @throws FileNotFoundException
166: * @throws IOException
167: */
168: public static Properties getJmxPropertiesFromFile()
169: throws FileNotFoundException, IOException {
170: Properties result = new Properties();
171: InputStream inStream;
172: try {
173: inStream = new FileInputStream(EsbPathHelper
174: .getCbesbHomeDir()
175: + "/runtime/console/config/"
176: + JMX_PROPERTY_FILE_NAME);
177: } catch (FileNotFoundException e) {
178: inStream = ServicemixJmxClient.class.getClassLoader()
179: .getResourceAsStream(JMX_PROPERTY_FILE_NAME);
180: if (inStream == null) {
181: //if the classloader also does not find the resource then
182: //the file really does not exist; throw the caught exception.
183: //actually the file will always exist in source it should exist
184: throw e;
185: }
186: }
187: result.load(inStream);
188: return result;
189: }
190:
191: /**
192: * @return the properties
193: */
194: public Properties getProperties() {
195: return properties;
196: }
197:
198: /**
199: * @param properties the properties to set
200: */
201: public void setProperties(Properties properties) {
202: this.properties = properties;
203: }
204: }
|