Package javax.management

Examples of javax.management.NotificationEmitter


    public void memoryUsageLow(long usedMemory, long maxMemory);
  }

  private MemoryMonitor() {
    final MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(new NotificationListener() {
      public void handleNotification(Notification n, Object hb) {
        if (n.getType()
            .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
          long maxMemory = tenuredGenPool.getUsage().getMax();
          long usedMemory = tenuredGenPool.getUsage().getUsed();
View Full Code Here


            System.out.println("found node: " + n + n.getId());
            assertTrue(n.isLive());
        }
       
        // Test notifications
        NotificationEmitter notifyProxy = (NotificationEmitter) proxy;
        TestJMXNotificationListener listener =
                new TestJMXNotificationListener();
        notifyProxy.addNotificationListener(listener, null, null);
        // add another node
        SgsTestNode node3 = null;
        try {
            node3 = new SgsTestNode(serverNode, null, null);
            // We expect to see one notification for a started node
            AtomicLong count = listener.notificationMap.get(
                                NodesMXBean.NODE_STARTED_NOTIFICATION);
            assertNotNull(count);
            assertEquals(1, count.longValue());
           
            // and no notifications for failed nodes
            assertNull(listener.notificationMap.get(
                                NodesMXBean.NODE_FAILED_NOTIFICATION));
        } finally {
            if (node3 != null) {
                node3.shutdown(false);
            }
            // Shutdown takes a little while...need to detect that the
            // node is gone
            int renewTime = Integer.valueOf(serverNode.getServiceProperties().
                getProperty(
                "com.sun.sgs.impl.service.watchdog.server.renew.interval"));
            Thread.sleep(renewTime * 2);
            AtomicLong count = listener.notificationMap.get(
                                NodesMXBean.NODE_FAILED_NOTIFICATION);
            assertNotNull(count);
            assertEquals(1, count.longValue());
        }
        notifyProxy.removeNotificationListener(listener);
    }
View Full Code Here

    }

    private void registerMBean(final Object mbean, final Class<?> mbeanInterface, final String name) throws Exception {
        final MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();
        final ObjectName on = new ObjectName(name);
        NotificationEmitter emitter = null;
        if (mbean instanceof AlertMonitor) {
            final AlertMonitor monitor = (AlertMonitor) mbean;
            monitor.setObjectName(on);
            emitter = monitor;
        }
View Full Code Here

    }

    private void registerMBean(final Object mbean, final Class<?> mbeanInterface, final String name) throws Exception {
        final MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();
        final ObjectName on = new ObjectName(name);
        NotificationEmitter emitter = null;
        if (mbean instanceof AlertMonitor) {
            final AlertMonitor monitor = (AlertMonitor) mbean;
            monitor.setObjectName(on);
            emitter = monitor;
        }
View Full Code Here

            throw new ListenerNotFoundException("Unknown listener");

        if (removeAll)
            broadcaster.removeNotificationListener(listenerWrapper);
        else {
            NotificationEmitter emitter = (NotificationEmitter) broadcaster;
            emitter.removeNotificationListener(listenerWrapper,
                                               filter,
                                               handback);
        }
    }
View Full Code Here

            pool.setUsageThreshold(warningThreshold);
          }
        }
       
        MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
        NotificationEmitter emitter = (NotificationEmitter) mbean;
        MemoryNotificationListener listener = new MemoryNotificationListener(types);
        emitter.addNotificationListener(listener, null, cs);
        init=true;
  }
View Full Code Here

    @Override public void setASysMon(ASysMonApi sysMon) {
        this.sysMon = sysMon;

        for (GarbageCollectorMXBean gcbean : ManagementFactory.getGarbageCollectorMXBeans()) {
            final NotificationEmitter emitter = (NotificationEmitter) gcbean;
            emitter.addNotificationListener(listener, null, null);
        }
    }
View Full Code Here

        }
    }

    @Override public void shutdown() throws Exception {
        for (GarbageCollectorMXBean gcbean : ManagementFactory.getGarbageCollectorMXBeans()) {
            final NotificationEmitter emitter = (NotificationEmitter) gcbean;
            try {
                emitter.removeNotificationListener(listener, null, null);
            } catch (ListenerNotFoundException e) { // ignore this to facilitate repeated shutdown
            }
        }
    }
View Full Code Here

        //copied from http://www.fasterj.com/articles/gcnotifs.shtml

        private void registerGarbageCollectionListener() {
            List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
            for (GarbageCollectorMXBean gcbean : gcbeans) {
                NotificationEmitter emitter = (NotificationEmitter) gcbean;

                NotificationListener listener = new NotificationListener() {
                    //keep a count of the total time spent in GCs
                    long totalGcDuration = 0;

                    //implement the notifier callback handler
                    @Override
                    public void handleNotification(Notification notification, Object handback) {
                        if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                            //get the information associated with this notification
                            GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
                            Map<String, MemoryUsage> mem = info.getGcInfo().getMemoryUsageAfterGc();
                            for (Map.Entry<String, MemoryUsage> entry : mem.entrySet()) {
                                String name = entry.getKey();
                                MemoryUsage memoryDetail = entry.getValue();
                                if ("PS Old Gen".equals(name)) {
                                    memoryStatus = findStatus(memoryDetail.getUsed(), memoryDetail.getMax());
                                }
                            }
                            totalGcDuration += info.getGcInfo().getDuration();
                        }
                    }
                };

                //Add the listener
                emitter.addNotificationListener(listener, null, null);
            }
        }
View Full Code Here

    }

    private void registerMBean(final Object mbean, final Class<?> mbeanInterface, final String name) throws Exception {
        final MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();
        final ObjectName on = new ObjectName(name);
        NotificationEmitter emitter = null;
        if (mbean instanceof AlertMonitor) {
            final AlertMonitor monitor = (AlertMonitor) mbean;
            monitor.setObjectName(on);
            emitter = monitor;
        }
View Full Code Here

TOP

Related Classes of javax.management.NotificationEmitter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.