Package javax.management

Examples of javax.management.MBeanServerNotification


        try {
            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            NotificationListener jmxlisten = new NotificationListener() {
                @Override
                public void handleNotification(Notification notification, Object handback) {
                    MBeanServerNotification n = (MBeanServerNotification) notification;
                    if (match(pattern, n.getMBeanName())) {
                        if (MBEAN_ADD.equals(n.getType())) {
                            listener.mbeanAdded(n.getMBeanName());
                        }
                        if (MBEAN_DEL.equals(n.getType())) {
                            listener.mbeanRemoved(n.getMBeanName());
                        }
                    }
                }
            };


            listenerName=name;
        }

        public void handleNotification(Notification n,
                                       Object h) {
            MBeanServerNotification mbsn =
                (MBeanServerNotification) n;
            System.out.println(listenerName + " got notification: "
                               + mbsn.getMBeanName());
            synchronized (listenerCount) {
                listenerCount[0]++;
                listenerCount.notify();
            }
        }

        // Check that notification filtering works
        NotificationFilter senderFilter = new NotificationFilter() {
            public boolean isNotificationEnabled(Notification n) {
                if (!(n instanceof MBeanServerNotification))
                    return false;
                MBeanServerNotification mbsn = (MBeanServerNotification) n;
                return (mbsn.getMBeanName().equals(senderName));
            }
        };
        Integer senderListenerId = new Integer(88);
        NotificationBufferFilter senderListenerFilter =
                makeFilter(senderListenerId, wildcardName, senderFilter);
        nr = nb.fetchNotifications(senderListenerFilter, 0, 1000L,
                                   Integer.MAX_VALUE);
        tns = nr.getTargetedNotifications();
        if (tns.length != 1) {
            System.out.println("Expected 1 notif, got: " + Arrays.asList(tns));
            return false;
        }
        MBeanServerNotification mbsn =
            (MBeanServerNotification) tns[0].getNotification();
        if (!mbsn.getMBeanName().equals(senderName)) {
            System.out.println("Expected notif with senderName, got: " +
                               mbsn + " (" + mbsn.getMBeanName() + ")");
            return false;
        }
        System.out.println("Successfully applied NotificationFilter, OK");

        // Now send 8 notifs to fill up our 10-element buffer

                    "Type not selected, exiting");
            return false;
        }

        // We have a MBeanServerNotification: downcasts it
        MBeanServerNotification mbsNtf = (MBeanServerNotification)notif;

        // Checks the ObjectName
        ObjectName objName = mbsNtf.getMBeanName();
        // Is it selected?
        boolean isSelectedFlg = false;
        if (selectedNames != null) {
            // Not all are implicitly selected:
            // checks for explicit selection

        RELATION_LOGGER.entering(RelationService.class.getName(),
                "handleNotification", notif);

        if (notif instanceof MBeanServerNotification) {

            MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
            String ntfType = notif.getType();

            if (ntfType.equals(
                       MBeanServerNotification.UNREGISTRATION_NOTIFICATION )) {
                ObjectName mbeanName =

   
  }
  @Override
  public void handleNotification(Notification notification, Object handback)
  {
    MBeanServerNotification mbs = (MBeanServerNotification) notification;
    if(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      //System.out.println("Adding mbean " + mbs.getMBeanName());
      _logger.info("Adding mbean " + mbs.getMBeanName());
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        addMBean( mbs.getMBeanName());
      }
    }
    else if(MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      //System.out.println("Removing mbean " + mbs.getMBeanName());
      _logger.info("Removing mbean " + mbs.getMBeanName());
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        removeMBean(mbs.getMBeanName());
      }
    }
  }

    _server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, filter, null);
  }
 
  public void handleNotification(Notification notification, Object handback)
  {
    MBeanServerNotification mbs = (MBeanServerNotification) notification;
    if(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        _logger.info("MBean Registered, name :" + mbs.getMBeanName());
        onMBeanRegistered(_server, mbs);
      }
    }
    else if(MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        _logger.info("MBean Unregistered, name :" + mbs.getMBeanName());
        onMBeanUnRegistered(_server, mbs);
      }
    }
  }

/*     */   }
/*     */
/*     */   protected void sendRegistrationNotification(ObjectName regName)
/*     */   {
/* 393 */     long sequence = this.registrationNotificationSequence.increment();
/* 394 */     this.delegate.sendNotification(new MBeanServerNotification("JMX.mbean.registered", this.delegate, sequence, regName));
/*     */   }

/*     */
/*     */   protected void sendUnRegistrationNotification(ObjectName name)
/*     */   {
/* 499 */     long sequence = this.unregistrationNotificationSequence.increment();
/*     */
/* 501 */     this.delegate.sendNotification(new MBeanServerNotification("JMX.mbean.unregistered", this.delegate, sequence, name));
/*     */   }

    _server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, filter, null);
  }
 
  public void handleNotification(Notification notification, Object handback)
  {
    MBeanServerNotification mbs = (MBeanServerNotification) notification;
    if(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        _logger.info("MBean Registered, name :" + mbs.getMBeanName());
        onMBeanRegistered(_server, mbs);
      }
    }
    else if(MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(mbs.getType()))
    {
      if(mbs.getMBeanName().getDomain().equalsIgnoreCase(_domain))
      {
        _logger.info("MBean Unregistered, name :" + mbs.getMBeanName());
        onMBeanUnRegistered(_server, mbs);
      }
    }
  }

TOP

Related Classes of javax.management.MBeanServerNotification

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.