@Override public String description() { return "Waiting for the proxy of " + objectName.getCanonicalName() + " to get propagated to Manager"; }
private String toPattern(String tableName) throws MalformedObjectNameException { if (!tableName.contains("*")) { return Pattern.quote(new ObjectName(tableName).getCanonicalName()); } return Streams.stream(Splitter.on('*').split(tableName)) .map(Pattern::quote) .collect(Collectors.joining(".*")); }
private List<SchemaTableName> listJmxTables() { Builder<SchemaTableName> tableNames = ImmutableList.builder(); for (ObjectName objectName : mbeanServer.queryNames(WILDCARD, null)) { // todo remove lower case when presto supports mixed case names tableNames.add(new SchemaTableName(JMX_SCHEMA_NAME, objectName.getCanonicalName().toLowerCase(ENGLISH))); } return tableNames.build(); }
@Mapping( "name" ) public ValueRepresentation getName() { return ValueRepresentation.string( beanName.getCanonicalName() ); }
/** * Performs cleanup for deregistering this MBean. Default implementation * unregisters MBean instances which are registered using * {@link #registerMBean(Object mbean, ObjectName objectName)}. */ public void preDeregister() { getLogger().debug("preDeregister called."); Enumeration iterator = mbeanList.elements(); while (iterator.hasMoreElements()) { ObjectName name = (ObjectName) iterator.nextElement(); try { server.unregisterMBean(name); } catch (InstanceNotFoundException e) { getLogger().warn("Missing MBean " + name.getCanonicalName()); } catch (MBeanRegistrationException e) { getLogger().warn("Failed unregistering " + name.getCanonicalName()); } } }
/** * Add results from a value of type objet name array. */ private void add(String attributeName, ImmutableList.Builder<String> valuePath, ObjectName[] objs) { ImmutableMap.Builder<String, Object> values = ImmutableMap.builder(); for (ObjectName obj : objs) { values.put(obj.getCanonicalName(), obj.getKeyPropertyListString()); } addNew(attributeName, valuePath, values.build()); }
public void assertSingleLiveBeansViewMbean(String applicationName) throws MalformedObjectNameException { Set<ObjectName> objectNames = searchLiveBeansViewMeans(); assertEquals(1, objectNames.size()); assertEquals("Wrong MBean name", String.format("%s:application=%s", this.name.getMethodName(), applicationName), objectNames.iterator().next().getCanonicalName()); }
/** * */ private TransactionsMXBean txMXBean(int igniteInt) throws Exception { ObjectName mbeanName = U.makeMBeanName(getTestIgniteInstanceName(igniteInt), "Transactions", TransactionsMXBeanImpl.class.getSimpleName()); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, TransactionsMXBean.class, true); }
/** * */ private TransactionsMXBean txMXBean(int igniteInt) throws Exception { ObjectName mbeanName = U.makeMBeanName(getTestIgniteInstanceName(igniteInt), "Transactions", TransactionsMXBeanImpl.class.getSimpleName()); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, TransactionsMXBean.class, true); } }
/** * @return IO statistics MX bean for node with given index. * @throws Exception In case of failure. */ private IoStatisticsMetricsMXBean ioStatMXBean() throws Exception { ObjectName mbeanName = U.makeMBeanName(getTestIgniteInstanceName(0), "IOMetrics", IoStatisticsMetricsLocalMXBeanImpl.class.getSimpleName()); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, IoStatisticsMetricsMXBean.class, false); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testRegisterNotificationListenerWithWildcard() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); JmxTestBean bean = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); Map notificationListeners = new HashMap(); notificationListeners.put("*", listener); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); exporter.setNotificationListenerMappings(notificationListeners); start(exporter); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testRegisterNotificationListenerForMBean() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); JmxTestBean bean = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); Map notificationListeners = new HashMap(); notificationListeners.put(objectName, listener); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); exporter.setNotificationListenerMappings(notificationListeners); start(exporter); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); }
/** * */ private TransactionMetricsMxBean txMetricsMXBean(int igniteInt) throws Exception { ObjectName mbeanName = U.makeMBeanName( getTestIgniteInstanceName(igniteInt), "TransactionMetrics", TransactionMetricsMxBeanImpl.class.getSimpleName() ); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, TransactionMetricsMxBean.class, true); } }
/** * Configure workers mx bean. */ private WorkersControlMXBean workersMXBean(int igniteInt) throws Exception { ObjectName mbeanName = U.makeMBeanName( getTestIgniteInstanceName(igniteInt), "Kernal", WorkersControlMXBeanImpl.class.getSimpleName() ); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, WorkersControlMXBean.class, true); } }
/** * Gets CacheGroupMetricsMXBean for given node and group name. * * @param nodeIdx Node index. * @param cacheOrGrpName Cache group name. * @return MBean instance. */ private CacheGroupMetricsMXBean mxBean(int nodeIdx, String cacheOrGrpName) throws MalformedObjectNameException { ObjectName mbeanName = U.makeMBeanName(getTestIgniteInstanceName(nodeIdx), "Cache groups", cacheOrGrpName); MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer(); if (!mbeanSrv.isRegistered(mbeanName)) fail("MBean is not registered: " + mbeanName.getCanonicalName()); return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, CacheGroupMetricsMXBean.class, true); }
@Test public void testRegisterNotificationListenerForAllMBeans() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); JmxTestBean bean = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); NotificationListenerBean listenerBean = new NotificationListenerBean(); listenerBean.setNotificationListener(listener); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean }); start(exporter); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); }
@Test public void testNotificationListenerRegistrarWithMultipleNames() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2"); JmxTestBean bean = new JmxTestBean(); JmxTestBean bean2 = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); beans.put(objectName2.getCanonicalName(), bean2); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); start(exporter); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); NotificationListenerRegistrar registrar = new NotificationListenerRegistrar(); registrar.setServer(server); registrar.setNotificationListener(listener); //registrar.setMappedObjectNames(new Object[] {objectName, objectName2}); registrar.setMappedObjectNames("spring:name=Test", "spring:name=Test2"); registrar.afterPropertiesSet(); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); registrar.destroy(); // try to update the attribute again server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName)); }
@Test public void naming() throws Exception { ObjectNamingStrategy strat = getStrategy(); ObjectName objectName = strat.getObjectName(getManagedResource(), getKey()); assertEquals(objectName.getCanonicalName(), getCorrectObjectName()); }
beans.put(objectName.getCanonicalName(), bean);
@Test public void testNotificationListenerRegistrar() throws Exception { ObjectName objectName = ObjectName.getInstance("spring:name=Test"); JmxTestBean bean = new JmxTestBean(); Map<String, Object> beans = new HashMap<>(); beans.put(objectName.getCanonicalName(), bean); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(server); exporter.setBeans(beans); start(exporter); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); NotificationListenerRegistrar registrar = new NotificationListenerRegistrar(); registrar.setServer(server); registrar.setNotificationListener(listener); registrar.setMappedObjectName(objectName); registrar.afterPropertiesSet(); // update the attribute String attributeName = "Name"; server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener not notified", 1, listener.getCount(attributeName)); registrar.destroy(); // try to update the attribute again server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop")); assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName)); }