Example usage for javax.management MBeanServerNotification UNREGISTRATION_NOTIFICATION

List of usage examples for javax.management MBeanServerNotification UNREGISTRATION_NOTIFICATION

Introduction

In this page you can find the example usage for javax.management MBeanServerNotification UNREGISTRATION_NOTIFICATION.

Prototype

String UNREGISTRATION_NOTIFICATION

To view the source code for javax.management MBeanServerNotification UNREGISTRATION_NOTIFICATION.

Click Source Link

Document

Notification type denoting that an MBean has been unregistered.

Usage

From source file:com.googlecode.psiprobe.beans.ContainerListenerBean.java

/**
 * Handles creation and deletion of new "worker" threads.
 *///from   w ww  .  ja  v  a 2  s .  c om
public synchronized void handleNotification(Notification notification, Object object) {
    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();

        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {

            if ("RequestProcessor".equals(objectName.getKeyProperty("type"))) {
                ThreadPoolObjectName threadPoolObjectName = findPool(objectName.getKeyProperty("worker"));
                if (threadPoolObjectName != null) {
                    threadPoolObjectName.getRequestProcessorNames().add(objectName);
                }
            }

        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {

            if ("RequestProcessor".equals(objectName.getKeyProperty("type"))) {
                ThreadPoolObjectName threadPoolObjectName = findPool(objectName.getKeyProperty("worker"));
                if (threadPoolObjectName != null) {
                    threadPoolObjectName.getRequestProcessorNames().remove(objectName);
                }
            }
        }
    }
}

From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java

public void handleNotification(Notification notification, Object handBack) {

    if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
        MBeanServerNotification regNot = (MBeanServerNotification) notification;
        MBeanServer srv = getMBeanServer();
        ObjectName name = regNot.getMBeanName();
        try {//from   w ww  . j  a v  a2s . com
            ObjectInstance objIn = srv.getObjectInstance(name);
            String className = objIn.getClassName();
            // do not expose as UPN, UPNP devices exposed as MBeans ( class UPNPServiceMBean purpose )
            if (className.equals(UPNPServiceMBean.class.getName()))
                return;
            if (builder.select(name, className)) {
                MBeanInfo info = srv.getMBeanInfo(name);
                UPNPMBeanDevice dv = builder.buildUPNPMBean(getMBeanServer(), objIn, info);
                if (dv != null) {
                    dv.setBindAddress(sktAddress);
                    dv.start();
                    registeredMBeans.put(name.toString(), dv);
                }
            }
        } catch (Exception ex) {
            log.error("Error during UPNP Mbean device " + name.toString() + " creation", ex);
        }
    } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
        MBeanServerNotification regNot = (MBeanServerNotification) notification;
        String beanName = regNot.getMBeanName().toString();
        synchronized (STOP_PROCESS) {
            UPNPMBeanDevice dv = (UPNPMBeanDevice) registeredMBeans.get(beanName);
            if (dv != null) {
                try {
                    dv.stop();
                } catch (Exception ex) {
                    log.error("Error during UPNPMBean device stop", ex);
                }
                registeredMBeans.remove(beanName);
            }
        }
    }
}

From source file:org.apache.catalina.manager.StatusManagerServlet.java

public void handleNotification(Notification notification, java.lang.Object handback) {

    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();
        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if (type != null) {
                if (type.equals("ProtocolHandler")) {
                    protocolHandlers.addElement(objectName);
                } else if (type.equals("ThreadPool")) {
                    threadPools.addElement(objectName);
                } else if (type.equals("GlobalRequestProcessor")) {
                    globalRequestProcessors.addElement(objectName);
                } else if (type.equals("RequestProcessor")) {
                    requestProcessors.addElement(objectName);
                }/*  w  w w .  j  a  v a 2s  .com*/
            }
        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if (type != null) {
                if (type.equals("ProtocolHandler")) {
                    protocolHandlers.removeElement(objectName);
                } else if (type.equals("ThreadPool")) {
                    threadPools.removeElement(objectName);
                } else if (type.equals("GlobalRequestProcessor")) {
                    globalRequestProcessors.removeElement(objectName);
                } else if (type.equals("RequestProcessor")) {
                    requestProcessors.removeElement(objectName);
                }
            }
            String j2eeType = objectName.getKeyProperty("j2eeType");
            if (j2eeType != null) {

            }
        }
    }

}

From source file:org.apache.coyote.tomcat5.MapperListener.java

public void handleNotification(Notification notification, java.lang.Object handback) {

    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();
        String j2eeType = objectName.getKeyProperty("j2eeType");
        String engineName = null;
        if (j2eeType != null) {
            if ((j2eeType.equals("WebModule")) || (j2eeType.equals("Servlet"))) {
                if (mBeanServer.isRegistered(objectName)) {
                    try {
                        engineName = (String) mBeanServer.getAttribute(objectName, "engineName");
                    } catch (Exception e) {
                        // Ignore  
                    }/*from  w w  w  . j  av  a  2  s .co m*/
                }
            }
        }

        // At deployment time, engineName is always = null.
        if ((!"*".equals(domain)) && (!domain.equals(objectName.getDomain()))
                && ((!domain.equals(engineName)) && (engineName != null))) {
            return;
        }

        log.debug("Handle " + objectName);
        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if ("Host".equals(type)) {
                try {
                    registerHost(objectName);
                } catch (Exception e) {
                    log.warn("Error registering Host " + objectName, e);
                }
            }

            if (j2eeType != null) {
                if (j2eeType.equals("WebModule")) {
                    try {
                        registerContext(objectName);
                    } catch (Throwable t) {
                        log.warn("Error registering Context " + objectName, t);
                    }
                } else if (j2eeType.equals("Servlet")) {
                    try {
                        registerWrapper(objectName);
                    } catch (Throwable t) {
                        log.warn("Error registering Wrapper " + objectName, t);
                    }
                }
            }
        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if ("Host".equals(type)) {
                try {
                    unregisterHost(objectName);
                } catch (Exception e) {
                    log.warn("Error unregistering Host " + objectName, e);
                }
            }

            if (j2eeType != null) {
                if (j2eeType.equals("WebModule")) {
                    try {
                        unregisterContext(objectName);
                    } catch (Throwable t) {
                        log.warn("Error unregistering webapp " + objectName, t);
                    }
                }
            }
        }
    }

}

From source file:org.apache.geode.admin.jmx.internal.MBeanUtil.java

static void registerServerNotificationListener() {
    if (mbeanServer == null) {
        return;//from  w  w w . ja  v a 2  s .c om
    }
    try {
        // the MBeanServerDelegate name is spec'ed as the following...
        ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        mbeanServer.addNotificationListener(delegate, new NotificationListener() {
            public void handleNotification(Notification notification, Object handback) {
                MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
                if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) {
                    ObjectName objectName = serverNotification.getMBeanName();
                    synchronized (MBeanUtil.managedResources) {
                        Object entry = MBeanUtil.managedResources.get(objectName);
                        if (entry == null)
                            return;
                        if (!(entry instanceof ManagedResource)) {
                            throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE
                                    .toLocalizedString(new Object[] { entry.getClass().getName() }));
                        }
                        ManagedResource resource = (ManagedResource) entry;
                        {
                            // call cleanup on managedResource
                            cleanupResource(resource);
                        }
                    }
                }
            }
        }, null, null);
    } catch (JMException e) {
        logStackTrace(Level.WARN, e,
                LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    } catch (JMRuntimeException e) {
        logStackTrace(Level.WARN, e,
                LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    }
}

From source file:org.apache.helix.tools.JmxDumper.java

@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());
        }//from   w w w.  j a  va  2  s . co m
    } 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());
        }
    }
}

From source file:org.mule.providers.jmx.JmxEndpointBuilder.java

private String translateDelegateNotificationType(String typePrefix) {
    if (".registered".equalsIgnoreCase(typePrefix))
        return MBeanServerNotification.REGISTRATION_NOTIFICATION;
    if (".unregistered".equalsIgnoreCase(typePrefix))
        return MBeanServerNotification.UNREGISTRATION_NOTIFICATION;
    return typePrefix;
}

From source file:org.zenoss.jmxnl.NotificationListener.java

public void handleNotification(Notification notification, Object obj) {
    Boolean sendEvent = true;// w w w. j a va2s. co  m
    Boolean reconnect = false;
    String type = notification.getType();

    Map<String, String> evt = new HashMap<String, String>();
    evt.put("device", (String) obj);
    evt.put("severity", "2");
    evt.put("eventClassKey", type);

    if (notification instanceof JMXConnectionNotification) {
        if (type.equals(JMXConnectionNotification.CLOSED)) {
            sendConnectionEvent("4", "JMX connection has been closed");
            reconnect = true;
        } else if (type.equals(JMXConnectionNotification.FAILED)) {
            sendConnectionEvent("4", "JMX connection has failed");
            reconnect = true;
        } else if (type.equals(JMXConnectionNotification.NOTIFS_LOST)) {
            sendConnectionEvent("3", "JMX connection has possibly lost notifications");
        } else if (type.equals(JMXConnectionNotification.OPENED)) {
            sendConnectionEvent("0", "JMX connection has been opened");
        }

        // Event has already been sent
        sendEvent = false;
    } else if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification notif = (AttributeChangeNotification) notification;
        evt.put("component", notif.getAttributeName());
        evt.put("eventKey", notif.getSource().toString() + ":" + notif.getAttributeName());
        evt.put("summary", "Attribute changed from " + notif.getOldValue() + " to " + notif.getNewValue());
    } else if (notification instanceof MBeanServerNotification) {
        MBeanServerNotification notif = (MBeanServerNotification) notification;
        evt.put("severity", "1");
        evt.put("component", notif.getMBeanName().getDomain());
        evt.put("eventKey", notif.getMBeanName().toString());
        if (type.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            evt.put("summary", "MBean Registered");
        } else if (type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            evt.put("summary", "MBean Unregistered");
        } else {
            evt.put("summary", "Unknown MBean Server Notification");
        }

        // These are too noisy and unlikely to be useful
        sendEvent = false;
    } else if (notification instanceof MonitorNotification) {
        MonitorNotification notif = (MonitorNotification) notification;
        evt.put("severity", "3");
        evt.put("component", notif.getObservedObject().toString() + ":" + notif.getObservedAttribute());
        if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR)) {
            evt.put("summary", "Observed attribute not contained within the observed object");
        } else if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR)) {
            evt.put("summary", "Type of the observed attribute is not correct");
        } else if (type.equals(MonitorNotification.OBSERVED_OBJECT_ERROR)) {
            evt.put("summary", "The observed object is not registered in the MBean server");
        } else if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
            evt.put("summary", "Non pre-defined error has occurred");
        } else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED)) {
            evt.put("summary", "Attribute differs from the string to compare");
        } else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED)) {
            evt.put("summary", "Attribute matched the string to compare");
        } else if (type.equals(MonitorNotification.THRESHOLD_ERROR)) {
            evt.put("summary", "Type of threshold is not correct");
        } else if (type.equals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has exceeded the threshold high value");
        } else if (type.equals(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has exceeded the threshold low value");
        } else if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has reached the threshold value");
        } else {
            evt.put("summary", "Unknown Monitor Notification");
        }
    } else if (notification instanceof RelationNotification) {
        RelationNotification notif = (RelationNotification) notification;
        evt.put("component", notif.getRelationId());
        if (type.equals(RelationNotification.RELATION_BASIC_CREATION)) {
            evt.put("summary", "Internal relation created");
        } else if (type.equals(RelationNotification.RELATION_BASIC_REMOVAL)) {
            evt.put("summary", "Internal relation removed");
        } else if (type.equals(RelationNotification.RELATION_BASIC_UPDATE)) {
            evt.put("summary", "Internal relation updated");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_CREATION)) {
            evt.put("summary", "MBean relation created");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_REMOVAL)) {
            evt.put("summary", "MBean relation removed");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_UPDATE)) {
            evt.put("summary", "MBean relation updated");
        }
    } else {
        if (notification.getMessage().equals("")) {
            evt.put("summary", "Unknown JMX Notification Type");
        } else {
            evt.put("summary", notification.getMessage());
        }
    }

    if (sendEvent) {
        try {
            EventSender.getEventSender().sendEvent(evt);
        } catch (XmlRpcException e) {
            log.error("Error sending event: " + e);
        }
    }

    if (reconnect) {
        run();
    }
}