Java Code Examples for javax.management.ObjectName#getCanonicalName()
The following examples show how to use
javax.management.ObjectName#getCanonicalName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMBeanServerInterceptor.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
Example 2
Source File: DefaultMBeanServerInterceptor.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
Example 3
Source File: DefaultMBeanServerInterceptor.java From JDKSourceCode1.8 with MIT License | 6 votes |
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
Example 4
Source File: DefaultMBeanServerInterceptor.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
Example 5
Source File: DefaultMBeanServerInterceptor.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
Example 6
Source File: DefaultMBeanServerInterceptor.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
Example 7
Source File: DefaultMBeanServerInterceptor.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
Example 8
Source File: DefaultMBeanServerInterceptor.java From hottub with GNU General Public License v2.0 | 6 votes |
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
Example 9
Source File: DefaultMBeanServerInterceptor.java From hottub with GNU General Public License v2.0 | 6 votes |
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
Example 10
Source File: DefaultMBeanServerInterceptor.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
Example 11
Source File: DefaultMBeanServerInterceptor.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 12
Source File: DefaultMBeanServerInterceptor.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 13
Source File: DefaultMBeanServerInterceptor.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 14
Source File: DefaultMBeanServerInterceptor.java From JDKSourceCode1.8 with MIT License | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 15
Source File: DefaultMBeanServerInterceptor.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 16
Source File: Client.java From vjtools with Apache License 2.0 | 5 votes |
protected static Object[] doBeans(final MBeanServerConnection mbsc, final ObjectName objName, final String[] command, final boolean oneBeanOnly) throws Exception { Object[] result = null; Set beans = mbsc.queryMBeans(objName, null); if (beans.isEmpty()) { // No bean found. Check if we are to create a bean? if (command.length == 1 && notEmpty(command[0]) && command[0].startsWith(CREATE_CMD_PREFIX)) { String className = command[0].substring(CREATE_CMD_PREFIX.length()); mbsc.createMBean(className, objName); } else { // TODO: Is there a better JMX exception that RE for this // scenario? throw new RuntimeException(objName.getCanonicalName() + " not registered."); } } else if (beans.size() == 1) { result = doBean(mbsc, (ObjectInstance) beans.iterator().next(), command); } else { if (oneBeanOnly) { throw new RuntimeException("Only supposed to be one bean " + "query result"); } // This is case of multiple beans in query results. // Print name of each into a StringBuffer. Return as one // result. StringBuffer buffer = new StringBuffer(); for (Iterator i = beans.iterator(); i.hasNext();) { Object obj = i.next(); if (obj instanceof ObjectName) { buffer.append((((ObjectName) obj).getCanonicalName())); } else if (obj instanceof ObjectInstance) { buffer.append((((ObjectInstance) obj).getObjectName().getCanonicalName())); } else { throw new RuntimeException("Unexpected object type: " + obj); } buffer.append("\n"); } result = new String[] { buffer.toString() }; } return result; }
Example 17
Source File: Client.java From vjtools with Apache License 2.0 | 5 votes |
protected static Object[] doBeans(final MBeanServerConnection mbsc, final ObjectName objName, final String[] command, final boolean oneBeanOnly) throws Exception { Object[] result = null; Set beans = mbsc.queryMBeans(objName, null); if (beans.size() == 0) { // No bean found. Check if we are to create a bean? if (command.length == 1 && notEmpty(command[0]) && command[0].startsWith(CREATE_CMD_PREFIX)) { String className = command[0].substring(CREATE_CMD_PREFIX.length()); mbsc.createMBean(className, objName); } else { // TODO: Is there a better JMX exception that RE for this // scenario? throw new RuntimeException(objName.getCanonicalName() + " not registered."); } } else if (beans.size() == 1) { result = doBean(mbsc, (ObjectInstance) beans.iterator().next(), command); } else { if (oneBeanOnly) { throw new RuntimeException("Only supposed to be one bean " + "query result"); } // This is case of multiple beans in query results. // Print name of each into a StringBuffer. Return as one // result. StringBuffer buffer = new StringBuffer(); for (Iterator i = beans.iterator(); i.hasNext();) { Object obj = i.next(); if (obj instanceof ObjectName) { buffer.append((((ObjectName) obj).getCanonicalName())); } else if (obj instanceof ObjectInstance) { buffer.append((((ObjectInstance) obj).getObjectName().getCanonicalName())); } else { throw new RuntimeException("Unexpected object type: " + obj); } buffer.append("\n"); } result = new String[] { buffer.toString() }; } return result; }
Example 18
Source File: DefaultMBeanServerInterceptor.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
Example 19
Source File: MBeanDeployerTest.java From tomee with Apache License 2.0 | 4 votes |
@Test public void mbeans() throws Exception { final Set<String> parsed = new HashSet<>(); for (final Object name : appInfo.jmx.values()) { final ObjectName on = new ObjectName((String) name); final String cn = on.getCanonicalName(); if (cn.contains("name=Empty")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); parsed.add(cn); } else if (cn.contains("name=Reader")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); assertEquals(2, server.getAttribute(on, "value")); parsed.add(cn); } else if (cn.contains("name=ReaderWriter")) { assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); assertEquals(2, server.getAttribute(on, "value")); server.setAttribute(on, new Attribute("value", 5)); assertEquals(5, server.getAttribute(on, "value")); parsed.add(cn); } else if (cn.contains("name=Inheritance")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); assertEquals(2, server.getAttribute(on, "value")); server.setAttribute(on, new Attribute("value", 5)); assertEquals(5, server.getAttribute(on, "value")); assertEquals("yes - no", server.invoke(on, "returnValue", null, null)); parsed.add(cn); } else if (cn.contains("name=MBeanDescription")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); assertEquals("descr ;)", server.getMBeanInfo(on).getDescription()); parsed.add(cn); } else if (cn.contains("name=Operation")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); final MBeanInfo info = server.getMBeanInfo(on); if ("desc".equals(info.getOperations()[0].getName())) { assertEquals("param", info.getOperations()[0].getSignature()[0].getDescription()); } else { assertEquals("param", info.getOperations()[1].getSignature()[0].getDescription()); } assertTrue(server.isRegistered(on)); assertEquals("yes - no", server.invoke(on, "returnValue", null, null)); parsed.add(cn); } else if (cn.contains("name=ReaderDescription")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(cn.contains("name=ReaderDescription")); assertTrue(server.isRegistered(on)); assertEquals(1, server.getMBeanInfo(on).getAttributes().length); assertEquals("just a value", server.getMBeanInfo(on).getAttributes()[0].getDescription()); parsed.add(cn); } else if (cn.contains("name=OperationDescription")) { assertTrue(cn.startsWith("openejb.user.mbeans")); assertTrue(cn.contains("group=org.apache.openejb.mbeans")); assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule")); assertTrue(server.isRegistered(on)); assertEquals(1, server.getMBeanInfo(on).getOperations().length); assertEquals("just an op", server.getMBeanInfo(on).getOperations()[0].getDescription()); parsed.add(cn); } } assertEquals(8, parsed.size()); }
Example 20
Source File: JmxWorker.java From smallrye-metrics with Apache License 2.0 | 4 votes |
/** * We need to expand entries that are marked with the <b>multi</b> flag * into the actual MBeans. This is done by replacing a placeholder of <b>%s</b> * in the name and MBean name with the real Mbean key-value. * * @param entries List of entries */ public void expandMultiValueEntries(List<ExtendedMetadataAndTags> entries) { List<ExtendedMetadataAndTags> result = new ArrayList<>(); List<ExtendedMetadataAndTags> toBeRemoved = new ArrayList<>(entries.size()); for (ExtendedMetadataAndTags entry : entries) { if (entry.getMetadata().isMulti()) { String name = entry.getMetadata().getMbean(); String attName; String queryableName; int slashIndex = name.indexOf('/'); // MBeanName is invalid, lets skip this altogether if (slashIndex < 0) { toBeRemoved.add(entry); continue; } queryableName = name.substring(0, slashIndex); attName = name.substring(slashIndex + 1); try { ObjectName objectNameWithPlaceholders = new ObjectName(queryableName); final Map<String, String> keyHolders = findComponentPairsWithPlaceholders(objectNameWithPlaceholders); ObjectName objectName = new ObjectName(queryableName.replaceAll(PLACEHOLDER + "(\\d)?+", "*")); Set<ObjectName> objNames = mbs.queryNames(objectName, null); for (ObjectName oName : objNames) { String newName = entry.getMetadata().getName(); if (!newName.contains(PLACEHOLDER) && entry.getTags().isEmpty()) { SmallRyeMetricsLogging.log.nameDoesNotContainPlaceHoldersOrTags(newName); } String newDisplayName = entry.getMetadata().getDisplayName(); String newDescription = entry.getMetadata().getDescription(); List<Tag> newTags = new ArrayList<>(entry.getTags()); for (final Entry<String, String> keyHolder : keyHolders.entrySet()) { String keyValue = oName.getKeyPropertyList().get(keyHolder.getValue()); newName = newName.replaceAll(Pattern.quote(keyHolder.getKey()), keyValue); newDisplayName = newDisplayName.replaceAll(Pattern.quote(keyHolder.getKey()), keyValue); newDescription = newDescription.replaceAll(Pattern.quote(keyHolder.getKey()), keyValue); newTags = newTags.stream() .map(originalTag -> new Tag(originalTag.getTagName(), originalTag.getTagValue().replaceAll(Pattern.quote(keyHolder.getKey()), keyValue))) .collect(Collectors.toList()); } String newObjectName = oName.getCanonicalName() + "/" + attName; ExtendedMetadata newEntryMetadata = new ExtendedMetadata(newName, newDisplayName, newDescription, entry.getMetadata().getTypeRaw(), entry.getMetadata().getUnit(), newObjectName, true); ExtendedMetadataAndTags newEntry = new ExtendedMetadataAndTags(newEntryMetadata, newTags); result.add(newEntry); } toBeRemoved.add(entry); } catch (MalformedObjectNameException e) { throw SmallRyeMetricsMessages.msg.malformedObjectName(e); } } } entries.removeAll(toBeRemoved); entries.addAll(result); }