List of usage examples for javax.management ObjectName getCanonicalName
public String getCanonicalName()
Returns the canonical form of the name; that is, a string representation where the properties are sorted in lexical order.
More precisely, the canonical form of the name is a String consisting of the domain part, a colon (:
), the canonical key property list, and a pattern indication.
The canonical key property list is the same string as described for #getCanonicalKeyPropertyListString() .
The pattern indication is:
,*
) for an ObjectName that is a property list pattern with at least one key. From source file:com.googlecode.jmxtrans.model.Query.java
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { MBeanInfo info = mbeanServer.getMBeanInfo(queryName); ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); }/* ww w.ja va2 s. c o m*/ } else { attributes = attr; } try { if (!attributes.isEmpty()) { logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this); AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()])); return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()) .getResults(); } } catch (UnmarshalException ue) { if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) { logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage()); } else { throw ue; } } return ImmutableList.of(); }
From source file:azkaban.webapp.AzkabanWebServer.java
public void close() { try {/*from www .j a v a2s. co m*/ for (ObjectName name : registeredMBeans) { mbeanServer.unregisterMBean(name); logger.info("Jmx MBean " + name.getCanonicalName() + " unregistered."); } } catch (Exception e) { logger.error("Failed to cleanup MBeanServer", e); } scheduleManager.shutdown(); executorManager.shutdown(); }
From source file:com.cyberway.issue.crawler.Heritrix.java
public static void unregisterMBean(final MBeanServer server, final ObjectName name) { try {/* ww w . ja v a 2s . c o m*/ server.unregisterMBean(name); logger.info("Unregistered bean " + name.getCanonicalName()); } catch (InstanceNotFoundException e) { e.printStackTrace(); } catch (MBeanRegistrationException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } }
From source file:azkaban.webapp.AzkabanWebServer.java
private void configureMBeanServer() { logger.info("Registering MBeans..."); mbeanServer = ManagementFactory.getPlatformMBeanServer(); registerMbean("jetty", new JmxJettyServer(server)); registerMbean("triggerManager", new JmxTriggerManager(triggerManager)); if (executorManager instanceof ExecutorManager) { registerMbean("executorManager", new JmxExecutorManager((ExecutorManager) executorManager)); }/*from w ww. j a v a2s . c o m*/ // Register Log4J loggers as JMX beans so the log level can be // updated via JConsole or Java VisualVM HierarchyDynamicMBean log4jMBean = new HierarchyDynamicMBean(); registerMbean("log4jmxbean", log4jMBean); ObjectName accessLogLoggerObjName = log4jMBean.addLoggerMBean(AZKABAN_ACCESS_LOGGER_NAME); if (accessLogLoggerObjName == null) { System.out.println("************* loginLoggerObjName is null, make sure there is a logger with name " + AZKABAN_ACCESS_LOGGER_NAME); } else { System.out.println("******** loginLoggerObjName: " + accessLogLoggerObjName.getCanonicalName()); } }
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public GetMultiObjectKeysResponse getWildcardJmxKeys(String name, String attributeName) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { GetMultiObjectKeysResponse reponse = new GetMultiObjectKeysResponse(); ArrayList<MultiObjectKeys> multiObjectKeysList = new ArrayList<MultiObjectKeys>(); ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); for (ObjectName iterObject : objectNameList) { objectName = iterObject;// ww w . j av a2s. co m List<KeyResponse> keyList = new ArrayList<KeyResponse>(); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; CompositeType type = cds.getCompositeType(); Set<String> listKey = type.keySet(); for (Object key : listKey) { if (key instanceof String) { Object value = cds.get((String) key); KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(key.toString()); keyResponse.setValue(value.toString()); keyList.add(keyResponse); } } } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setValue(attr.toString()); keyList.add(keyResponse); } MultiObjectKeys multiObjectKeys = new MultiObjectKeys(); multiObjectKeys.setJmxKeys(keyList); multiObjectKeys.setObjectName(objectName.getCanonicalName()); multiObjectKeysList.add(multiObjectKeys); } reponse.setMultiObjectKeys(multiObjectKeysList); return reponse; }
From source file:org.apache.geode.tools.pulse.internal.data.JMXDataUpdater.java
/** * Add member specific region information on the region * /*from ww w.jav a2 s .co m*/ * @param regionObjectName: used to construct the jmx objectname. For region name that has special * characters in, it will have double quotes around it. */ private void updateRegionOnMembers(String regionObjectName, String regionFullPath, Cluster.Region region) throws IOException { try { List<String> memberNamesTemp = region.getMemberName(); ArrayList<String> memberNames = new ArrayList<String>(memberNamesTemp); List<Cluster.RegionOnMember> regionOnMemberList = new ArrayList<Cluster.RegionOnMember>(); List<Cluster.RegionOnMember> regionOnMemberListNew = new ArrayList<Cluster.RegionOnMember>(); Cluster.RegionOnMember[] regionOnMemberNames = region.getRegionOnMembers(); if ((regionOnMemberNames != null) && (regionOnMemberNames.length > 0)) { regionOnMemberList = new ArrayList<Cluster.RegionOnMember>(Arrays.asList(regionOnMemberNames)); } logger.debug("updateRegionOnMembers : # regionOnMembers objects in region = {}", regionOnMemberList.size()); for (Cluster.RegionOnMember anRom : regionOnMemberList) { for (String memberName : memberNames) { if (anRom.getMemberName().equals(memberName)) { // Add regionOnMember object in new list regionOnMemberListNew.add(anRom); logger.debug("updateRegionOnMembers : Processing existing Member name = {}", anRom.getMemberName()); String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + anRom.getMemberName(); ObjectName regionOnMemberMBean = new ObjectName(objectNameROM); logger.debug("updateRegionOnMembers : Object name = {}", regionOnMemberMBean.getCanonicalName()); AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE: anRom.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getEntrySize() = {}", anRom.getEntrySize()); break; case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT: anRom.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getEntryCount() = {}", anRom.getEntryCount()); break; case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE: anRom.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getPutsRate() = {}", anRom.getPutsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE: anRom.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getGetsRate() = {}", anRom.getGetsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: anRom.setDiskGetsRate( getDoubleAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getDiskGetsRate() = {}", anRom.getDiskGetsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: anRom.setDiskPutsRate( getDoubleAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getDiskPutsRate() = {}", anRom.getDiskPutsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY: anRom.setLocalMaxMemory( getIntegerAttribute(attribute.getValue(), attribute.getName())); logger.debug("updateRegionOnMembers : anRom.getLocalMaxMemory() = {}", anRom.getLocalMaxMemory()); break; } } anRom.getGetsPerSecTrend().add(anRom.getGetsRate()); anRom.getPutsPerSecTrend().add(anRom.getPutsRate()); anRom.getDiskReadsPerSecTrend().add(anRom.getDiskGetsRate()); anRom.getDiskWritesPerSecTrend().add(anRom.getDiskPutsRate()); logger.debug( "updateRegionOnMembers : Existing member on region : getGetsRate() = {}, getPutsRate() = {}, getDiskGetsRate() = {}, getDiskPutsRate() = {}", anRom.getGetsPerSecTrend().size(), anRom.getPutsPerSecTrend().size(), anRom.getDiskReadsPerSecTrend().size(), anRom.getDiskWritesPerSecTrend().size()); // remove existing member names from list so only new ones will remain memberNames.remove(anRom.getMemberName()); break; } } } logger.debug( "updateRegionOnMembers : Loop over remaining member names and adding new member in region. Existing count = {}", regionOnMemberList.size()); logger.debug("updateRegionOnMembers : Remaining new members in this region = {}", memberNames.size()); // loop over the remaining regions members and add new members for this region for (String memberName : memberNames) { String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + memberName; ObjectName regionOnMemberMBean = new ObjectName(objectNameROM); Cluster.RegionOnMember regionOnMember = new Cluster.RegionOnMember(); regionOnMember.setMemberName(memberName); regionOnMember.setRegionFullPath(regionFullPath); AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE: regionOnMember.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT: regionOnMember.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE: regionOnMember.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE: regionOnMember.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: regionOnMember .setDiskGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: regionOnMember .setDiskPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY: regionOnMember .setLocalMaxMemory(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; } } regionOnMember.getGetsPerSecTrend().add(regionOnMember.getGetsRate()); regionOnMember.getPutsPerSecTrend().add(regionOnMember.getPutsRate()); regionOnMember.getDiskReadsPerSecTrend().add(regionOnMember.getDiskGetsRate()); regionOnMember.getDiskWritesPerSecTrend().add(regionOnMember.getDiskPutsRate()); logger.debug( "updateRegionOnMembers : Adding New member on region : getGetsRate() = {}, getPutsRate() = {}, getDiskGetsRate() = {}, getDiskPutsRate() = {}", regionOnMember.getGetsRate(), regionOnMember.getPutsRate(), regionOnMember.getDiskGetsRate(), regionOnMember.getDiskPutsRate()); regionOnMemberListNew.add(regionOnMember); } // set region on member region.setRegionOnMembers(regionOnMemberListNew); logger.debug("updateRegionOnMembers : Total regions on member in region after update = {}", region.getFullPath(), region.getRegionOnMembers().length); } catch (MalformedObjectNameException | InstanceNotFoundException | ReflectionException e) { logger.warn(e); } }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public ObjectName preRegister(final MBeanServer server, ObjectName on) throws Exception { this.mbeanServer = server; @SuppressWarnings("unchecked") Hashtable<String, String> ht = on.getKeyPropertyList(); if (!ht.containsKey(JmxUtils.NAME)) { throw new IllegalArgumentException("Name property required" + on.getCanonicalName()); }/*from w ww .j ava 2 s. com*/ // Now append key/values from hosting heritrix JMX ObjectName so it can be // found just by examination of the CrawlJob JMX ObjectName. Add heritrix // name attribute as 'mother' attribute. Heritrix h = getHostingHeritrix(); if (h == null || h.getMBeanName() == null) { throw new IllegalArgumentException( "Hosting heritrix not found " + "or not registered with JMX: " + on.getCanonicalName()); } @SuppressWarnings("unchecked") Map<String, String> hht = h.getMBeanName().getKeyPropertyList(); ht.put(JmxUtils.MOTHER, hht.get(JmxUtils.NAME)); String port = hht.get(JmxUtils.JMX_PORT); if (port != null) { ht.put(JmxUtils.JMX_PORT, port); } ht.put(JmxUtils.HOST, hht.get(JmxUtils.HOST)); if (!ht.containsKey(JmxUtils.TYPE)) { ht.put(JmxUtils.TYPE, CRAWLJOB_JMXMBEAN_TYPE); } this.mbeanName = new ObjectName(on.getDomain(), ht); return this.mbeanName; }
From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java
/** * Add member specific region information on the region * * @param regionObjectName: used to construct the jmx objectname. For region name that has special characters in, it will have double quotes around it. * @param region/* w ww . jav a 2 s . c om*/ */ private void updateRegionOnMembers(String regionObjectName, String regionFullPath, Cluster.Region region) throws IOException { try { List<String> memberNamesTemp = region.getMemberName(); ArrayList<String> memberNames = new ArrayList<String>(memberNamesTemp); List<Cluster.RegionOnMember> regionOnMemberList = new ArrayList<Cluster.RegionOnMember>(); List<Cluster.RegionOnMember> regionOnMemberListNew = new ArrayList<Cluster.RegionOnMember>(); Cluster.RegionOnMember[] regionOnMemberNames = region.getRegionOnMembers(); if ((regionOnMemberNames != null) && (regionOnMemberNames.length > 0)) { regionOnMemberList = new ArrayList<Cluster.RegionOnMember>(Arrays.asList(regionOnMemberNames)); } LOGGER.fine( "updateRegionOnMembers : # regionOnMembers objects in region = " + regionOnMemberList.size()); for (Cluster.RegionOnMember anRom : regionOnMemberList) { for (String memberName : memberNames) { if (anRom.getMemberName().equals(memberName)) { // Add regionOnMember object in new list regionOnMemberListNew.add(anRom); LOGGER.fine("updateRegionOnMembers : Processing existing Member name = " + anRom.getMemberName()); String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + anRom.getMemberName(); ObjectName regionOnMemberMBean = new ObjectName(objectNameROM); LOGGER.fine( "updateRegionOnMembers : Object name = " + regionOnMemberMBean.getCanonicalName()); AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE: anRom.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine( "updateRegionOnMembers : anRom.getEntrySize() = " + anRom.getEntrySize()); break; case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT: anRom.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine( "updateRegionOnMembers : anRom.getEntryCount() = " + anRom.getEntryCount()); break; case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE: anRom.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine("updateRegionOnMembers : anRom.getPutsRate() = " + anRom.getPutsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE: anRom.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine("updateRegionOnMembers : anRom.getGetsRate() = " + anRom.getGetsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: anRom.setDiskGetsRate( getDoubleAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine("updateRegionOnMembers : anRom.getDiskGetsRate() = " + anRom.getDiskGetsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: anRom.setDiskPutsRate( getDoubleAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine("updateRegionOnMembers : anRom.getDiskPutsRate() = " + anRom.getDiskPutsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY: anRom.setLocalMaxMemory( getIntegerAttribute(attribute.getValue(), attribute.getName())); LOGGER.fine("updateRegionOnMembers : anRom.getLocalMaxMemory() = " + anRom.getLocalMaxMemory()); break; } } anRom.getGetsPerSecTrend().add(anRom.getGetsRate()); anRom.getPutsPerSecTrend().add(anRom.getPutsRate()); anRom.getDiskReadsPerSecTrend().add(anRom.getDiskGetsRate()); anRom.getDiskWritesPerSecTrend().add(anRom.getDiskPutsRate()); LOGGER.fine("updateRegionOnMembers : Existing member on region : getGetsRate() = " + anRom.getGetsPerSecTrend().size() + ", getPutsRate() = " + anRom.getPutsPerSecTrend().size() + ", getDiskGetsRate() = " + anRom.getDiskReadsPerSecTrend().size() + ", getDiskPutsRate() = " + anRom.getDiskWritesPerSecTrend().size()); //remove existing member names from list so only new ones will remain memberNames.remove(anRom.getMemberName()); break; } } } LOGGER.fine( "updateRegionOnMembers : Loop over remaining member names and adding new member in region. Existing count = " + regionOnMemberList.size()); LOGGER.fine("updateRegionOnMembers : Remaining new members in this region = " + memberNames.size()); //loop over the remaining regions members and add new members for this region for (String memberName : memberNames) { String objectNameROM = PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObjectName + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + memberName; ObjectName regionOnMemberMBean = new ObjectName(objectNameROM); Cluster.RegionOnMember regionOnMember = new Cluster.RegionOnMember(); regionOnMember.setMemberName(memberName); regionOnMember.setRegionFullPath(regionFullPath); AttributeList attributeList = this.mbs.getAttributes(regionOnMemberMBean, PulseConstants.REGION_ON_MEMBER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE: regionOnMember.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_ENTRYCOUNT: regionOnMember.setEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE: regionOnMember.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE: regionOnMember.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: regionOnMember .setDiskGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: regionOnMember .setDiskPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCALMAXMEMORY: regionOnMember .setLocalMaxMemory(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; } } regionOnMember.getGetsPerSecTrend().add(regionOnMember.getGetsRate()); regionOnMember.getPutsPerSecTrend().add(regionOnMember.getPutsRate()); regionOnMember.getDiskReadsPerSecTrend().add(regionOnMember.getDiskGetsRate()); regionOnMember.getDiskWritesPerSecTrend().add(regionOnMember.getDiskPutsRate()); LOGGER.fine("updateRegionOnMembers : Adding New member on region : getGetsRate() = " + regionOnMember.getGetsRate() + ", getPutsRate() = " + regionOnMember.getPutsRate() + ", getDiskGetsRate() = " + regionOnMember.getDiskGetsRate() + ", getDiskPutsRate() = " + regionOnMember.getDiskPutsRate()); regionOnMemberListNew.add(regionOnMember); } //set region on member region.setRegionOnMembers(regionOnMemberListNew); LOGGER.fine("updateRegionOnMembers : Total regions on member in region " + region.getFullPath() + " after update = " + region.getRegionOnMembers().length); } catch (MalformedObjectNameException e) { LOGGER.warning(e); } catch (InstanceNotFoundException infe) { LOGGER.warning(infe); } catch (ReflectionException re) { LOGGER.warning(re); } }
From source file:com.cyberway.issue.crawler.Heritrix.java
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { this.mbeanServer = server; @SuppressWarnings("unchecked") Hashtable<String, String> ht = name.getKeyPropertyList(); if (!ht.containsKey(JmxUtils.NAME)) { throw new IllegalArgumentException("Name property required" + name.getCanonicalName()); }// w w w . j a va 2s . co m if (!ht.containsKey(JmxUtils.TYPE)) { ht.put(JmxUtils.TYPE, JmxUtils.SERVICE); name = new ObjectName(name.getDomain(), ht); } this.mbeanName = addGuiPort(addVitals(name)); Heritrix.instances.put(this.mbeanName.getCanonicalKeyPropertyListString(), this); return this.mbeanName; }
From source file:org.rhq.plugins.jbossas.util.DeploymentUtility.java
/** * Retrieves all the discovery information for a War resources. We are retrieving all the information * so that there is only ever one call to the MBeanServer to get the deployed mbeans, therefore saving * some performance if it did this for each and every war resource one at a time. * * @param connection EmsConnection to get the mbean information * @param jbossManMBeanNames Name of the main jboss.management mbeans for a collection of wars. * @return map holds all the war deployment information for the objects passed in the objectNames collection *//*from w w w.j a v a 2s.co m*/ public static Map<String, List<WarDeploymentInformation>> getWarDeploymentInformation(EmsConnection connection, List<String> jbossManMBeanNames) { // We need a list of informations, as one jsr77 deployment can end up in multiple web apps in different vhosts HashMap<String, List<WarDeploymentInformation>> retDeploymentInformationMap = new HashMap<String, List<WarDeploymentInformation>>(); // will contain information on all deployments Collection deploymentInfos; try { // NOTE: This is an expensive operation, since it returns a bunch of large objects. deploymentInfos = getDeploymentInformations(connection); } catch (Exception e) { return null; } String separator = System.getProperty("file.separator"); boolean isOnWin = separator.equals("\\"); // Loop through the deployment infos, and find the deployment infos corresponding to each of the // jboss.management/JSR77 MBean names that were passed into this method. From the deployment infos, // we can figure out the vhost(s) and context root for each WAR. for (Object deploymentInfo : deploymentInfos) { try { // NOTE: There may be more than one jboss.web MBean, // e.g. "jboss.web:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/jmx-console", // associated with a given WAR deployment, in which case, the "deployedObject" field will be // arbitrarily set to the name of one of the jboss.web MBeans. ObjectName jbossWebObjectName = getFieldValue(deploymentInfo, "deployedObject", ObjectName.class); if (jbossWebObjectName != null) { // e.g. "jmx-console.war" String shortName = getFieldValue(deploymentInfo, "shortName", String.class); for (String jbossManMBeanName : jbossManMBeanNames) { ObjectName jbossManObjectName = new ObjectName(jbossManMBeanName); String jbossManWarName = jbossManObjectName.getKeyProperty("name"); if (shortName.equals(jbossManWarName)) { log.debug("Found DeploymentInfo for WAR " + shortName + "."); // The only reliable way to determine the vhosts associated with the WAR is to use // the "mbeans" field, whose value is a list of all the Servlet MBeans, // .e.g. "jboss.web:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/jmx-console,j2eeType=Servlet,name=default", // corresponding to the WAR (one per servlet per vhost). List servletObjectNames = getFieldValue(deploymentInfo, "mbeans", List.class); Set<String> webModuleNames = new HashSet(); for (Object servletObjectName : servletObjectNames) { // e.g. Figure out the web module name, e.g. "//localhost/jmx-console". // NOTE: We must use reflection when working with the returned ObjectNames, since EMS // loaded them using a different classloader. Attempting to access them directly // would cause ClassCastExceptions. Class<? extends Object> objectNameClass = servletObjectName.getClass(); Method getKeyPropertyMethod = objectNameClass.getMethod("getKeyProperty", String.class); String webModuleName = (String) getKeyPropertyMethod.invoke(servletObjectName, "WebModule"); webModuleNames.add(webModuleName); } log.debug("Found " + webModuleNames.size() + " Web modules for WAR " + shortName + ": " + webModuleNames); String path = getPath(isOnWin, deploymentInfo); List<WarDeploymentInformation> infos = new ArrayList<WarDeploymentInformation>(); for (String webModuleName : webModuleNames) { WebModule webModule = parseWebModuleName(webModuleName); WarDeploymentInformation deploymentInformation = new WarDeploymentInformation(); deploymentInformation.setVHost(webModule.vhost); deploymentInformation.setFileName(path); deploymentInformation.setContextRoot(webModule.contextRoot); String jbossWebMBeanName = String.format(JBOSS_WEB_MBEAN_NAME_TEMPLATE, webModuleName); jbossWebObjectName = ObjectName.getInstance(jbossWebMBeanName); jbossWebMBeanName = jbossWebObjectName.getCanonicalName(); deploymentInformation.setJbossWebModuleMBeanObjectName(jbossWebMBeanName); infos.add(deploymentInformation); } retDeploymentInformationMap.put(jbossManMBeanName, infos); } } } } catch (Exception evalError) { log.warn("Failed to determine if a deployment contains our MBean", evalError); } } return retDeploymentInformationMap; }