List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java
private int getDeadlockedThreadCount(MBeanServerConnection connection) throws MetricInvalidException, MetricUnreachableException { int deadlockCount = 0; try {/*from w w w . j ava 2s .c o m*/ // in version 1.6+ there is a findDeadlockedThreads method long[] deadlocks; try { deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"), "findDeadlockedThreads", null, null); } catch (MalformedObjectNameException e) { throw new MetricInvalidException("Error querying for deadlock thread mbean: " + e.getMessage(), e); } catch (JMException e) { LOGGER.debug("Method 'findDeadlockedThreads' for objectname 'java.lang:type=Threading'" + "was not found. Trying method findMonitorDeadlockedThreads...", e); // If this occurs then the issue is most likely related to the // Java version. // Now check for the method on java 1.5 try { deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"), "findMonitorDeadlockedThreads", null, null); } catch (MalformedObjectNameException me) { throw new MetricInvalidException("Error querying for deadlock thread mbean: " + me.getMessage(), me); } catch (JMException ex) { LOGGER.debug("Unable to retrieve DeadlockedThreads count: ", ex); throw new MetricUnreachableException( "Unable to reach deadlock thread mbean: " + ex.getMessage(), ex); } } if (deadlocks != null) { deadlockCount = deadlocks.length; } return deadlockCount; } catch (IOException e) { throw new MetricUnreachableException("Error querying for deadlock thread mbean: " + e.getMessage(), e); } }
From source file:com.nabla.project.application.core.spring.ExtractionScope.java
/** * DOCUMENT ME!// ww w .j ava 2 s. co m * * @param beanName DOCUMENT ME! * @return DOCUMENT ME! */ public Object remove(String beanName) { RequestId requestId = (RequestId) extractionId.get(); if (logger.isDebugEnabled()) { logger.debug("remove(" + beanName + ") extractionId=" + requestId); } Object bean = null; Map<String, Object> beansMap = scopeMaps.get(requestId); if (beansMap != null) { beansMap.remove(beanName); } try { ObjectName name = new ObjectName(getJmxObjectName(beanName, requestId)); mbs.unregisterMBean(name); if (logger.isDebugEnabled()) { logger.debug("JMX registration done for " + name); } } catch (Exception ex) { logger.warn(ex); } return bean; }
From source file:com.taobao.tddl.common.util.TDDLMBeanServer.java
private void registerMBeanWithId0(Object o, String id) { // MBean/* ww w . jav a2s . co m*/ if (null == id || id.length() == 0) { throw new IllegalArgumentException("must set id"); } if (null != mbs) { try { mbs.registerMBean(o, new ObjectName(o.getClass().getPackage().getName() + ":type=" + o.getClass().getSimpleName() + ",id=" + id)); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:org.fishwife.jrugged.spring.PerformanceMonitorBeanFactory.java
/** * Create a new {@link PerformanceMonitorBean} and map it to the provided * name. If the {@link MBeanExportOperations} is set, then the * PerformanceMonitorBean will be exported as a JMX MBean. * If the PerformanceMonitor already exists, then the existing instance is * returned.// w ww. j a v a 2s. com * @param name the value for the {@link PerformanceMonitorBean} * @return the created {@link PerformanceMonitorBean} * @throws IllegalArgumentException if the MBean value is invalid. */ public synchronized PerformanceMonitor createPerformanceMonitor(String name) { PerformanceMonitorBean performanceMonitor = findPerformanceMonitorBean(name); if (performanceMonitor == null) { performanceMonitor = new PerformanceMonitorBean(); if (mBeanExportOperations != null) { ObjectName objectName; try { objectName = new ObjectName( "org.fishwife.jrugged.spring:type=" + "PerformanceMonitorBean,name=" + name); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Invalid MBean Name " + name, e); } mBeanExportOperations.registerManagedResource(performanceMonitor, objectName); } addPerformanceMonitorToMap(name, performanceMonitor); } return performanceMonitor; }
From source file:com.sun.grizzly.http.jk.common.JniHandler.java
protected void initNative(String nativeComponentName) { apr = (AprImpl) wEnv.getHandler("apr"); if (apr == null) { // In most cases we can just load it automatically. // that requires all libs to be installed in standard places // ( LD_LIBRARY_PATH, /usr/lib try {// ww w . j av a 2 s . c o m apr = new AprImpl(); wEnv.addHandler("apr", apr); apr.init(); if (oname != null) { ObjectName aprname = new ObjectName(oname.getDomain() + ":type=JkHandler, name=apr"); Registry.getRegistry(null, null).registerComponent(apr, aprname, null); } } catch (Throwable t) { LoggerUtils.getLogger().log(Level.FINEST, "Can't load apr", t); apr = null; } } if (apr == null || !apr.isLoaded()) { if (LoggerUtils.getLogger().isLoggable(Level.FINEST)) { LoggerUtils.getLogger().log(Level.FINEST, "No apr, disabling jni proxy "); } apr = null; return; } try { long xEnv = apr.getJkEnv(); nativeJkHandlerP = apr.getJkHandler(xEnv, nativeComponentName); if (nativeJkHandlerP == 0) { LoggerUtils.getLogger().log(Level.FINEST, "Component not found, creating it " + nativeComponentName); nativeJkHandlerP = apr.createJkHandler(xEnv, nativeComponentName); } LoggerUtils.getLogger().log(Level.FINEST, "Native proxy " + nativeJkHandlerP); apr.releaseJkEnv(xEnv); } catch (Throwable t) { apr = null; } }
From source file:net.sf.ehcache.management.ManagementServiceTest.java
/** * Integration test for the registration service *//* w ww.j a v a2 s. com*/ public void testMultipleCacheManagers() throws Exception { ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true); assertEquals(OBJECTS_IN_TEST_EHCACHE, mBeanServer.queryNames(new ObjectName("net.sf.ehcache:*"), null).size()); File file = new File(AbstractCacheTest.SRC_CONFIG_DIR + "ehcache.xml"); Configuration configuration = ConfigurationFactory.parseConfiguration(file); net.sf.ehcache.CacheManager secondCacheManager = new net.sf.ehcache.CacheManager(configuration); ManagementService.registerMBeans(secondCacheManager, mBeanServer, true, true, true, true); assertEquals(59, mBeanServer.queryNames(new ObjectName("net.sf.ehcache:*"), null).size()); secondCacheManager.shutdown(); assertEquals(OBJECTS_IN_TEST_EHCACHE, mBeanServer.queryNames(new ObjectName("net.sf.ehcache:*"), null).size()); }
From source file:com.fatwire.dta.sscrawler.URLReaderService.java
public void start(final ProgressMonitor monitor) { connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setConnectionTimeout(30000); connectionManager.getParams().setDefaultMaxConnectionsPerHost(1500); connectionManager.getParams().setMaxTotalConnections(30000); final MBeanServer platform = java.lang.management.ManagementFactory.getPlatformMBeanServer(); try {// w ww. j av a2 s.c o m platform.registerMBean(new ReaderService(scheduler, connectionManager), new ObjectName("com.fatwire.crawler:name=scheduler")); } catch (final Throwable t) { log.error(t.getMessage(), t); } monitor.beginTask("Crawling on " + hostConfig.toString(), maxPages == Integer.MAX_VALUE ? -1 : maxPages); scheduler.monitor = monitor; for (final QueryString thingToDo : startUrls) { scheduler.schedulePage(thingToDo); } scheduler.waitForlAllTasksToFinish(); try { connectionManager.shutdown(); } catch (final Throwable t) { log.error(t.getMessage(), t); } try { platform.unregisterMBean(new ObjectName("com.fatwire.crawler:name=scheduler")); } catch (final Throwable t) { log.error(t.getMessage(), t); } monitor.done(); }
From source file:io.fabric8.support.impl.SupportServiceImpl.java
protected ObjectName getObjectName() throws Exception { return new ObjectName(SUPPORT_TYPE_SUPPORT_SERVICE_MBEAN); }
From source file:com.funambol.server.db.DataSourceContextHelper.java
/** * Registers the given DataSouce as a MBean * @param ds the datasource/* w w w. java 2 s .com*/ * @param name the name * @throws java.lang.Exception if an error occurs */ private static void registerMBean(DataSource ds, String name) throws Exception { ObjectName on = new ObjectName("com.funambol:type=DataSource,name=" + name); Registry.getRegistry(null, null).registerComponent(ds, on, null); }
From source file:com.clustercontrol.jmx.factory.RunMonitorJmx.java
/** * JMX ??/*from ww w. j a va2 s . com*/ * * @param facilityId ID * @return ???????true */ @Override public boolean collect(String facilityId) { boolean result = false; if (m_now != null) { m_nodeDate = m_now.getTime(); } m_value = 0; exception = null; NodeInfo node = null; if (!m_isMonitorJob) { node = nodeInfo.get(facilityId); } else { try { // ?? node = new RepositoryControllerBean().getNode(facilityId); } catch (Exception e) { m_message = MessageConstant.MESSAGE_COULD_NOT_GET_NODE_ATTRIBUTES.getMessage(); return false; } } JMXServiceURL url = null; try { String rmiFormat = HinemosPropertyUtil.getHinemosPropertyStr("monitor.jmx.rmi.format", "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"); String urlStr = String.format(rmiFormat, node.getAvailableIpAddress(), jmx.getPort()); m_log.debug("facilityId=" + facilityId + ", url=" + urlStr); url = new JMXServiceURL(urlStr); } catch (Exception e) { m_log.warn("fail to initialize JMXServiceURL : " + e.getMessage() + " (" + e.getClass().getName() + ")", e); exception = e; return result; } JMXConnector jmxc = null; try { Map<String, Object> env = new HashMap<>(); if (jmx.getAuthUser() != null) env.put(JMXConnector.CREDENTIALS, new String[] { jmx.getAuthUser(), jmx.getAuthPassword() }); System.setProperty("sun.rmi.transport.tcp.responseTimeout", Integer.toString(HinemosPropertyUtil .getHinemosPropertyNum("system.sun.rmi.transport.tcp.responseTimeout", Long.valueOf(10 * 1000)) .intValue())); jmxc = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); JmxMasterInfo jmxMasterInfo = QueryUtil.getJmxMasterInfoPK(jmx.getMasterId()); Object value = mbsc.getAttribute(new ObjectName(jmxMasterInfo.getObjectName()), jmxMasterInfo.getAttributeName()); m_value = Double.parseDouble( searchTargetValue(value, Arrays.asList(KeyParser.parseKeys(jmxMasterInfo.getKeys()))) .toString()); // ?? if (m_convertFlg == ConvertValueConstant.TYPE_DELTA) { // ?? MonitorJmxValue valueEntity = null; Double prevValue = 0d; Long prevDate = 0l; if (!m_isMonitorJob) { // ?? // cache?? valueEntity = MonitorJmxCache.getMonitorJmxValue(m_monitorId, facilityId); // ??? prevValue = valueEntity.getValue(); if (valueEntity.getGetDate() != null) { prevDate = valueEntity.getGetDate(); } } else { // ?? valueEntity = new MonitorJmxValue(new MonitorJmxValuePK(m_monitorId, facilityId)); if (m_prvData instanceof MonitorJmxValue) { // ???? prevValue = ((MonitorJmxValue) m_prvData).getValue(); prevDate = ((MonitorJmxValue) m_prvData).getGetDate(); } } // JMX???? valueEntity.setValue(Double.valueOf(m_value)); valueEntity.setGetDate(m_nodeDate); if (!m_isMonitorJob) { // ???ID????? if (m_monitor.getMonitorFlg()) MonitorJmxCache.update(m_monitorId, facilityId, valueEntity); int m_validSecond = HinemosPropertyUtil .getHinemosPropertyNum("monitor.jmx.valid.second", Long.valueOf(15)).intValue(); // ??????????? int tolerance = (m_runInterval + m_validSecond) * 1000; if (prevDate > m_nodeDate - tolerance) { // ??null??? if (prevValue == null) { m_log.debug("collect() : prevValue is null"); m_prevNullchk = true; return false; } m_value = m_value - prevValue; } else { if (prevDate != 0l) { DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(HinemosTime.getTimeZone()); String[] args = { df.format(new Date(prevDate)) }; m_message = MessageConstant.MESSAGE_TOO_OLD_TO_CALCULATE.getMessage(args); return false; } else { // ???0?? m_nodeDate = 0l; } } } else { m_value = m_value - prevValue; m_curData = valueEntity; } } m_log.debug(jmxMasterInfo.getName() + " : " + m_value + " " + jmxMasterInfo.getMeasure()); result = true; } catch (NumberFormatException e) { m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); String[] args = { Double.toString(m_value) }; m_message = MessageConstant.MESSAGE_COULD_NOT_GET_NUMERIC_VALUE.getMessage(args); return false; } catch (Exception e) { String message = e.getMessage(); if (message != null) { message = message.replaceAll("\n", ""); } m_log.warn("fail to access JMXService : " + message + " (" + e.getClass().getName() + ")"); exception = e; } finally { try { if (jmxc != null) { jmxc.close(); } } catch (IOException e) { m_log.info("fail to close JMXService : " + e.getMessage() + " (" + e.getClass().getName() + ")"); exception = e; } } return result; }