/** * Retrieve the {@code ObjectName} instance corresponding to the supplied name. * @param objectName the {@code ObjectName} in {@code String} format * @return the {@code ObjectName} instance * @throws MalformedObjectNameException in case of an invalid object name specification * @see ObjectName#ObjectName(String) * @see ObjectName#getInstance(String) */ public static ObjectName getInstance(String objectName) throws MalformedObjectNameException { return ObjectName.getInstance(objectName); }
/** * Unregisters the {@code MBeanServer} instance, if necessary. */ @Override public void destroy() { if (this.newlyRegistered) { MBeanServerFactory.releaseMBeanServer(this.server); } }
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, java.lang.Object handback) { nbs.addNotificationListener(listener, filter, handback); }
/** * 根据指定的url来获取jmx服务返回的内容. * * @param connetion jmx连接 * @param url url内容 * @return the jmx返回的内容 * @throws Exception the exception */ private String getJmxResult(MBeanServerConnection connetion, String url) throws Exception { ObjectName name = new ObjectName(DruidStatService.MBEAN_NAME); String result = (String) conn.invoke(name, "service", new String[] { url }, new String[] { String.class.getName() }); return result; }
private Set<ObjectName> searchLiveBeansViewMeans() throws MalformedObjectNameException { String objectName = String.format("%s:*,%s=*", this.name.getMethodName(), LiveBeansView.MBEAN_APPLICATION_KEY); return ManagementFactory.getPlatformMBeanServer().queryNames(new ObjectName(objectName), null); }
@Test public void testDatesInJmx() throws Exception { // System.out.println(getServer().getClass().getName()); ObjectName oname = new ObjectName("bean:name=dateRange"); Date startJmx = (Date) getServer().getAttribute(oname, "StartDate"); Date endJmx = (Date) getServer().getAttribute(oname, "EndDate"); assertEquals("startDate ", getStartDate(), startJmx); assertEquals("endDate ", getEndDate(), endJmx); }
@Test public void mBeanExportAlsoWorks() throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); assertEquals("done", server.invoke(ObjectName.getInstance("test:type=TestBean"), "doSomething", new Object[0], new String[0])); }
@Override public MBeanInfo getMBeanInfo() { MBeanAttributeInfo attr = new MBeanAttributeInfo("name", "java.lang.String", "", true, false, false); return new MBeanInfo( TestDynamicMBean.class.getName(), "", new MBeanAttributeInfo[]{attr}, new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]); }
private void assertNickName(MBeanAttributeInfo attr) { assertNotNull("Nick Name should not be null", attr); assertTrue("Nick Name should be writable", attr.isWritable()); assertTrue("Nick Name should be readable", attr.isReadable()); }
@Override public MBeanInfo getMBeanInfo() { return new MBeanInfo(MyNotificationPublisherMBean.class.getName(), "", new MBeanAttributeInfo[0], new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]); }
@Override public void sendNotification() { sendNotification(new Notification("test", this, 1)); } }
@MXBean(true) public interface FooIfc { String getName(); }
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { nbs.removeNotificationListener(listener); }
/** * Replaces the notification source if necessary to do so. * From the {@link Notification javadoc}: * <i>"It is strongly recommended that notification senders use the object name * rather than a reference to the MBean object as the source."</i> * @param notification the {@link Notification} whose * {@link javax.management.Notification#getSource()} might need massaging */ private void replaceNotificationSourceIfNecessary(Notification notification) { if (notification.getSource() == null || notification.getSource().equals(this.managedResource)) { notification.setSource(this.objectName); } }
@Override public boolean isNotificationEnabled(Notification notification) { if (notification instanceof AttributeChangeNotification) { AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification; return "Name".equals(changeNotification.getAttributeName()); } else { return false; } } });
/** * Retrieve an {@code ObjectName} instance with the specified domain name * and the supplied key/name properties. * @param domainName the domain name for the {@code ObjectName} * @param properties the properties for the {@code ObjectName} * @return the {@code ObjectName} instance * @throws MalformedObjectNameException in case of an invalid object name specification * @see ObjectName#ObjectName(String, java.util.Hashtable) * @see ObjectName#getInstance(String, java.util.Hashtable) */ public static ObjectName getInstance(String domainName, Hashtable<String, String> properties) throws MalformedObjectNameException { return ObjectName.getInstance(domainName, properties); }
private void assertNickName(MBeanAttributeInfo attr) { assertNotNull("Nick Name should not be null", attr); assertTrue("Nick Name should be writable", attr.isWritable()); assertTrue("Nick Name should be readable", attr.isReadable()); }
@MXBean(false) public interface FooNotMXBean { String getName(); }
/** * Retrieve an {@code ObjectName} instance for the specified domain and a * single property with the supplied key and value. * @param domainName the domain name for the {@code ObjectName} * @param key the key for the single property in the {@code ObjectName} * @param value the value for the single property in the {@code ObjectName} * @return the {@code ObjectName} instance * @throws MalformedObjectNameException in case of an invalid object name specification * @see ObjectName#ObjectName(String, String, String) * @see ObjectName#getInstance(String, String, String) */ public static ObjectName getInstance(String domainName, String key, String value) throws MalformedObjectNameException { return ObjectName.getInstance(domainName, key, value); }
private static ObjectName createObjectName() throws MalformedObjectNameException { return ObjectName.getInstance("foo:type=bar"); }