Example usage for javax.management MBeanServerNotification REGISTRATION_NOTIFICATION

List of usage examples for javax.management MBeanServerNotification REGISTRATION_NOTIFICATION

Introduction

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

Prototype

String REGISTRATION_NOTIFICATION

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

Click Source Link

Document

Notification type denoting that an MBean has been registered.

Usage

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

/**
 * Handles creation and deletion of new "worker" threads.
 *//*from  w w  w.j  a  va 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:org.openspaces.focalserver.FocalServer.java

/**
 * Logs registration events from the local mbeanserver
 *//*w  ww.ja  v a  2  s.  c  om*/
public void handleNotification(Notification notification, Object object) {
    if (notification instanceof MBeanServerNotification) {
        Logger logger = Logger.getLogger(FocalServer.class.getName());
        MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notification;

        if (mBeanServerNotification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            ObjectName beanName = mBeanServerNotification.getMBeanName();
            logger.log(Level.FINE, "Registered:" + beanName);
        } else {
            logger.log(Level.FINE, "Unregistered:" + mBeanServerNotification.getMBeanName());
        }
    }
}

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

public void start() throws IOException {
    MBeanServer server = getMBeanServer();
    if (exposeMBeansAsUPNP.booleanValue()) {
        try {//from   w w w. j a v  a  2  s  .  co  m
            ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
            NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler
                    .newProxyInstance(server, delegate, NotificationEmitter.class, false);
            // register for MBeans registration
            emmiter.addNotificationListener(this, null, this);
        } catch (Exception ex) {
            IOException ioEx = new IOException("UPNPConnector start error");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeUPNPAsMBeans.booleanValue()) {
        int timeout = 2500;
        if (env.containsKey(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)) {
            timeout = ((Integer) env.get(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)).intValue();
        }
        try {
            discoveryBeanName = new ObjectName("UPNPLib discovery:name=Discovery MBean_" + this.hashCode());
            UPNPDiscoveryMBean bean = new UPNPDiscovery(timeout, handleSSDPMessages.booleanValue(), true);
            server.registerMBean(bean, discoveryBeanName);
        } catch (Exception ex) {
            IOException ioEx = new IOException("Error occured during MBeans discovery");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeExistingMBeansAsUPNP.booleanValue()) {
        int c = 0;
        Set objectInstances = super.getMBeanServer().queryNames(null, null);
        for (Iterator i = objectInstances.iterator(); i.hasNext();) {
            ObjectName name = (ObjectName) i.next();
            MBeanServerNotification not = new MBeanServerNotification(
                    MBeanServerNotification.REGISTRATION_NOTIFICATION, this, c++, name);
            handleNotification(not, this);
        }
    }
}

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 {/* www. ja  va  2s  .c  o m*/
            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);
                }/*from   ww  w  .  j a v a2  s. c o  m*/
            }
        } 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  
                    }/*w  w w .j  a v a  2s  .  c o 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.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());
        }//  www . ja v  a  2s. c o 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;/*ww w.jav  a 2s.c  om*/
    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();
    }
}