use of javax.management.NotificationEmitter in project gephi by gephi.
the class MemoryStarvationManager method startup.
public void startup() {
((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
MemoryPoolMXBean biggestHeap = null;
long biggestSize = 0;
for (MemoryPoolMXBean b : mpbeans) {
if (b.getType() == MemoryType.HEAP) {
/* Here we are making the leap of faith that the biggest
* heap is the tenured heap
*/
long size = b.getUsage().getMax();
if (size > biggestSize) {
biggestSize = size;
biggestHeap = b;
}
}
}
if (biggestHeap != null) {
long usageThreshold = (long) (biggestSize - reservedMemory);
biggestHeap.setUsageThreshold(usageThreshold);
biggestHeap.setCollectionUsageThreshold(usageThreshold);
}
}
use of javax.management.NotificationEmitter in project jdk8u_jdk by JetBrains.
the class CounterMonitorInitThresholdTest method runTest.
public static void runTest() 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 TestMBeans
//
ObjectName name1 = new ObjectName(domain + ":type=" + Test.class.getName() + ",name=1");
mbs.createMBean(Test.class.getName(), name1);
TestMBean mbean1 = (TestMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name1, TestMBean.class, false);
ObjectName name2 = new ObjectName(domain + ":type=" + Test.class.getName() + ",name=2");
mbs.createMBean(Test.class.getName(), name2);
TestMBean mbean2 = (TestMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name2, TestMBean.class, false);
// Create and register CounterMonitorMBean
//
ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName());
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.setObservedAttribute("Counter");
cm.setGranularityPeriod(100);
cm.setInitThreshold(3);
cm.setNotify(true);
// Add observed object name1
//
System.out.println("\nObservedObject \"" + name1 + "\" registered before starting the monitor");
cm.addObservedObject(name1);
// Start the monitor
//
System.out.println("\nStart monitoring...");
cm.start();
// Play with counter for name1
//
System.out.println("\nTest ObservedObject \"" + name1 + "\"");
for (int i = 0; i < 4; i++) {
mbean1.setCounter(i);
System.out.println("\nCounter = " + mbean1.getCounter());
Thread.sleep(300);
Number thresholdValue = cm.getThreshold(name1);
System.out.println("Threshold = " + thresholdValue);
if (thresholdValue.intValue() != 3) {
System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = 3");
System.out.println("\nStop monitoring...");
cm.stop();
throw new IllegalArgumentException("wrong threshold");
}
Thread.sleep(300);
}
// Add observed object name2
//
System.out.println("\nObservedObject \"" + name2 + "\" registered after starting the monitor");
cm.addObservedObject(name2);
// Play with counter for name2
//
System.out.println("\nTest ObservedObject \"" + name2 + "\"");
for (int i = 0; i < 4; i++) {
mbean2.setCounter(i);
System.out.println("\nCounter = " + mbean2.getCounter());
Thread.sleep(300);
Number thresholdValue = cm.getThreshold(name2);
System.out.println("Threshold = " + thresholdValue);
if (thresholdValue.intValue() != 3) {
System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = 3");
System.out.println("\nStop monitoring...");
cm.stop();
throw new IllegalArgumentException("wrong threshold");
}
Thread.sleep(300);
}
// Stop the monitor
//
System.out.println("\nStop monitoring...");
cm.stop();
}
use of javax.management.NotificationEmitter in project jdk8u_jdk by JetBrains.
the class CounterMonitorThresholdTest method runTest.
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();
//
for (int i = 0; i < counter.length; i++) {
mbean.setCounter(counter[i]);
System.out.println("\nCounter = " + mbean.getCounter());
Integer derivedGaugeValue;
// 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();
}
use of javax.management.NotificationEmitter in project aries by apache.
the class RegistrableStandardEmitterMBean method getMBeanInfo.
/**
* @see javax.management.StandardMBean#getMBeanInfo()
*/
public MBeanInfo getMBeanInfo() {
MBeanInfo mbeanInfo = super.getMBeanInfo();
if (mbeanInfo != null) {
MBeanNotificationInfo[] notificationInfo;
Object impl = getImplementation();
if (impl instanceof NotificationEmitter) {
notificationInfo = ((NotificationEmitter) (impl)).getNotificationInfo();
} else {
notificationInfo = new MBeanNotificationInfo[0];
}
mbeanInfo = new MBeanInfo(mbeanInfo.getClassName(), mbeanInfo.getDescription(), mbeanInfo.getAttributes(), mbeanInfo.getConstructors(), mbeanInfo.getOperations(), notificationInfo);
}
return mbeanInfo;
}
use of javax.management.NotificationEmitter in project geode by apache.
the class HeapMemoryMonitor method startJVMThresholdListener.
/**
* Register with the JVM to get threshold events.
*
* Package private for testing.
*/
void startJVMThresholdListener() {
final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();
// appropriate value.
if (!testDisableMemoryUpdates) {
memoryPoolMXBean.setCollectionUsageThreshold(1);
}
final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
this.cache.getLoggerI18n().info(LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1, new Object[] { usageThreshold, memoryPoolMXBean.getName() });
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
NotificationEmitter emitter = (NotificationEmitter) mbean;
emitter.addNotificationListener(this, null, null);
}
Aggregations