0001: package com.bostechcorp.cbesb.console.jmxclient;
0002:
0003: import java.io.File;
0004: import java.io.IOException;
0005: import java.net.MalformedURLException;
0006: import java.util.HashMap;
0007: import java.util.HashSet;
0008: import java.util.Iterator;
0009: import java.util.List;
0010: import java.util.Map;
0011: import java.util.Set;
0012: import java.util.Vector;
0013: import java.util.concurrent.ConcurrentHashMap;
0014: import java.util.concurrent.TimeUnit;
0015:
0016: import javax.jbi.management.AdminServiceMBean;
0017: import javax.jbi.management.DeploymentServiceMBean;
0018: import javax.jbi.management.InstallationServiceMBean;
0019: import javax.jbi.management.InstallerMBean;
0020: import javax.jbi.management.LifeCycleMBean;
0021: import javax.management.MBeanServerConnection;
0022: import javax.management.MBeanServerInvocationHandler;
0023: import javax.management.MalformedObjectNameException;
0024: import javax.management.Notification;
0025: import javax.management.ObjectInstance;
0026: import javax.management.ObjectName;
0027: import javax.management.remote.JMXConnector;
0028: import javax.management.remote.JMXServiceURL;
0029:
0030: import org.apache.commons.logging.Log;
0031: import org.apache.commons.logging.LogFactory;
0032:
0033: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
0034: import com.bostechcorp.cbesb.common.i18n.Messages;
0035: import com.bostechcorp.cbesb.common.util.runtimedb.vo.EndpointStatVO;
0036: import com.bostechcorp.cbesb.common.version.Version;
0037: import com.bostechcorp.cbesb.console.client.ConsoleVersion;
0038: import com.bostechcorp.cbesb.console.common.ExceptionUtil;
0039: import com.bostechcorp.cbesb.console.common.JmxAssemblyInfo;
0040: import com.bostechcorp.cbesb.console.common.JmxComponentInfo;
0041: import com.bostechcorp.cbesb.console.common.JmxConnectInfo;
0042: import com.bostechcorp.cbesb.console.common.JmxEndpointInfo;
0043: import com.bostechcorp.cbesb.console.common.ServerSideException;
0044: import com.bostechcorp.cbesb.console.common.ServiceAssemblyObj;
0045: import com.bostechcorp.cbesb.console.help.DeployInfo;
0046: import com.bostechcorp.cbesb.console.help.DeployObject;
0047: import com.bostechcorp.cbesb.console.pub.JmxAssemblyObj;
0048: import com.bostechcorp.cbesb.console.pub.JmxComponentObj;
0049: import com.bostechcorp.cbesb.console.pub.JmxEndpointObj;
0050: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.LifeCycleExtensionMBean;
0051: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.StateChangeNotification;
0052: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.StatisticChangeNotification;
0053:
0054: public abstract class BaseJmxClient implements JmxClient {
0055: static private String[] familiarDomains = { "org.apache.servicemix" };
0056:
0057: public final static String BOOTSTRAP_COMP = "ChainBuilderESB-SE-Bootstrap";
0058:
0059: protected static final String LIFE_CYCLE_EXTENSION_MBEAN_NAME = "com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.LifeCycleExtension";
0060:
0061: protected static final String ENDPOINT_MBEAN_NAME = "org.apache.servicemix.jbi.framework.Endpoint";
0062:
0063: static protected int SERVICEMIX_CONTAINER = 0;
0064:
0065: protected Log log = LogFactory.getLog(this .getClass());
0066:
0067: protected JMXConnector jmxConnector;
0068:
0069: //protected MBeanServerConnection mbsc;
0070:
0071: protected int containerType = -1;
0072:
0073: protected int port;
0074:
0075: protected String user;
0076:
0077: protected String password;
0078:
0079: protected String sessionId;
0080:
0081: static ConcurrentHashMap<String, SaClientListener> saListenerStatusMap = new ConcurrentHashMap<String, SaClientListener>();
0082: static ConcurrentHashMap<String, ClientListener> listenerStatusMap = new ConcurrentHashMap<String, ClientListener>();
0083: static ConcurrentHashMap<String, SaClientListener> saListenerStatisMap = new ConcurrentHashMap<String, SaClientListener>();
0084: static ConcurrentHashMap<String, ClientListener> listenerStatisMap = new ConcurrentHashMap<String, ClientListener>();
0085:
0086: public String getSessionId() {
0087: return sessionId;
0088: }
0089:
0090: public void setSessionId(String sessionId) {
0091: this .sessionId = sessionId;
0092: }
0093:
0094: /*
0095: * The constructor will establish an MBeanServer connection if it is
0096: * successful.
0097: */
0098: /**
0099: * Port is not neded anymore;
0100: * @deprecated
0101: */
0102: protected BaseJmxClient(String port, String user, String password)
0103: throws Exception {
0104: init(port, user, password);
0105: }
0106:
0107: /**
0108: * blank constructor; do whatever in super classes
0109: * @throws Exception
0110: */
0111: protected BaseJmxClient() throws Exception {
0112: super ();
0113: }
0114:
0115: /**
0116: * main constructor
0117: * @param user
0118: * @param password
0119: * @throws Exception
0120: * Since 1.2
0121: */
0122: protected BaseJmxClient(String user, String password)
0123: throws Exception {
0124: init("0", user, password);
0125: }
0126:
0127: public MBeanServerConnection getServerConnection()
0128: throws ServerSideException {
0129: try {
0130: return jmxConnector.getMBeanServerConnection();
0131: } catch (IOException ex) {
0132: // reconnect if not yet cnnected
0133:
0134: init("0", user, password);
0135:
0136: try {
0137: return jmxConnector.getMBeanServerConnection();
0138: } catch (IOException e) {
0139: throw new ServerSideException(
0140: (Messages
0141: .get(CoreMessageConstants.NO_JMX_SERVER_ERROR)),
0142: e);
0143: }
0144: }
0145: }
0146:
0147: protected void init(String port, String user, String password)
0148: throws ServerSideException {
0149: this .port = Integer.parseInt(port);
0150: this .user = user;
0151: this .password = password;
0152: try {
0153: jmxConnector = getJmxConnector(getServiceUrl());
0154: } catch (MalformedURLException e) {
0155: throw new ServerSideException(e);
0156: }
0157: MBeanServerConnection mbsc = getServerConnection();
0158: // look for a familiar domain to try and extrapolate the container that
0159: // we are attached to
0160: String[] domains;
0161: try {
0162: domains = mbsc.getDomains();
0163: } catch (IOException e) {
0164: throw new ServerSideException(e);
0165:
0166: }
0167: for (int i = 0; i < domains.length; i++) {
0168: for (int j = 0; j < familiarDomains.length; j++)
0169: if (domains[i].equals(familiarDomains[j])) {
0170: containerType = j;
0171: break;
0172: }
0173: if (containerType > -1)
0174: break;
0175: }
0176: }
0177:
0178: public void closeJmxConnection() {
0179: try {
0180: jmxConnector.close();
0181: } catch (IOException e) {
0182:
0183: e.printStackTrace();
0184: }
0185: }
0186:
0187: private Set differenceSet(Map map, String[] names) {
0188: Set<String> set1 = new HashSet<String>();
0189:
0190: Iterator it = map.keySet().iterator();
0191: while (it.hasNext())
0192: set1.add((String) it.next());
0193:
0194: Set<String> set2 = new HashSet<String>();
0195: for (int i = 0; i < names.length; i++)
0196: set2.add(names[i]);
0197: set1.removeAll(set2);
0198:
0199: Set<String> setNew = new HashSet<String>();
0200:
0201: Iterator itNew = set1.iterator();
0202: String name = "";
0203: while (itNew.hasNext()) {
0204: name = (String) itNew.next();
0205: DeployObject obj = (DeployObject) map.get(name);
0206: setNew.add(name + "#" + obj.getJarName());
0207: }
0208: return setNew;
0209: }
0210:
0211: private String[] getNamesBySet(Set set) {
0212: String[] installNames = new String[set.size()];
0213: Iterator it = set.iterator();
0214: int i = 0;
0215: while (it.hasNext()) {
0216: installNames[i] = (String) it.next();
0217: i++;
0218: }
0219: return installNames;
0220: }
0221:
0222: private String[] getRemoveComponents(Map map, String[] names) {
0223: // map<-> custom components
0224: // names <->run components
0225: String[] removeNames = null;
0226: for (int i = 0; i < names.length; i++) {
0227: map.remove(names[i]);
0228: }
0229: Iterator it = map.keySet().iterator();
0230: removeNames = new String[map.size()];
0231: int e = 0;
0232: String name, jarName;
0233: while (it.hasNext()) {
0234: name = (String) it.next();
0235: DeployObject obj = (DeployObject) map.get(name);
0236: jarName = obj.getJarName();
0237: removeNames[e] = name + "#" + jarName;
0238: e++;
0239: }
0240: return removeNames;
0241: }
0242:
0243: public String getCurrentState(String componentName)
0244: throws Exception {
0245: LifeCycleMBean lifeCycleProxy = (LifeCycleMBean) getProxy(
0246: getLifeCycleMbeanName(componentName),
0247: LifeCycleMBean.class);
0248: try {
0249: return lifeCycleProxy.getCurrentState();
0250: } catch (Exception ex) {
0251: throw new ServerSideException((Messages.get(
0252: (CoreMessageConstants.CAN_NOT_GET_STATE),
0253: componentName)), ex);
0254: }
0255: }
0256:
0257: /**
0258: * get all component for component->control view
0259: */
0260: public void getCurrentComponentList(JmxComponentInfo info)
0261: throws Exception {
0262:
0263: // This is non-standard so it is subclassed for the container
0264: info.setSharedLibraries(getSharedLibraryNames());
0265:
0266: // This is standard, JBI-compliant code
0267: AdminServiceMBean adminServiceProxy = (AdminServiceMBean) getProxy(
0268: getAdminServiceMbeanName(), AdminServiceMBean.class);
0269:
0270: ObjectName[] bcObjNames = adminServiceProxy
0271: .getBindingComponents();
0272: String[] bcNames = new String[bcObjNames.length];
0273: String[] bcStates = new String[bcObjNames.length];
0274: for (int i = 0; i < bcObjNames.length; i++) {
0275: bcNames[i] = bcObjNames[i].getKeyProperty("Name");
0276: bcStates[i] = this .getCurrentState(bcNames[i]);
0277: }
0278: info.setBindingComponents(bcNames);
0279: info.setBcStates(bcStates);
0280:
0281: ObjectName[] seObjNames = adminServiceProxy
0282: .getEngineComponents();
0283: String[] seNames = new String[seObjNames.length];
0284: String[] seStates = new String[seObjNames.length];
0285:
0286: for (int i = 0; i < seObjNames.length; i++) {
0287: seNames[i] = seObjNames[i].getKeyProperty("Name");
0288: seStates[i] = this .getCurrentState(seNames[i]);
0289: }
0290: info.setServiceEngines(seNames);
0291: info.setSeStates(seStates);
0292: }
0293:
0294: /**
0295: * get all installed components' objectName
0296: */
0297: public ObjectName[] getCurComponentObjectNames() throws Exception {
0298:
0299: // This is standard, JBI-compliant code
0300: AdminServiceMBean adminServiceProxy = (AdminServiceMBean) getProxy(
0301: getAdminServiceMbeanName(), AdminServiceMBean.class);
0302:
0303: ObjectName[] bcObjNames = adminServiceProxy
0304: .getBindingComponents();
0305: ObjectName[] seObjNames = adminServiceProxy
0306: .getEngineComponents();
0307: ObjectName[] objectNames = new ObjectName[bcObjNames.length
0308: + seObjNames.length];
0309: for (int i = 0; i < bcObjNames.length; i++) {
0310: objectNames[i] = bcObjNames[i];
0311: }
0312: for (int i = 0; i < seObjNames.length; i++) {
0313: objectNames[bcObjNames.length + i] = seObjNames[i];
0314: }
0315: return objectNames;
0316:
0317: }
0318:
0319: /**
0320: * get all component for component->install view
0321: */
0322: public void getInstallCompontentList(JmxComponentInfo info)
0323: throws Exception {
0324:
0325: // get share library names
0326: String[] slNames = getSharedLibraryNames();
0327:
0328: info.setUninstallSL(slNames);
0329:
0330: // get binding component names
0331: AdminServiceMBean adminServiceProxy = (AdminServiceMBean) getProxy(
0332: getAdminServiceMbeanName(), AdminServiceMBean.class);
0333: ObjectName[] bcObjNames = adminServiceProxy
0334: .getBindingComponents();
0335: String[] bcNames = new String[bcObjNames.length];
0336: for (int i = 0; i < bcObjNames.length; i++)
0337: bcNames[i] = bcObjNames[i].getKeyProperty("Name");
0338:
0339: info.setUninstallBC(bcNames);
0340: // get service engines component names
0341: ObjectName[] seObjNames = adminServiceProxy
0342: .getEngineComponents();
0343: String[] seNames = new String[seObjNames.length];
0344: for (int i = 0; i < seObjNames.length; i++)
0345: seNames[i] = seObjNames[i].getKeyProperty("Name");
0346:
0347: info.setUninstallSE(seNames);
0348: // get all compontents from local path
0349: DeployInfo.getInstance().parseCompontentsJar();
0350: Map mapBCComponent = DeployInfo.getInstance()
0351: .getDeployBCComponents();
0352: Map mapSEComponent = DeployInfo.getInstance()
0353: .getDeploySEComponents();
0354: Map mapSharedLibrary = DeployInfo.getInstance()
0355: .getDeploySharedLibraries();
0356:
0357: Set bcSet = differenceSet(mapBCComponent, bcNames);
0358: Set seSet = differenceSet(mapSEComponent, seNames);
0359: Set slSet = differenceSet(mapSharedLibrary, slNames);
0360:
0361: String[] installBCNames = getNamesBySet(bcSet);
0362: String[] installSENames = getNamesBySet(seSet);
0363: String[] installSLNames = getNamesBySet(slSet);
0364:
0365: info.setBindingComponents(installBCNames);
0366: info.setServiceEngines(installSENames);
0367: info.setSharedLibraries(installSLNames);
0368:
0369: }
0370:
0371: public void getRemoveComponentList(JmxComponentInfo info)
0372: throws Exception {
0373: // get all custom compontents
0374: DeployInfo.getInstance().parseCustomCompontentsJar();
0375: Map mapBCComponent = DeployInfo.getInstance()
0376: .getDeployBCComponents();
0377: Map mapSEComponent = DeployInfo.getInstance()
0378: .getDeploySEComponents();
0379: Map mapSharedLibrary = DeployInfo.getInstance()
0380: .getDeploySharedLibraries();
0381:
0382: // get share library name
0383: String[] slNames = getSharedLibraryNames();
0384:
0385: // This is standard, JBI-compliant code
0386: AdminServiceMBean adminServiceProxy = (AdminServiceMBean) getProxy(
0387: getAdminServiceMbeanName(), AdminServiceMBean.class);
0388:
0389: // adminServiceProxy.getSystemServices()
0390:
0391: ObjectName[] bcObjNames = adminServiceProxy
0392: .getBindingComponents();
0393: String[] bcNames = new String[bcObjNames.length];
0394: String[] bcStates = new String[bcObjNames.length];
0395: for (int i = 0; i < bcObjNames.length; i++) {
0396: bcNames[i] = bcObjNames[i].getKeyProperty("Name");
0397: bcStates[i] = this .getCurrentState(bcNames[i]);
0398: }
0399:
0400: ObjectName[] seObjNames = adminServiceProxy
0401: .getEngineComponents();
0402: String[] seNames = new String[seObjNames.length];
0403: String[] seStates = new String[seObjNames.length];
0404: for (int i = 0; i < seObjNames.length; i++) {
0405: seNames[i] = seObjNames[i].getKeyProperty("Name");
0406: seStates[i] = this .getCurrentState(seNames[i]);
0407: }
0408:
0409: String[] removeBCNames = getRemoveComponents(mapBCComponent,
0410: bcNames);
0411: String[] removeSENames = getRemoveComponents(mapSEComponent,
0412: seNames);
0413: String[] removeSLNames = getRemoveComponents(mapSharedLibrary,
0414: slNames);
0415:
0416: info.setBindingComponents(removeBCNames);
0417: info.setServiceEngines(removeSENames);
0418: info.setSharedLibraries(removeSLNames);
0419: }
0420:
0421: public void startComponent(String componentName) throws Exception {
0422:
0423: String state = getCurrentState(componentName);
0424: if (state.equals(LifeCycleMBean.STARTED))
0425: return;
0426: LifeCycleMBean lifeCycleProxy = (LifeCycleMBean) getProxy(
0427: getLifeCycleMbeanName(componentName),
0428: LifeCycleMBean.class);
0429: try {
0430: lifeCycleProxy.start();
0431: } catch (Exception ex) {
0432: throw new ServerSideException((Messages
0433: .get(CoreMessageConstants.CAN_NOT_START_COMPONENT))
0434: + ":" + componentName, ex);
0435: }
0436: }
0437:
0438: public void stopComponent(String componentName) throws Exception {
0439: String state = getCurrentState(componentName);
0440: if (!state.equals(LifeCycleMBean.STARTED))
0441: return;
0442: LifeCycleMBean lifeCycleProxy = (LifeCycleMBean) getProxy(
0443: getLifeCycleMbeanName(componentName),
0444: LifeCycleMBean.class);
0445: try {
0446: lifeCycleProxy.stop();
0447: } catch (Exception ex) {
0448: throw new ServerSideException((Messages
0449: .get(CoreMessageConstants.CAN_NOT_STOP_COMPONENT))
0450: + ":" + componentName, ex);
0451: }
0452: }
0453:
0454: public void shutdownComponent(String componentName)
0455: throws Exception {
0456: LifeCycleMBean lifeCycleProxy = (LifeCycleMBean) getProxy(
0457: getLifeCycleMbeanName(componentName),
0458: LifeCycleMBean.class);
0459: String state = getCurrentState(componentName);
0460:
0461: try {
0462: if (state.equals(LifeCycleMBean.STOPPED))
0463: lifeCycleProxy.stop();
0464: } catch (Exception ex) {
0465: throw new ServerSideException("can't stop component: "
0466: + componentName + " when shut down", ex);
0467: }
0468:
0469: try {
0470: lifeCycleProxy.shutDown();
0471: } catch (Exception ex) {
0472: throw new ServerSideException(
0473: (Messages
0474: .get(CoreMessageConstants.CAN_NOT_SHUTDOWN_COMPONENT))
0475: + ":" + componentName, ex);
0476: }
0477: }
0478:
0479: public void installComponent(String componentName, String jarName)
0480: throws Exception {
0481: ObjectName installName = null;
0482: InstallationServiceMBean installationService = (InstallationServiceMBean) getProxy(
0483: getInstallationServiceMbeanName(),
0484: InstallationServiceMBean.class);
0485:
0486: try {
0487: installName = installationService
0488: .loadNewInstaller(ServerUtil
0489: .getComponentJarName(jarName));
0490:
0491: } catch (Exception ex) {
0492: installationService.unloadInstaller(componentName, true);
0493: installName = installationService
0494: .loadNewInstaller(ServerUtil
0495: .getComponentJarName(jarName));
0496:
0497: // installName = installationService.loadInstaller(componentName);
0498:
0499: }
0500: try {
0501:
0502: if (installName != null) {
0503: InstallerMBean installerProxy = (InstallerMBean) getProxy(
0504: installName, InstallerMBean.class);
0505: installerProxy.install();
0506: } else {
0507: InstallerMBean installerProxy = (InstallerMBean) getProxy(
0508: getInstallerMbeanName(componentName),
0509: InstallerMBean.class);
0510: installerProxy.install();
0511:
0512: }
0513: } catch (Exception ex) {
0514: throw new Exception(ex.toString());
0515: }
0516:
0517: }
0518:
0519: public void installUserComponent(String fileName) throws Exception {
0520: InstallationServiceMBean installationService = (InstallationServiceMBean) getProxy(
0521: getInstallationServiceMbeanName(),
0522: InstallationServiceMBean.class);
0523: ObjectName installName = installationService
0524: .loadNewInstaller(fileName);
0525: if (installName != null) {
0526: InstallerMBean installerProxy = (InstallerMBean) getProxy(
0527: installName, InstallerMBean.class);
0528: installerProxy.install();
0529: } else {
0530: throw new Exception((Messages
0531: .get(CoreMessageConstants.CAN_NOT_GET_INSTALLER)));
0532: }
0533: }
0534:
0535: public void installSharedLibrary(String libName, String jarName)
0536: throws Exception {
0537: InstallationServiceMBean installationService = (InstallationServiceMBean) getProxy(
0538: getInstallationServiceMbeanName(),
0539: InstallationServiceMBean.class);
0540: installationService.installSharedLibrary(ServerUtil
0541: .getSharedLibraryJarName(jarName));
0542: }
0543:
0544: public void uninstallComponent(String componentName)
0545: throws Exception {
0546: try {
0547: this .shutdownComponent(componentName);
0548: InstallerMBean installerProxy = (InstallerMBean) getProxy(
0549: getInstallerMbeanName(componentName),
0550: InstallerMBean.class);
0551: installerProxy.uninstall();
0552: } catch (Exception ex) {
0553: InstallationServiceMBean installationService = (InstallationServiceMBean) getProxy(
0554: getInstallationServiceMbeanName(),
0555: InstallationServiceMBean.class);
0556: ObjectName installName = installationService
0557: .loadInstaller(componentName);
0558: if (installName == null) {
0559: installName = installationService
0560: .loadNewInstaller(ServerUtil
0561: .getComponentJarName(componentName));
0562: }
0563: if (installName != null) {
0564: InstallerMBean installerProxy = (InstallerMBean) getProxy(
0565: installName, InstallerMBean.class);
0566: try {
0567: installerProxy.uninstall();
0568: } catch (Exception e) {
0569: throw new ServerSideException(
0570: (Messages
0571: .get(CoreMessageConstants.CAN_NOT_UNINSTALL_COMPONENT))
0572: + ":" + componentName, ex);
0573: }
0574: } else {
0575: throw new Exception(
0576: (Messages
0577: .get(CoreMessageConstants.CAN_NOT_GET_INSTALLER)));
0578: }
0579: }
0580: }
0581:
0582: public void uninstallSharedLibrary(String libName) throws Exception {
0583: InstallationServiceMBean installationService = (InstallationServiceMBean) getProxy(
0584: getInstallationServiceMbeanName(),
0585: InstallationServiceMBean.class);
0586: try {
0587: installationService.uninstallSharedLibrary(libName);
0588: } catch (Exception ex) {
0589: throw new ServerSideException(
0590: (Messages
0591: .get(CoreMessageConstants.CAN_NOT_UNINSTALL_SHARED_LIBRARY))
0592: + ":" + libName, ex);
0593: }
0594: }
0595:
0596: public void removeComponent(String componentJarName)
0597: throws Exception {
0598: String jarFile = ServerUtil.getComponentFolder()
0599: + componentJarName;
0600: try {
0601: File file = new File(jarFile);
0602: file.delete();
0603: } catch (Exception e) {
0604: e.printStackTrace();
0605: }
0606: // delete assemblyJarName
0607: }
0608:
0609: public void removeSharedLibrary(String libName) throws Exception {
0610: removeComponent(libName);
0611: }
0612:
0613: // -------service assembley-------------------------------
0614: public String getServiceAssemblState(String assemblyName)
0615: throws Exception {
0616: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0617: getDeploymentServiceMbeanName(),
0618: DeploymentServiceMBean.class);
0619: try {
0620: return deploymentServiceProxy.getState(assemblyName);
0621: } catch (Exception ex) {
0622: throw new ServerSideException(
0623: (Messages
0624: .get(CoreMessageConstants.CAN_NOT_GET_SERVICE_ASSEMBLY_STATE))
0625: + ":" + assemblyName, ex);
0626: }
0627: }
0628:
0629: public void getCurrentServiceAssemblyList(JmxAssemblyInfo info)
0630: throws Exception {
0631: // yz.ling
0632: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0633: getDeploymentServiceMbeanName(),
0634: DeploymentServiceMBean.class);
0635:
0636: String[] saNames = deploymentServiceProxy
0637: .getDeployedServiceAssemblies();
0638: String[] saStates = new String[saNames.length];
0639: for (int i = 0; i < saNames.length; i++) {
0640: saStates[i] = this .getServiceAssemblState(saNames[i]);
0641: }
0642: info.setServiceAssemblys(saNames);
0643: info.setSaStates(saStates);
0644: }
0645:
0646: public String[] getSANames() throws Exception {
0647: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0648: getDeploymentServiceMbeanName(),
0649: DeploymentServiceMBean.class);
0650:
0651: // load deployed service assemblies
0652: String[] saNames = deploymentServiceProxy
0653: .getDeployedServiceAssemblies();
0654: return saNames;
0655: }
0656:
0657: public void getDeployServiceAssemblyList(JmxAssemblyInfo info)
0658: throws Exception {
0659: // yz.ling
0660: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0661: getDeploymentServiceMbeanName(),
0662: DeploymentServiceMBean.class);
0663:
0664: // load deployed service assemblies
0665: String[] saNames = deploymentServiceProxy
0666: .getDeployedServiceAssemblies();
0667: String[] saStates = new String[saNames.length];
0668:
0669: DeployInfo.getInstance().parseAssebliesJar();
0670: Map mapServiceAssembly = DeployInfo.getInstance()
0671: .getServiceAssemblies();
0672:
0673: for (int i = 0; i < saNames.length; i++) {
0674: // saStates="Deployed";
0675: mapServiceAssembly.remove(saNames[i]);
0676: }
0677:
0678: // load undeploy service assemblies
0679: int num = 0;
0680: String[] undeploySANames = new String[mapServiceAssembly.size()];
0681: Iterator itServiceAssembly = mapServiceAssembly.keySet()
0682: .iterator();
0683: while (itServiceAssembly.hasNext()) {
0684: String name = (String) itServiceAssembly.next();
0685: DeployObject deployObj = (DeployObject) mapServiceAssembly
0686: .get(name);
0687: undeploySANames[num] = deployObj.getName();
0688: num++;
0689: }
0690: info.setUndeployServiceAssemblies(undeploySANames);
0691: info.setServiceAssemblys(saNames);
0692: info.setSaStates(saStates);
0693: }
0694:
0695: public void getRemoveServiceAssemblyList(JmxAssemblyInfo info)
0696: throws Exception {
0697: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0698: getDeploymentServiceMbeanName(),
0699: DeploymentServiceMBean.class);
0700:
0701: // load deployed service assemblies
0702: String[] saNames = deploymentServiceProxy
0703: .getDeployedServiceAssemblies();
0704:
0705: DeployInfo.getInstance().parseAssebliesJar();
0706: Map mapServiceAssembly = DeployInfo.getInstance()
0707: .getServiceAssemblies();
0708:
0709: for (int i = 0; i < saNames.length; i++) {
0710: mapServiceAssembly.remove(saNames[i]);
0711: }
0712:
0713: // load remove service assemblies
0714: int num = 0;
0715: String[] removeSANames = new String[mapServiceAssembly.size()];
0716: String[] saJarName = new String[mapServiceAssembly.size()];
0717:
0718: Iterator itServiceAssembly = mapServiceAssembly.keySet()
0719: .iterator();
0720: while (itServiceAssembly.hasNext()) {
0721: String name = (String) itServiceAssembly.next();
0722: DeployObject deployObj = (DeployObject) mapServiceAssembly
0723: .get(name);
0724: removeSANames[num] = deployObj.getName();
0725: saJarName[num] = deployObj.getJarName();
0726: num++;
0727: }
0728: info.setUndeployServiceAssemblies(removeSANames);
0729: info.setSaJarName(saJarName);
0730: }
0731:
0732: public void startServiceAssembly(String assemblyName)
0733: throws Exception {
0734: String state = getServiceAssemblState(assemblyName);
0735: if (state.equals(DeploymentServiceMBean.STARTED))
0736: return;
0737: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0738: getDeploymentServiceMbeanName(),
0739: DeploymentServiceMBean.class);
0740: try {
0741: deploymentServiceProxy.start(assemblyName);
0742: } catch (Exception ex) {
0743: throw new ServerSideException(
0744: (Messages
0745: .get(CoreMessageConstants.CAN_NOT_START_SERVICE_ASSEMBLY))
0746: + ":" + assemblyName, ex);
0747: }
0748: }
0749:
0750: public void stopServiceAssembly(String assemblyName)
0751: throws Exception {
0752: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0753: getDeploymentServiceMbeanName(),
0754: DeploymentServiceMBean.class);
0755: try {
0756: deploymentServiceProxy.stop(assemblyName);
0757: } catch (Exception ex) {
0758: throw new ServerSideException(
0759: (Messages
0760: .get(CoreMessageConstants.CAN_NOT_STOP_SERVICE_ASSEMBLY))
0761: + ":" + assemblyName, ex);
0762: }
0763: }
0764:
0765: public void shutdownServiceAssembly(String assemblyName)
0766: throws Exception {
0767: String state = getServiceAssemblState(assemblyName);
0768: if (state.equals(DeploymentServiceMBean.SHUTDOWN))
0769: return;
0770: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0771: getDeploymentServiceMbeanName(),
0772: DeploymentServiceMBean.class);
0773: // if (deploymentServiceProxy.getState(assemblyName).equals(
0774: // DeploymentServiceMBean.STARTED))
0775: stopServiceAssembly(assemblyName);
0776: try {
0777: deploymentServiceProxy.shutDown(assemblyName);
0778: } catch (Exception ex) {
0779: throw new ServerSideException(
0780: (Messages
0781: .get(CoreMessageConstants.CAN_NOT_SHUTDOWN_SERVICE_ASSEMBLY))
0782: + ":" + assemblyName, ex);
0783: }
0784: }
0785:
0786: public void deployServiceAssembly(String assemblyZipUrl)
0787: throws Exception {
0788:
0789: if (!(assemblyZipUrl.indexOf(File.separator) > -1)) {
0790: DeployInfo.getInstance().parseAssebliesJar();
0791: assemblyZipUrl = DeployInfo.getInstance()
0792: .getAssemblyJarByName(assemblyZipUrl);
0793: assemblyZipUrl = ServerUtil.getAssemblyFolder()
0794: + assemblyZipUrl;
0795:
0796: }
0797: if (assemblyZipUrl.endsWith(".zip")
0798: || assemblyZipUrl.endsWith(".jar")) {
0799: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0800: getDeploymentServiceMbeanName(),
0801: DeploymentServiceMBean.class);
0802: try {
0803: deploymentServiceProxy.deploy(assemblyZipUrl);
0804: } catch (Exception ex) {
0805: throw new ServerSideException(
0806: (Messages
0807: .get(CoreMessageConstants.CAN_NOT_DEPLOY_SERVICE_ASSEMBLY))
0808: + ":" + assemblyZipUrl, ex);
0809: }
0810: }
0811: }
0812:
0813: public void undeployServiceAssembly(String assemblyName)
0814: throws Exception {
0815:
0816: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0817: getDeploymentServiceMbeanName(),
0818: DeploymentServiceMBean.class);
0819: if (!deploymentServiceProxy.getState(assemblyName).equals(
0820: DeploymentServiceMBean.SHUTDOWN))
0821: shutdownServiceAssembly(assemblyName);
0822: try {
0823: deploymentServiceProxy.undeploy(assemblyName);
0824: } catch (Exception ex) {
0825: throw new ServerSideException(
0826: Messages
0827: .get(CoreMessageConstants.CAN_NOT_UNDEPLOY_SERVICE_ASSEMBLY)
0828: + ":" + assemblyName, ex);
0829: }
0830:
0831: }
0832:
0833: public void removeServiceAssembly(String assemblyJarName)
0834: throws Exception {
0835: String jarFile = ServerUtil.getAssemblyFolder()
0836: + assemblyJarName;
0837: boolean result = false;
0838: try {
0839: File file = new File(jarFile);
0840: if (file.exists()) {
0841: result = file.delete();
0842: }
0843: } catch (Exception e) {
0844: e.printStackTrace();
0845: }
0846: if (!result) {
0847: throw new Exception(Messages
0848: .get(CoreMessageConstants.CAN_NOT_REMOVE_FILE));
0849: }
0850: // delete assemblyJarName
0851: }
0852:
0853: // -----------------------------------------------------------
0854: protected abstract String[] getSharedLibraryNames()
0855: throws ServerSideException;
0856:
0857: protected abstract ObjectName getAdminServiceMbeanName()
0858: throws MalformedObjectNameException;
0859:
0860: protected abstract ObjectName getDeploymentServiceMbeanName()
0861: throws MalformedObjectNameException;
0862:
0863: protected abstract ObjectName getInstallationServiceMbeanName()
0864: throws MalformedObjectNameException;
0865:
0866: protected abstract ObjectName getRegistryMbeanName()
0867: throws MalformedObjectNameException;
0868:
0869: protected abstract ObjectName getInstallerMbeanName(
0870: String componentName) throws MalformedObjectNameException;
0871:
0872: protected abstract ObjectName getLifeCycleMbeanName(
0873: String componentName) throws MalformedObjectNameException;
0874:
0875: protected abstract ObjectName getLifeCycleExtensionMbeanName(
0876: String componentName) throws MalformedObjectNameException;
0877:
0878: protected abstract ObjectName getSharedLibraryMbeanName(
0879: String libName) throws MalformedObjectNameException;
0880:
0881: protected abstract ObjectName getSharedLibraryInstallerMbeanName(
0882: String libName) throws MalformedObjectNameException;
0883:
0884: protected abstract ObjectName getServiceUnitLifeCycleMbeanName(
0885: String serviceUintName, String componentName)
0886: throws MalformedObjectNameException;
0887:
0888: protected abstract JMXServiceURL getServiceUrl()
0889: throws MalformedURLException;
0890:
0891: protected abstract JMXConnector getJmxConnector(JMXServiceURL url)
0892: throws ServerSideException;
0893:
0894: protected Object getProxy(ObjectName name, Class type)
0895: throws ServerSideException {
0896: Object o = MBeanServerInvocationHandler.newProxyInstance(
0897: getServerConnection(), name, type, true);
0898: try {
0899: this .getServerConnection().getObjectInstance(name);
0900: } catch (Exception ex) {
0901: throw new ServerSideException(Messages.get(
0902: CoreMessageConstants.NO_JMX_INSTANCE_ERROR, name),
0903: ex);
0904: } catch (Throwable t) {
0905: throw new ServerSideException(Messages.get(
0906: CoreMessageConstants.NO_JMX_INSTANCE_ERROR, name),
0907: t);
0908: }
0909: return o;
0910: }
0911:
0912: protected LifeCycleExtensionMBean getLifeCycleExtensionMBean(
0913: String componentName) throws Exception {
0914: ObjectName objectName = this
0915: .getLifeCycleExtensionMbeanName(componentName);
0916: LifeCycleExtensionMBean lifeCycleExtensionMBean = (LifeCycleExtensionMBean) getProxy(
0917: objectName, LifeCycleExtensionMBean.class);
0918: return lifeCycleExtensionMBean;
0919: }
0920:
0921: /*
0922: * Gets lists of Binding Components, Service Engines and Shared Libraries
0923: * currently installed
0924: */
0925: public void getDependences(String componentName,
0926: JmxComponentInfo info) throws Exception {
0927:
0928: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
0929: getDeploymentServiceMbeanName(),
0930: DeploymentServiceMBean.class);
0931:
0932: String[] assemblies = deploymentServiceProxy
0933: .getDeployedServiceAssembliesForComponent(componentName);
0934: Vector<ServiceAssemblyObj> result = new Vector<ServiceAssemblyObj>();
0935: for (int i = 0; i < assemblies.length; i++) {
0936: String state = deploymentServiceProxy
0937: .getState(assemblies[i]);
0938: if (state.equals(JmxComponentInfo.LifeCycleState[2])) {
0939: ServiceAssemblyObj serviceAssembly = new ServiceAssemblyObj();
0940: serviceAssembly.setName(assemblies[i]);
0941: serviceAssembly
0942: .setServiceUnits(deploymentServiceProxy
0943: .getComponentsForDeployedServiceAssembly(assemblies[i]));
0944: result.add(serviceAssembly);
0945: }
0946: }
0947: info.setComponentDependences((ServiceAssemblyObj[]) result
0948: .toArray(new ServiceAssemblyObj[result.size()]));
0949: }
0950:
0951: public String[] getEndpointNameArray() throws Exception {
0952:
0953: JmxComponentInfo componentInfo = new JmxComponentInfo();
0954: this .getCurrentComponentList(componentInfo);
0955: String[] bcs = componentInfo.getBindingComponents();
0956: String[] sas = componentInfo.getServiceEngines();
0957: Vector<String> endpointList = new Vector<String>();
0958: for (int i = 0; i < bcs.length; i++) {
0959: String componentName = bcs[i];
0960: LifeCycleExtensionMBean ext = null;
0961: try {
0962: ext = this .getLifeCycleExtensionMBean(componentName);
0963: } catch (Exception ex) {
0964: continue;
0965: }
0966: if (ext == null)
0967: continue;
0968: try {
0969: String[] endpoints = ext.getEndpointNames();
0970: for (int j = 0; j < endpoints.length; j++) {
0971: String temp = endpoints[j];
0972: String[] array = temp.split(":");
0973:
0974: endpointList.add(array[1]);
0975: }
0976: } catch (Exception ex) {
0977: log.error(
0978: "Fail to get Endpoint name array from component "
0979: + componentName, ex);
0980: }
0981:
0982: }
0983: for (int i = 0; i < sas.length; i++) {
0984: String componentName = sas[i];
0985: LifeCycleExtensionMBean ext = null;
0986: try {
0987: ext = this .getLifeCycleExtensionMBean(componentName);
0988: } catch (Exception ex) {
0989: continue;
0990: }
0991: if (ext == null)
0992: continue;
0993: try {
0994: String[] endpoints = ext.getEndpointNames();
0995: for (int j = 0; j < endpoints.length; j++) {
0996: String temp = endpoints[j];
0997: String[] array = temp.split(":");
0998:
0999: endpointList.add(array[1]);
1000: }
1001: } catch (Exception ex) {
1002: log.error(
1003: "Fail to get Endpoint name array from component "
1004: + componentName, ex);
1005: }
1006: // String[] endpoints = ext.getEndpointNames();
1007: // for (int j = 0; j < endpoints.length; j++){
1008: // String temp=endpoints[j];
1009: // String[] array=temp.split(":");
1010: // endpointList.add(array[1]);
1011: // }
1012: }
1013: return endpointList.toArray(new String[] {});
1014: }
1015:
1016: public String[] getDisplayTitles(String componentName)
1017: throws Exception {
1018: LifeCycleExtensionMBean ext = (LifeCycleExtensionMBean) getLifeCycleExtensionMBean(componentName);
1019: try {
1020: String[] titles = ext.getDisplayParameterTitles();
1021: return titles;
1022: } catch (Exception ex) {
1023: throw new ServerSideException((Messages.get(
1024: (CoreMessageConstants.CAN_NOT_GET_PROPERTY_NAMES),
1025: componentName)), ex);
1026: }
1027: }
1028:
1029: public void getPropertyObjects(String componentName,
1030: String endpointName, JmxEndpointObj obj) throws Exception {
1031: LifeCycleExtensionMBean ext = (LifeCycleExtensionMBean) getLifeCycleExtensionMBean(componentName);
1032: try {
1033: obj.setProptertyObjects(ext
1034: .getGetablePropertyObject(endpointName));
1035: } catch (Exception ex) {
1036: throw new ServerSideException((Messages.get(
1037: (CoreMessageConstants.CAN_NOT_GET_PROPERTY_VALUES),
1038: endpointName)), ex);
1039: }
1040: }
1041:
1042: public String[] getExtendedComponentByAssembly(String saName)
1043: throws Exception {
1044:
1045: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
1046: getDeploymentServiceMbeanName(),
1047: DeploymentServiceMBean.class);
1048:
1049: String[] components = deploymentServiceProxy
1050: .getComponentsForDeployedServiceAssembly(saName);
1051: Vector<String> result = new Vector<String>();
1052: for (int i = 0; i < components.length; i++) {
1053: if (components[i].equals(BOOTSTRAP_COMP))
1054: continue;
1055:
1056: //if (this.getLifeCycleExtensionMBean(components[i]) != null) {
1057: result.add(components[i]);
1058: //}
1059: }
1060: return (String[]) result.toArray(new String[0]);
1061: }
1062:
1063: /**
1064: *
1065: * get the endpoint status and properties info for all SAs .
1066: */
1067: public void getSaList(JmxEndpointInfo info) throws Exception {
1068:
1069: DeploymentServiceMBean deploymentServiceProxy = (DeploymentServiceMBean) getProxy(
1070: getDeploymentServiceMbeanName(),
1071: DeploymentServiceMBean.class);
1072: List<JmxAssemblyObj> saList = new Vector<JmxAssemblyObj>();
1073: String[] saNames = deploymentServiceProxy
1074: .getDeployedServiceAssemblies();
1075: for (int i = 0; i < saNames.length; i++) {
1076: String saName = saNames[i];
1077: JmxAssemblyObj sa = new JmxAssemblyObj(saName);
1078: this .getAssemblyObjAndValues(sa);
1079: saList.add(sa);
1080: }
1081:
1082: info.setSaList(saList.toArray(new JmxAssemblyObj[0]));
1083:
1084: }
1085:
1086: /**
1087: * get one assembly info . no endpoint property values
1088: */
1089: public void getAssemblyObj(JmxAssemblyObj sa) throws Exception {
1090: List<JmxComponentObj> compList = new Vector<JmxComponentObj>();
1091:
1092: String[] componentList = this .getExtendedComponentByAssembly(sa
1093: .getName());
1094: for (String componentName : componentList) {
1095: JmxComponentObj component = this .getComponentObj(sa
1096: .getName(), componentName);
1097: if (component == null)
1098: continue;
1099: compList.add(component);
1100: }
1101: sa.setComponentList(compList.toArray(new JmxComponentObj[0]));
1102:
1103: }
1104:
1105: /**
1106: * get one assembly info and endpoint property's value.
1107: */
1108: public void getAssemblyObjAndValues(JmxAssemblyObj sa)
1109: throws Exception {
1110: List<JmxComponentObj> compList = new Vector<JmxComponentObj>();
1111:
1112: String[] componentList = this .getExtendedComponentByAssembly(sa
1113: .getName());
1114: for (String componentName : componentList) {
1115: JmxComponentObj component = this .getComponentObjAndValues(
1116: sa.getName(), componentName);
1117: if (component == null)
1118: continue;
1119: compList.add(component);
1120: }
1121: sa.setComponentList(compList.toArray(new JmxComponentObj[0]));
1122:
1123: }
1124:
1125: public void getStatusChange(long timeout, JmxEndpointInfo info)
1126: throws Exception {
1127:
1128: //HashMap<String, ObjectName> lceMap = this.prepareLceMap();
1129: ObjectName[] names = this .getCurComponentObjectNames();
1130: ClientListener listener = new ClientListener();
1131:
1132: MBeanServerConnection mbsc = this .getServerConnection();
1133: for (ObjectName on : names) {
1134: mbsc.addNotificationListener(on, listener, null, null);
1135:
1136: }
1137: listenerStatusMap.put(getSessionId(), listener);
1138:
1139: Notification notification = (Notification) listener
1140: .getStateChangeNotificationQueue().poll(timeout,
1141: TimeUnit.MILLISECONDS);
1142: info
1143: .setEndpointThatChanged(notification != null ? ((StateChangeNotification) notification)
1144: .getComponentName()
1145: : null);
1146:
1147: listenerStatusMap.remove(getSessionId());
1148:
1149: for (ObjectName on : names) {
1150: // ObjectName on = lceMap.get(componentName);
1151: // System.out.println(componentName);
1152: mbsc.removeNotificationListener(on, listener, null, null);
1153: }
1154: if (notification != null) {
1155: this .getSaList(info);
1156: }
1157:
1158: }
1159:
1160: public void getStatusChangeBySA(long timeout, JmxAssemblyObj info)
1161: throws Exception {
1162:
1163: JmxEndpointInfo endpointInfo = getStatusChangeBySA(timeout,
1164: info.getName());
1165: if (endpointInfo.getEndpointThatChanged() != null) {
1166: this .getAssemblyObjAndValues(info);
1167: info.setEndpointStatusChanged("true");
1168: }
1169: }
1170:
1171: /**
1172: *
1173: * @param timeout
1174: * @param saName
1175: * @return if there is status change, return JmxAssemblyObj. if not, return null .
1176: * @throws Exception
1177: */
1178: public JmxEndpointInfo getStatusChangeBySA(long timeout,
1179: String saName) throws Exception {
1180: JmxEndpointInfo info = new JmxEndpointInfo();
1181: // HashMap<String, ObjectName> lceMap = this.prepareLceMap();
1182: SaClientListener listener = new SaClientListener(saName);
1183:
1184: String[] componentList = this
1185: .getExtendedComponentByAssembly(saName);
1186: Vector<ObjectName> nameList = new Vector<ObjectName>();
1187: for (String componentName : componentList) {
1188: nameList.add(getLifeCycleExtensionMbeanName(componentName));
1189: }
1190: MBeanServerConnection mbsc = this .getServerConnection();
1191:
1192: for (ObjectName on : nameList) {
1193:
1194: // ObjectName on = lceMap.get(componentName);
1195: mbsc.addNotificationListener(on, listener, null, null);
1196:
1197: }
1198: saListenerStatusMap.put(getSessionId(), listener);
1199: Notification notification = (Notification) listener
1200: .getStateChangeNotificationQueue().poll(timeout,
1201: TimeUnit.MILLISECONDS);
1202:
1203: info
1204: .setEndpointThatChanged(notification != null ? ((StateChangeNotification) notification)
1205: .getComponentName()
1206: : null);
1207: saListenerStatusMap.remove(getSessionId());
1208:
1209: for (ObjectName on : nameList) {
1210:
1211: mbsc.removeNotificationListener(on, listener, null, null);
1212: }
1213:
1214: return info;
1215:
1216: }
1217:
1218: public void stopPollingNotification() {
1219: if (saListenerStatusMap.containsKey(getSessionId())) {
1220: StateChangeNotification noti = new StateChangeNotification(
1221: "jmx", "jmx", 0);
1222: SaClientListener listener = saListenerStatusMap
1223: .get(getSessionId());
1224: listener.getStateChangeNotificationQueue().offer(noti);
1225: }
1226: if (listenerStatusMap.containsKey(getSessionId())) {
1227: StateChangeNotification noti = new StateChangeNotification(
1228: "jmx", "jmx", 0);
1229: ClientListener listener = listenerStatusMap
1230: .get(getSessionId());
1231: listener.getStateChangeNotificationQueue().offer(noti);
1232: }
1233:
1234: if (saListenerStatisMap.containsKey(getSessionId())) {
1235: StatisticChangeNotification noti = new StatisticChangeNotification(
1236: "jmx", "jmx", 0);
1237: SaClientListener listener = saListenerStatisMap
1238: .get(getSessionId());
1239: listener.getStatisticNotificationQueue().offer(noti);
1240: }
1241:
1242: if (listenerStatisMap.containsKey(getSessionId())) {
1243: StatisticChangeNotification noti = new StatisticChangeNotification(
1244: "jmx", "jmx", 0);
1245: ClientListener listener = listenerStatisMap
1246: .get(getSessionId());
1247: listener.getStatisticNotificationQueue().offer(noti);
1248: }
1249: }
1250:
1251: public void getStatisticsChangeBySA(long timeout, JmxAssemblyObj sa)
1252: throws Exception {
1253: SaClientListener listener = new SaClientListener(sa.getName());
1254:
1255: ObjectName name = getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP);
1256: MBeanServerConnection mbsc = this .getServerConnection();
1257:
1258: mbsc.addNotificationListener(name, listener, null, null);
1259: saListenerStatisMap.put(getSessionId(), listener);
1260: StatisticChangeNotification notification = (StatisticChangeNotification) listener
1261: .getStatisticNotificationQueue().poll(timeout,
1262: TimeUnit.MILLISECONDS);
1263:
1264: // System.out.println("Poll from queue :" + notification);
1265: sa.setStatisticChanged(notification != null ? true : false);
1266: saListenerStatisMap.remove(getSessionId());
1267: mbsc.removeNotificationListener(name, listener, null, null);
1268:
1269: if (notification != null && notification.getStatMap() != null) {
1270: this .getStatInfoFromNotificationBySA(sa, notification);
1271: }
1272: }
1273:
1274: public void getStatisticsChange(long timeout, JmxEndpointInfo info)
1275: throws Exception {
1276:
1277: // System.out.println("recived get status change");
1278: ClientListener listener = new ClientListener();
1279:
1280: ObjectName name = getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP);
1281: MBeanServerConnection mbsc = this .getServerConnection();
1282:
1283: mbsc.addNotificationListener(name, listener, null, null);
1284: listenerStatisMap.put(getSessionId(), listener);
1285:
1286: StatisticChangeNotification notification = (StatisticChangeNotification) listener
1287: .getStatisticNotificationQueue().poll(timeout,
1288: TimeUnit.MILLISECONDS);
1289:
1290: listenerStatisMap.remove(getSessionId());
1291: // System.out.println("Poll from queue :" + notification);
1292: info.setStatChanged(notification != null ? true : false);
1293:
1294: mbsc.removeNotificationListener(name, listener, null, null);
1295:
1296: if (notification != null) {
1297: this .getStatInfoFromNotification(info, notification);
1298: }
1299:
1300: // System.out.println("finish get status change");
1301: }
1302:
1303: private void getStatInfoFromNotification(
1304: JmxEndpointInfo endpointInfo,
1305: StatisticChangeNotification notification) throws Exception {
1306: ConcurrentHashMap<String, EndpointStatVO> map = notification
1307: .getStatMap();
1308: this .getSaList(endpointInfo);
1309: for (int i = 0; i < endpointInfo.getSaList().length; i++) {
1310: JmxAssemblyObj sa = endpointInfo.getSaList()[i];
1311: for (int j = 0; j < sa.getComponentList().length; j++) {
1312: JmxComponentObj component = sa.getComponentList()[j];
1313: for (int m = 0; m < component.getEndpointList().length; m++) {
1314: JmxEndpointObj endpoint = component
1315: .getEndpointList()[m];
1316: if (map.containsKey(endpoint.getName())) {
1317: EndpointStatVO statVO = map.get(endpoint
1318: .getName());
1319: endpoint.setLatency(statVO.getLatency());
1320: endpoint.setMessagesCount(statVO
1321: .getMessagesCount());
1322: endpoint.setMessagesPerSecond(statVO
1323: .getMessagesPerSecond());
1324: }
1325: }
1326: }
1327: }
1328:
1329: }
1330:
1331: private void getStatInfoFromNotificationBySA(JmxAssemblyObj sa,
1332: StatisticChangeNotification notification) throws Exception {
1333: ConcurrentHashMap<String, EndpointStatVO> map = notification
1334: .getStatMap();
1335: //Don't need property values
1336: this .getAssemblyObj(sa);
1337: for (int j = 0; j < sa.getComponentList().length; j++) {
1338: JmxComponentObj component = sa.getComponentList()[j];
1339: for (int m = 0; m < component.getEndpointList().length; m++) {
1340: JmxEndpointObj endpoint = component.getEndpointList()[m];
1341: if (map.containsKey(endpoint.getName())) {
1342: EndpointStatVO statVO = map.get(endpoint.getName());
1343: endpoint.setLatency(statVO.getLatency());
1344: endpoint
1345: .setMessagesCount(statVO.getMessagesCount());
1346: endpoint.setMessagesPerSecond(statVO
1347: .getMessagesPerSecond());
1348: }
1349: }
1350: }
1351:
1352: }
1353:
1354: public JmxComponentObj getComponentObj(String saName,
1355: String componentName) throws Exception {
1356: JmxComponentObj component = new JmxComponentObj(componentName);
1357:
1358: LifeCycleExtensionMBean ext = (LifeCycleExtensionMBean) this
1359: .getLifeCycleExtensionMBean(componentName);
1360: if (ext == null)
1361: return null;
1362: // String[] titles = ext.getDisplayParameterTitles();
1363: // component.setDisplayTitles(titles);
1364: component.setEndpointList(this .getEndpoints(saName,
1365: componentName, ext).toArray(new JmxEndpointObj[0]));
1366: return component;
1367: }
1368:
1369: public JmxComponentObj getComponentObjAndValues(String saName,
1370: String componentName) throws Exception {
1371: JmxComponentObj component = new JmxComponentObj(componentName);
1372:
1373: LifeCycleExtensionMBean ext = (LifeCycleExtensionMBean) this
1374: .getLifeCycleExtensionMBean(componentName);
1375: if (ext == null)
1376: return null;
1377: String[] titles = ext.getDisplayParameterTitles();
1378: component.setDisplayTitles(titles);
1379: component.setEndpointList(this .getEndpointsAndValues(saName,
1380: componentName, ext).toArray(new JmxEndpointObj[0]));
1381: return component;
1382: }
1383:
1384: public JmxEndpointObj getEndpointObj(String saName,
1385: String componentName, String endpointName) throws Exception {
1386:
1387: LifeCycleExtensionMBean ext = (LifeCycleExtensionMBean) this
1388: .getLifeCycleExtensionMBean(componentName);
1389: JmxEndpointObj[] endpoints = this .getEndpoints(saName,
1390: componentName, ext).toArray(new JmxEndpointObj[0]);
1391: for (int i = 0; i < endpoints.length; i++) {
1392: if (endpoints[i].getName().equals(endpointName)) {
1393: return endpoints[i];
1394: }
1395: }
1396: return null;
1397: }
1398:
1399: private Vector<JmxEndpointObj> getEndpointsAndValues(String saName,
1400: String componentName, LifeCycleExtensionMBean ext)
1401: throws Exception {
1402:
1403: Vector<JmxEndpointObj> endpointList = this .getEndpoints(saName,
1404: componentName, ext);
1405:
1406: for (int i = 0; i < endpointList.size(); i++) {
1407: JmxEndpointObj jmxEndpointObj = endpointList.get(i);
1408:
1409: String[] params = ext.getDisplayParameters(jmxEndpointObj
1410: .getName());
1411:
1412: jmxEndpointObj.setDisplayValues(params);
1413: }
1414: return endpointList;
1415:
1416: }
1417:
1418: private Vector<JmxEndpointObj> getEndpoints(String saName,
1419: String componentName, LifeCycleExtensionMBean ext)
1420: throws Exception {
1421:
1422: Vector<JmxEndpointObj> endpointList = new Vector<JmxEndpointObj>();
1423:
1424: String[] endpoints = ext.getEndpointNamesBySA(saName);
1425:
1426: // HashMap<String, String> suMap = new HashMap<String, String>();
1427: // String prefix=saName+"_";
1428: for (int i = 0; i < endpoints.length; i++) {
1429: String[] name = endpoints[i].split(":");
1430: String suName = name[0];
1431: String endpointName = name[1];
1432: String state = name[2];
1433: String role = name[3];
1434: JmxEndpointObj endpoint = new JmxEndpointObj();
1435: endpoint.setName(endpointName);
1436: endpoint.setStatus(state);
1437: endpoint.setRole(role);
1438: endpoint.setSuName(suName);
1439: endpoint.setSaName(saName);
1440: endpoint.setComponentName(componentName);
1441: // String[] params = ext.getDisplayParameters(endpoint.getName());
1442: // endpoint.setDisplayValues(params);
1443: endpointList.add(endpoint);
1444:
1445: }
1446: return endpointList;
1447:
1448: }
1449:
1450: public void startEndpoint(String componentName, String endpointName)
1451: throws Exception {
1452:
1453: LifeCycleExtensionMBean ext = this
1454: .getLifeCycleExtensionMBean(componentName);
1455: try {
1456: ext.startEndpoint(endpointName);
1457: } catch (Exception ex) {
1458: throw new ServerSideException(Messages
1459: .get((CoreMessageConstants.CAN_NOT_START_ENDPOINT))
1460: + ":" + endpointName, ex);
1461: }
1462: }
1463:
1464: public void stopEndpoint(String componentName, String endpointName)
1465: throws Exception {
1466:
1467: LifeCycleExtensionMBean ext = this
1468: .getLifeCycleExtensionMBean(componentName);
1469: try {
1470: ext.stopEndpoint(endpointName);
1471: } catch (Exception ex) {
1472: throw new ServerSideException((Messages
1473: .get((CoreMessageConstants.CAN_NOT_STOP_ENDPOINT)))
1474: + ":" + endpointName, ex);
1475: }
1476:
1477: }
1478:
1479: public void setPropertyObjects(String componentName,
1480: String endpointName, String[][] propertyObjects,
1481: JmxEndpointInfo info) throws Exception {
1482: LifeCycleExtensionMBean ext = this
1483: .getLifeCycleExtensionMBean(componentName);
1484: try {
1485: ext.setGetablePropertyObject(endpointName, propertyObjects);
1486: } catch (Exception ex) {
1487: throw new ServerSideException((Messages
1488: .get((CoreMessageConstants.CAN_NOT_SET_ENDPOINT)))
1489: + ":" + endpointName, ex);
1490: }
1491: }
1492:
1493: /**
1494: * timeout should larger than 60000ms
1495: */
1496: public ConcurrentHashMap<String, EndpointStatVO> getStatisticInfo(
1497: long timeout) throws Exception {
1498: // System.out.println("recived get Statistic info");
1499:
1500: ConcurrentHashMap<String, EndpointStatVO> result = new ConcurrentHashMap<String, EndpointStatVO>();
1501: ClientListener listener = new ClientListener();
1502: ObjectName name = getLifeCycleExtensionMbeanName(BOOTSTRAP_COMP);
1503: MBeanServerConnection mbsc = this .getServerConnection();
1504:
1505: mbsc.addNotificationListener(name, listener, null, null);
1506: listenerStatusMap.put(getSessionId(), listener);
1507:
1508: Notification notification = (Notification) listener
1509: .getStatisticNotificationQueue().poll(timeout,
1510: TimeUnit.MILLISECONDS);
1511:
1512: listenerStatusMap.remove(getSessionId());
1513: if (notification != null) {
1514: result = ((StatisticChangeNotification) notification)
1515: .getStatMap();
1516: }
1517: mbsc.removeNotificationListener(name, listener, null, null);
1518: return result;
1519: }
1520:
1521: /**
1522: * if saname=="all",reset all SA's statistics info,
1523: * otherwise reset one SA's statistics info which name is saName
1524: * @param saName
1525: * @throws Exception
1526: */
1527: public void resetEndpointStatistics(String saName) throws Exception {
1528: LifeCycleExtensionMBean mbean = (LifeCycleExtensionMBean) getProxy(
1529: getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP),
1530: LifeCycleExtensionMBean.class);
1531: if (mbean == null)
1532: throw new Exception(
1533: Messages
1534: .get(CoreMessageConstants.CAN_NOT_FIND_LIFECYCLEEXTENSIONMBEAN)
1535: + ":" + BaseJmxClient.BOOTSTRAP_COMP);
1536: try {
1537: mbean.resetEndpointStatistics(saName);
1538: } catch (Exception ex) {
1539: throw new ServerSideException(
1540: Messages
1541: .get(CoreMessageConstants.CAN_NOT_RESET_ENDPOINT_STATISTIC_INFO)
1542: + ":" + saName, ex);
1543: }
1544: }
1545:
1546: public void getVersionInfo(String name,
1547: ConsoleVersion consoleVersion) throws Exception {
1548: LifeCycleExtensionMBean mbean = (LifeCycleExtensionMBean) getProxy(
1549: getLifeCycleExtensionMbeanName(name),
1550: LifeCycleExtensionMBean.class);
1551: if (mbean == null) {
1552: consoleVersion
1553: .setVersionInfo(Messages
1554: .get(CoreMessageConstants.NO_COMPONENT_VERSION_INFO_ERROR));
1555: return;
1556:
1557: }
1558: Version version = mbean.getVersionInfo();
1559: if (version == null) {
1560: consoleVersion
1561: .setVersionInfo(Messages
1562: .get(CoreMessageConstants.NO_COMPONENT_VERSION_INFO_ERROR));
1563: return;
1564:
1565: }
1566: consoleVersion.setCompName(name);
1567: consoleVersion.setVersionInfo(version.toString());
1568: consoleVersion.setBuildTimestamp(version.getBuildTimestamp());
1569: consoleVersion.setBuildType(version.getBuildType());
1570: }
1571:
1572: public void getCCSLVersionInfo(String name,
1573: ConsoleVersion consoleVersion) throws Exception {
1574: if (!name.equalsIgnoreCase("CCSL")) {
1575: consoleVersion
1576: .setVersionInfo(Messages
1577: .get(CoreMessageConstants.NO_LIBRARY_VERSION_INFO_ERROR));
1578: return;
1579: }
1580: LifeCycleExtensionMBean mbean = (LifeCycleExtensionMBean) getProxy(
1581: getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP),
1582: LifeCycleExtensionMBean.class);
1583: if (mbean == null)
1584: throw new Exception(
1585: Messages
1586: .get(CoreMessageConstants.CAN_NOT_FIND_LIFECYCLEEXTENSIONMBEAN)
1587: + ":" + BaseJmxClient.BOOTSTRAP_COMP);
1588: try {
1589: Version version = mbean.getCCSLVersionInfo();
1590:
1591: consoleVersion.setCompName(name);
1592: consoleVersion.setVersionInfo(version.toString());
1593: consoleVersion.setBuildTimestamp(version
1594: .getBuildTimestamp());
1595: consoleVersion.setBuildType(version.getBuildType());
1596: } catch (Exception ex) {
1597: throw new ServerSideException(
1598: Messages
1599: .get(
1600: CoreMessageConstants.CAN_NOT_GET_VERSION_INFO_ERROR,
1601: name), ex);
1602: }
1603: }
1604:
1605: public void getConnectInfo() throws ServerSideException {
1606:
1607: getServerConnection();
1608:
1609: }
1610:
1611: public void setLogConfig(String logConfig)
1612: throws ServerSideException {
1613:
1614: try {
1615:
1616: LifeCycleExtensionMBean mbean = (LifeCycleExtensionMBean) getProxy(
1617: getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP),
1618: LifeCycleExtensionMBean.class);
1619: mbean.setLogConfig(logConfig);
1620:
1621: } catch (Exception ex) {
1622: throw new ServerSideException(Messages
1623: .get(CoreMessageConstants.FAILED_SET_LOG_LEVEL), ex);
1624: }
1625: }
1626:
1627: public String getLogConfig() throws ServerSideException {
1628: try {
1629:
1630: LifeCycleExtensionMBean mbean = (LifeCycleExtensionMBean) getProxy(
1631: getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP),
1632: LifeCycleExtensionMBean.class);
1633:
1634: return mbean.getLogConfig();
1635:
1636: } catch (Exception ex) {
1637: throw new ServerSideException(Messages
1638: .get(CoreMessageConstants.FAILED_SET_LOG_INFO), ex);
1639: }
1640: }
1641:
1642: }
|