List of usage examples for javax.management ObjectName getInstance
public static ObjectName getInstance(ObjectName name)
Return an instance of ObjectName that can be used anywhere the given object can be used.
From source file:fr.xebia.springframework.jms.ManagedDefaultMessageListenerContainer.java
public ObjectName getObjectName() throws MalformedObjectNameException { if (objectName == null) { String destinationName = getDestinationName(); Destination destination = getDestination(); if (destinationName == null && destination != null) { try { if (destination instanceof Queue) { Queue queue = (Queue) destination; destinationName = queue.getQueueName(); } else if (destination instanceof Topic) { Topic topic = (Topic) destination; destinationName = topic.getTopicName(); }/*from w ww. j a v a 2 s . c o m*/ } catch (JMSException e) { throw new UncategorizedJmsException(e); } } objectName = ObjectName.getInstance("javax.jms:type=MessageListenerContainer,name=" + ObjectName.quote(getBeanName()) + ",destination=" + destinationName); } return objectName; }
From source file:utilities.srvRutinas.java
public static double getProcessCpuLoad() throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem"); AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" }); if (list.isEmpty()) return Double.NaN; Attribute att = (Attribute) list.get(0); Double value = (Double) att.getValue(); // usually takes a couple of seconds before we get real values if (value == -1.0) return Double.NaN; // returns a percentage value with 1 decimal point precision return ((int) (value * 1000) / 10.0); }
From source file:org.eclipse.virgo.ide.runtime.internal.core.command.AbstractJmxServerDeployerCommand.java
/** * Method to be called by sub-classes to execute given command against the MBean *///from w w w . ja v a2 s. c om @SuppressWarnings("unchecked") protected final T doExecute() throws IOException, TimeoutException { JmxServerCommandTemplate template = new JmxServerCommandTemplate() { public Object invokeOperation(MBeanServerConnection connection) throws Exception { ObjectName name = ObjectName.getInstance(getMBeanName()); Object[] operationArguments = getOperationArguments(); String[] classNames = new String[operationArguments.length]; for (int i = 0; i < operationArguments.length; i++) { if (operationArguments[i] instanceof Boolean) { classNames[i] = boolean.class.getName(); } else { classNames[i] = operationArguments[i].getClass().getName(); } } return connection.invoke(name, getOperationName(), operationArguments, classNames); } }; return (T) execute(template); }
From source file:com.adaptris.core.runtime.RetryMessageErrorHandlerMonitorTest.java
public void testMBean_FailAllMessages() throws Exception { String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); MockMessageProducer failProducer = new MockMessageProducer(); RetryMessageErrorHandler handler = new RetryMessageErrorHandler(getName(), new StandaloneProducer(failProducer)); adapter.setMessageErrorHandler(handler); AdapterManager adapterManager = new AdapterManager(adapter); try {/*from w ww . j a va 2 s .c o m*/ registerMBeans(adapterManager); adapterManager.requestStart(); ObjectName retryObjectName = ObjectName.getInstance( JMX_RETRY_MONITOR_TYPE + adapterManager.createObjectHierarchyString() + ID_PREFIX + getName()); RetryMessageErrorHandlerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, retryObjectName, RetryMessageErrorHandlerMonitorMBean.class); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); // 10 retries 10 minutes apart, so it should be waiting. handler.handleProcessingException(msg); assertEquals(1, mbean.waitingForRetry().size()); assertTrue(mbean.waitingForRetry().contains(msg.getUniqueId())); mbean.failAllMessages(true); assertEquals(1, failProducer.messageCount()); handler.handleProcessingException(AdaptrisMessageFactory.getDefaultInstance().newMessage()); // All msgs Fail. assertEquals(0, mbean.waitingForRetry().size()); assertEquals(2, failProducer.messageCount()); } finally { adapterManager.requestClose(); } }
From source file:com.mtgi.analytics.jmx.StatisticsMBeanEventPersisterTest.java
@Test public void testMbeanRegistration() throws FailingHttpStatusCodeException, IOException, SQLException, JMException, InterruptedException { ObjectName[] all = {/*from w w w . ja va 2 s . co m*/ ObjectName.getInstance("testApp:type=http-request-monitor,name=/testApp/test/invoke.do"), ObjectName.getInstance("testApp:type=http-request-monitor,name=/testApp/test/invoke.do," + "nested=method_com.mtgi.analytics.jmx.StatisticsMBeanEventPersisterTest$Service.save"), ObjectName.getInstance("testApp:type=http-request-monitor,name=/testApp/test/invoke.do," + "nested=method_com.mtgi.analytics.jmx.StatisticsMBeanEventPersisterTest$Service.save," + "nested[2]=jdbc_executeBatch") }; MBeanServer jmx = JmxUtils.locateMBeanServer(); for (ObjectName on : all) assertFalse("statistics mbean " + on + " is not yet registered", jmx.isRegistered(on)); assertEquals("no data in test db yet", 0, countRecords()); webClient.getPage(baseUrl + "/testApp/test/invoke.do?id=1&value=hello"); assertEquals("test service invoked", 1, countRecords()); //verify that we receive updated statistics for each of our monitored events for (ObjectName on : all) waitForCount(on, 1); //post again, and verify that the now-registered mbeans are updated. webClient.getPage(baseUrl + "/testApp/test/invoke.do?id=2&value=world"); assertEquals("test service invoked", 2, countRecords()); for (ObjectName on : all) waitForCount(on, 2); }
From source file:co.paralleluniverse.common.spring.MBeanNamingStrategy.java
@Override public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { Class managedClass = AopUtils.getTargetClass(managedBean); ManagedResource mr = this.attributeSource.getManagedResource(managedClass); // Check that an object name has been specified. if (mr != null && StringUtils.hasText(mr.getObjectName())) { return ObjectName.getInstance(mr.getObjectName()); } else {/*from www . j a v a 2 s. c om*/ String domain = this.defaultDomain; if (domain == null) domain = ClassUtils.getPackageName(managedClass); return ObjectName.getInstance(domain + ":type=components,name=" + beanKey); } }
From source file:org.apache.axis2.transport.base.TransportMBeanSupport.java
private TransportMBeanSupport(String connectorName, TransportView mbeanInstance) { try {//from w ww .j a v a 2s. c o m mbs = ManagementFactory.getPlatformMBeanServer(); } catch (SecurityException ex) { log.warn("Unable to get the platform MBean server; JMX support disabled", ex); enabled = false; return; } String jmxAgentName = System.getProperty("jmx.agent.name"); if (jmxAgentName == null || "".equals(jmxAgentName)) { jmxAgentName = "org.apache.axis2"; } String mbeanNameString = jmxAgentName + ":Type=Transport,ConnectorName=" + connectorName; try { mbeanName = ObjectName.getInstance(mbeanNameString); } catch (MalformedObjectNameException ex) { log.warn("Unable to create object name '" + mbeanNameString + "'; JMX support disabled", ex); enabled = false; } this.mbeanInstance = mbeanInstance; }
From source file:uk.co.gidley.jmxmonitor.services.InternalJmx.java
public InternalJmx(MainConfiguration configuration, RegistryShutdownHub registryShutdownHub) throws InitialisationException, MalformedObjectNameException { //TODO make this a symbol this.PROPERTY_PREFIX = ThreadManager.PROPERTY_PREFIX; registryShutdownHub.addRegistryShutdownListener(this); connectorServerName = ObjectName.getInstance("connectors:protocol=rmi"); MBEAN_SERVER = ManagementFactory.getPlatformMBeanServer(); start(configuration.getConfiguration()); }
From source file:org.jboss.snowdrop.context.support.JBossJcaResourceAdapterParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { ClassLoader classLoader = getClass().getClassLoader(); if (classLoader.getClass().getName().startsWith("org.jboss.classloader")) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setFactoryBeanName(DEFAULT_JBOSS_MBEAN_SERVER_BEAN_NAME); builder.getRawBeanDefinition().setFactoryMethodName(FACTORY_METHOD_NAME); try {//from w ww. j av a2s.com builder.addConstructorArgValue(ObjectName.getInstance(DEFAULT_JCA_MBEAN_NAME)); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e); } builder.addConstructorArgValue("ResourceAdapter"); return builder.getBeanDefinition(); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition("org.jboss.snowdrop.context.support.ActivatorHolder"); builder.setFactoryMethod("getResourceAdapter"); return builder.getBeanDefinition(); } }
From source file:com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool.java
@Override public void setObjectName(String objectName) throws MalformedObjectNameException { this.objectName = ObjectName.getInstance(objectName); }