Search in sources :

Example 16 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project btrace by btraceio.

the class BTraceRuntime method initMemoryListener.

private void initMemoryListener() {
    initThreadPool();
    memoryListener = new NotificationListener() {

        @Override
        @SuppressWarnings("FutureReturnValueIgnored")
        public void handleNotification(Notification notif, Object handback) {
            boolean entered = BTraceRuntime.enter(BTraceRuntime.this);
            try {
                String notifType = notif.getType();
                if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                    CompositeData cd = (CompositeData) notif.getUserData();
                    final MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
                    String name = info.getPoolName();
                    final LowMemoryHandler handler = lowMemoryHandlerMap.get(name);
                    if (handler != null) {
                        threadPool.submit(new Runnable() {

                            @Override
                            public void run() {
                                boolean entered = BTraceRuntime.enter(BTraceRuntime.this);
                                try {
                                    if (handler.trackUsage) {
                                        handler.invoke(clazz, null, info.getUsage());
                                    } else {
                                        handler.invoke(clazz, null, (Object[]) null);
                                    }
                                } catch (Throwable th) {
                                } finally {
                                    if (entered) {
                                        BTraceRuntime.leave();
                                    }
                                }
                            }
                        });
                    }
                }
            } finally {
                if (entered) {
                    BTraceRuntime.leave();
                }
            }
        }
    };
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) LowMemoryHandler(com.sun.btrace.shared.LowMemoryHandler) Notification(javax.management.Notification) NotificationListener(javax.management.NotificationListener)

Aggregations

MemoryNotificationInfo (java.lang.management.MemoryNotificationInfo)16 MemoryUsage (java.lang.management.MemoryUsage)11 CompositeData (javax.management.openmbean.CompositeData)11 Notification (javax.management.Notification)10 Test (org.testng.annotations.Test)8 MalformedObjectNameException (javax.management.MalformedObjectNameException)7 ObjectName (javax.management.ObjectName)7 IOException (java.io.IOException)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4 MemoryMXBean (java.lang.management.MemoryMXBean)4 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 NotificationEmitter (javax.management.NotificationEmitter)4 ArrayList (java.util.ArrayList)3 MemoryUsageCompositeData (sun.management.MemoryUsageCompositeData)3 LowMemoryHandler (com.sun.btrace.shared.LowMemoryHandler)1 NotificationFilterSupport (javax.management.NotificationFilterSupport)1 NotificationListener (javax.management.NotificationListener)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 BeforeClass (org.testng.annotations.BeforeClass)1