List of usage examples for javax.management MBeanServerConnection isRegistered
public boolean isRegistered(ObjectName name) throws IOException;
From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxApplicationManager.java
private void fetchAndApplySessionCount(Properties configProperties, String hostName, Application application, boolean tomcat7) throws PluginException { Integer sessionCount = 0;/*from w w w. j a v a 2 s. c om*/ String appObjectName = ObjectNameUtils.getManagerMBeanObjectNameForApplication(hostName, application, tomcat7); try { MBeanServerConnection mbsc = mxUtil.getMBeanServer(configProperties); boolean mbeanIsRegistered = mbsc.isRegistered(new ObjectName(appObjectName)); if (mbeanIsRegistered) { sessionCount = (Integer) mxUtil.getValue(configProperties, appObjectName, "activeSessions"); } application.setSessionCount(sessionCount); } catch (PluginException pe) { throw pe; } catch (Exception e) { throw createPluginException(e); } }
From source file:org.helios.collector.jmx.connection.AbstractMBeanServerConnectionFactory.java
/** * Determines if the passed ObjectName is registered * @param objectName/*w w w. j av a 2s .c o m*/ * @return * @throws IOException */ @Override @ManagedOperation public boolean isRegistered(ObjectName objectName) throws IOException { validateConn(); MBeanServerConnection conn = null; try { conn = getPooledConnection(); return conn.isRegistered(objectName); } catch (MBeanServerConnectionFactoryException e) { throw new RuntimeException("Failed to get pooled connection", e); } finally { try { this.returnPooledConnection(conn); } catch (Exception e) { log.debug(e.getMessage()); } } }
From source file:org.springframework.integration.jmx.DefaultMBeanObjectConverter.java
@Override public Object convert(MBeanServerConnection connection, ObjectInstance instance) { Map<String, Object> attributeMap = new HashMap<String, Object>(); try {/*from w w w . jav a 2 s. c o m*/ ObjectName objName = instance.getObjectName(); if (!connection.isRegistered(objName)) { return attributeMap; } MBeanInfo info = connection.getMBeanInfo(objName); MBeanAttributeInfo[] attributeInfos = info.getAttributes(); for (MBeanAttributeInfo attrInfo : attributeInfos) { // we don't need to repeat name of this as an attribute if ("ObjectName".equals(attrInfo.getName()) || !this.filter.accept(objName, attrInfo.getName())) { continue; } Object value; try { value = connection.getAttribute(objName, attrInfo.getName()); } catch (RuntimeMBeanException e) { // N.B. standard MemoryUsage MBeans will throw an exception when some // measurement is unsupported. Logging at trace rather than debug to // avoid confusion. if (log.isTraceEnabled()) { log.trace("Error getting attribute '" + attrInfo.getName() + "' on '" + objName + "'", e); } // try to unwrap the exception somewhat; not sure this is ideal Throwable t = e; while (t.getCause() != null) { t = t.getCause(); } value = String.format("%s[%s]", t.getClass().getName(), t.getMessage()); } attributeMap.put(attrInfo.getName(), checkAndConvert(value)); } } catch (Exception e) { throw new IllegalArgumentException(e); } return attributeMap; }
From source file:org.xmatthew.spy2servers.component.spy.jmx.TomcatJmxSpyComponent.java
@Override public void mscOnInterval(MBeanServerConnection mbsc) throws Exception { super.mscOnInterval(mbsc); if (webModuleSpy == null) { return;//from w ww. jav a 2 s.com } Set<String> webModules = webModuleSpy.getWebModules(); if (CollectionUtils.isBlankCollection(webModules)) { return; } String mbeanName; ObjectName objectName; String webStatus; boolean registered; for (String webModule : webModules) { mbeanName = String.format(WEB_MODULE_MBNAME, webModule); objectName = new ObjectName(mbeanName); registered = mbsc.isRegistered(objectName); if (webModuleSpy.spyWebModule(webModule, registered)) { if (registered) { webStatus = WEB_MODULE_ON; } else { webStatus = WEB_MODULE_OFF; } onSpy(createMessage(webModule, webStatus, Message.LV_ERROR, WEB_MODULE_STATUS, new HashMap<String, Object>())); } } }