Java Code Examples for javax.management.MBeanServer#getDefaultDomain()
The following examples show how to use
javax.management.MBeanServer#getDefaultDomain() .
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: MBeans.java From javamelody with Apache License 2.0 | 6 votes |
public static List<MBeanNode> getAllMBeanNodes() throws JMException { initJRockitMBeansIfNeeded(); final List<MBeanNode> result = new ArrayList<MBeanNode>(); final MBeanServer platformMBeanServer = getPlatformMBeanServer(); final MBeanNode platformNode = new MBeanNode(""); // MBeans pour la plateforme final MBeans platformMBeans = new MBeans(); platformNode.getChildren().addAll(platformMBeans.getMBeanNodes()); result.add(platformNode); // pour JBoss 5.0.x, les MBeans de JBoss sont dans un autre MBeanServer for (final MBeanServer mbeanServer : getMBeanServers()) { if (!mbeanServer.equals(platformMBeanServer)) { final MBeanNode node = new MBeanNode(mbeanServer.getDefaultDomain()); final MBeans mbeans = new MBeans(mbeanServer); node.getChildren().addAll(mbeans.getMBeanNodes()); result.add(node); } } return result; }
Example 2
Source File: ThreadPoolTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 3
Source File: StartStopTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { int nTasks = maxPoolSize + 2; ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); } for (int j = 0; j < 2; j++) { echo(">>> Start MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].start(); echo(">>> MONITORS started"); doSleep(500); echo(">>> Check FLAGS true"); for (int i = 0; i < nTasks; i++) if (!monitored[i].called) { echo("KO: At least one attribute was not called"); return 1; } echo(">>> FLAGS checked true"); echo(">>> Stop MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].stop(); echo(">>> MONITORS stopped"); doSleep(500); echo(">>> Set FLAGS to false"); for (int i = 0; i < nTasks; i++) monitored[i].called = false; echo(">>> FLAGS set to false"); echo(">>> Check FLAGS remain false"); for (int i = 0; i < nTasks; i++) if (monitored[i].called) { echo("KO: At least one attribute " + "continued to get called"); return 1; } echo(">>> FLAGS checked false"); } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } return 0; }
Example 4
Source File: CounterMonitorThresholdTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 5
Source File: ThreadPoolTest.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 6
Source File: StartStopTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { int nTasks = maxPoolSize + 2; ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); } for (int j = 0; j < 2; j++) { echo(">>> Start MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].start(); echo(">>> MONITORS started"); doSleep(500); echo(">>> Check FLAGS true"); for (int i = 0; i < nTasks; i++) if (!monitored[i].called) { echo("KO: At least one attribute was not called"); return 1; } echo(">>> FLAGS checked true"); echo(">>> Stop MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].stop(); echo(">>> MONITORS stopped"); doSleep(500); echo(">>> Set FLAGS to false"); for (int i = 0; i < nTasks; i++) monitored[i].called = false; echo(">>> FLAGS set to false"); echo(">>> Check FLAGS remain false"); for (int i = 0; i < nTasks; i++) if (monitored[i].called) { echo("KO: At least one attribute " + "continued to get called"); return 1; } echo(">>> FLAGS checked false"); } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } return 0; }
Example 7
Source File: CounterMonitorThresholdTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 8
Source File: ThreadPoolTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 9
Source File: ThreadPoolTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 10
Source File: CounterMonitorThresholdTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 11
Source File: CounterMonitorThresholdTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 12
Source File: StartStopTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { int nTasks = maxPoolSize + 2; ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); } for (int j = 0; j < 2; j++) { echo(">>> Start MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].start(); echo(">>> MONITORS started"); Thread.sleep(500); echo(">>> Check FLAGS true"); for (int i = 0; i < nTasks; i++) if (!monitored[i].called) { echo("KO: At least one attribute was not called"); return 1; } echo(">>> FLAGS checked true"); echo(">>> Stop MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].stop(); echo(">>> MONITORS stopped"); Thread.sleep(500); echo(">>> Set FLAGS to false"); for (int i = 0; i < nTasks; i++) monitored[i].called = false; echo(">>> FLAGS set to false"); echo(">>> Check FLAGS remain false"); for (int i = 0; i < nTasks; i++) if (monitored[i].called) { echo("KO: At least one attribute " + "continued to get called"); return 1; } echo(">>> FLAGS checked false"); } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } return 0; }
Example 13
Source File: ThreadPoolTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 14
Source File: CounterMonitorThresholdTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 15
Source File: ThreadPoolTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 16
Source File: StartStopTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { int nTasks = maxPoolSize + 2; ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); } for (int j = 0; j < 2; j++) { echo(">>> Start MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].start(); echo(">>> MONITORS started"); doSleep(500); echo(">>> Check FLAGS true"); for (int i = 0; i < nTasks; i++) if (!monitored[i].called) { echo("KO: At least one attribute was not called"); return 1; } echo(">>> FLAGS checked true"); echo(">>> Stop MONITORS"); for (int i = 0; i < nTasks; i++) monitor[i].stop(); echo(">>> MONITORS stopped"); doSleep(500); echo(">>> Set FLAGS to false"); for (int i = 0; i < nTasks; i++) monitored[i].called = false; echo(">>> FLAGS set to false"); echo(">>> Check FLAGS remain false"); for (int i = 0; i < nTasks; i++) if (monitored[i].called) { echo("KO: At least one attribute " + "continued to get called"); return 1; } echo(">>> FLAGS checked false"); } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } return 0; }
Example 17
Source File: ThreadPoolTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }
Example 18
Source File: CounterMonitorThresholdTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 19
Source File: CounterMonitorThresholdTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void runTest(int offset, int counter[], int derivedGauge[], int threshold[]) throws Exception { // Retrieve the platform MBean server // System.out.println("\nRetrieve the platform MBean server"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String domain = mbs.getDefaultDomain(); // Create and register TestMBean // ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset); mbs.createMBean(Test.class.getName(), name); TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, name, TestMBean.class, false); // Create and register CounterMonitorMBean // ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset); CounterMonitor m = new CounterMonitor(); mbs.registerMBean(m, cmn); CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance( mbs, cmn, CounterMonitorMBean.class, true); ((NotificationEmitter) cm).addNotificationListener( new Listener(), null, null); cm.addObservedObject(name); cm.setObservedAttribute("Counter"); cm.setGranularityPeriod(100); cm.setInitThreshold(1); cm.setOffset(offset); cm.setModulus(5); cm.setNotify(true); // Start the monitor // System.out.println("\nStart monitoring..."); cm.start(); // Play with counter // for (int i = 0; i < counter.length; i++) { mbean.setCounter(counter[i]); System.out.println("\nCounter = " + mbean.getCounter()); Integer derivedGaugeValue; // either pass or test timeout (killed by test harness) // see 8025207 do { Thread.sleep(150); derivedGaugeValue = (Integer) cm.getDerivedGauge(name); } while (derivedGaugeValue.intValue() != derivedGauge[i]); Number thresholdValue = cm.getThreshold(name); System.out.println("Threshold = " + thresholdValue); if (thresholdValue.intValue() != threshold[i]) { System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]); System.out.println("\nStop monitoring..."); cm.stop(); throw new IllegalArgumentException("wrong threshold"); } } // Stop the monitor // System.out.println("\nStop monitoring..."); cm.stop(); }
Example 20
Source File: ThreadPoolTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Run test */ public int runTest(int monitorType) throws Exception { ObjectName[] mbeanNames = new ObjectName[nTasks]; ObservedObject[] monitored = new ObservedObject[nTasks]; ObjectName[] monitorNames = new ObjectName[nTasks]; Monitor[] monitor = new Monitor[nTasks]; String[] attributes = { "Integer", "Double", "String" }; try { echo(">>> CREATE MBeanServer"); MBeanServer server = MBeanServerFactory.newMBeanServer(); String domain = server.getDefaultDomain(); for (int i = 0; i < nTasks; i++) { mbeanNames[i] = new ObjectName(":type=ObservedObject,instance=" + (i + 1)); monitored[i] = new ObservedObject(); echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString()); server.registerMBean(monitored[i], mbeanNames[i]); switch (monitorType) { case 1: monitorNames[i] = new ObjectName(":type=CounterMonitor," + "instance=" + (i + 1)); monitor[i] = new CounterMonitor(); break; case 2: monitorNames[i] = new ObjectName(":type=GaugeMonitor," + "instance=" + (i + 1)); monitor[i] = new GaugeMonitor(); break; case 3: monitorNames[i] = new ObjectName(":type=StringMonitor," + "instance=" + (i + 1)); monitor[i] = new StringMonitor(); break; default: echo("Unsupported monitor type"); return 1; } echo(">>> CREATE Monitor = " + monitorNames[i].toString()); server.registerMBean(monitor[i], monitorNames[i]); monitor[i].addObservedObject(mbeanNames[i]); monitor[i].setObservedAttribute(attributes[monitorType-1]); monitor[i].setGranularityPeriod(50); monitor[i].start(); } if (!waiter.waiting(MAX_WAITING_TIME)) { echo("Error, not all "+nTasks+" monitor tasks are called after " +MAX_WAITING_TIME); return 1; } } finally { for (int i = 0; i < nTasks; i++) if (monitor[i] != null) monitor[i].stop(); } echo("All "+nTasks+" monitors are called."); return 0; }