Example usage for javax.management Notification getType

List of usage examples for javax.management Notification getType

Introduction

In this page you can find the example usage for javax.management Notification getType.

Prototype

public String getType() 

Source Link

Document

Get the notification type.

Usage

From source file:org.helios.netty.jmx.ThreadPoolFactory.java

/**
 * {@inheritDoc}//  w ww .  j  av  a 2 s  . c o m
 * @see javax.management.NotificationFilter#isNotificationEnabled(javax.management.Notification)
 */
@Override
public boolean isNotificationEnabled(Notification notification) {
    String notifType = notification.getType();
    return (METRIC_NAME_NOTIFICATION.equals(notifType) && notification.getUserData() instanceof Set)
            || (METRIC_NOTIFICATION.equals(notifType) && notification.getUserData() instanceof JSONObject);
}

From source file:de.iew.spring.integration.JmxTestServiceNotificationListener.java

private String formatNotification(Notification notification) {
    StringBuilder sb = new StringBuilder();
    sb.append("recieved notification class: ").append(notification.getType());
    sb.append(", method: ").append(notification.getSource());
    sb.append(", sequence: ").append(notification.getSequenceNumber());
    sb.append(",  timestamp: ").append(notification.getTimeStamp());
    sb.append(",  data: ");

    Object userData = notification.getUserData();
    String formattedUserData;//from  ww  w.  j a v  a2  s.  co  m
    if (userData == null) {
        formattedUserData = "";
    } else if (userData instanceof String) {
        formattedUserData = StringUtils.arrayToCommaDelimitedString((Object[]) notification.getUserData());
    } else {
        formattedUserData = userData.toString();
    }
    sb.append(formattedUserData);

    return sb.toString();
}

From source file:org.helios.netty.jmx.ThreadPoolFactory.java

/**
 * {@inheritDoc}/*from   w ww.  java2s .  c  o m*/
 * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
 */
@SuppressWarnings("unchecked")
@Override
public void handleNotification(Notification notification, Object handback) {
    String notifType = notification.getType();
    if (METRIC_NAME_NOTIFICATION.equals(notifType)) {
        Set<String> names = (Set<String>) notification.getUserData();
        names.addAll(metricNames);
    } else {
        addMetrics((JSONObject) notification.getUserData());
    }
}

From source file:com.vmware.springsource.hyperic.plugin.gemfire.AlertsPlugin.java

public void handleNotification(Notification notification, Object handback) {
    if (log.isDebugEnabled()) {
        log.debug("[handleNotification] notification.getType() => " + notification.getType());
    }//from ww w. ja v  a2s .c o  m
    if ("gemfire.distributedsystem.alert".equals(notification.getType())) {
        if (log.isDebugEnabled()) {
            log.debug("[handleNotification] notification.getMessage() => " + notification.getMessage().trim());
        }
        Matcher m = msgPatt.matcher(notification.getMessage().trim());
        if (m.find()) {
            try {
                String level = m.group(1);
                Date date = dateFormat.parse(m.group(2));
                String menberID = m.group(4);
                String msg = m.group(5);
                reportEvent(date.getTime(), LOGLEVEL_ERROR, menberID, msg);
            } catch (Exception ex) {
                log.debug("[handleNotification] BAD FORMAT!!!! " + ex.getMessage(), ex);
            }
        } else {
            log.debug("[handleNotification] BAD FORMAT!!!!");
        }
    }
}

From source file:org.rhq.enterprise.gui.startup.ShutdownListener.java

/**
 * This is called when the shutdown notification is received from the JBoss server. This gives a chance for us to
 * cleanly shutdown our application in an orderly fashion.
 *
 * @see javax.management.NotificationListener#handleNotification(Notification, Object)
 *///from   w w w  .java 2 s .c om
public void handleNotification(Notification notification, Object handback) {
    if (org.jboss.system.server.Server.STOP_NOTIFICATION_TYPE.equals(notification.getType())) {
        stopScheduler();

        updateServerOperationMode();

        stopEmbeddedDatabase();
    }
}

From source file:co.paralleluniverse.common.monitoring.PeriodicMonitor.java

@Override
public void handleNotification(Notification notification, Object handback) {
    if ("tickTimer".equals(notification.getType())) {
        //assert Objects.equal(handback, name);
        refresh();/*from   ww  w. j a  v a  2  s.c  o m*/
    }
}

From source file:co.paralleluniverse.common.monitoring.PeriodicMonitor.java

private void registerMBean() {
    try {//from w  ww  .  j av  a 2 s .com
        LOG.info("Registering MBean {}", name);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(name);
        mbs.registerMBean(this, mxbeanName);

        timer.addNotificationListener(this, new NotificationFilter() {
            @Override
            public boolean isNotificationEnabled(Notification notification) {
                return "tickTimer".equals(notification.getType());
            }
        }, null);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        throw new RuntimeException(ex);
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}

From source file:org.josso.gateway.event.security.SpringJMXSSOEventManagerImpl.java

public void handleNotification(Notification notification, Object handback) {

    if (notification instanceof SSOEventNotification) {

        if (logger.isDebugEnabled())
            logger.debug("Received SSO Event Notification  : " + notification.getType());

        if (getListeners().size() < 1) {
            logger.warn("No listeners registered!");
        }/*from   www.  j ava2 s  . co  m*/

        try {

            String eventType = notification.getType();

            for (SSOEventListener l : getListeners()) {

                if (l instanceof SSOConfigurationEventListener) {
                    SSOConfigurationEventListener listener = (SSOConfigurationEventListener) l;
                    if (listener.isEventEnabled(eventType, notification)) {

                        if (logger.isDebugEnabled())
                            logger.debug("Handling notification to configuration listener : " + l);

                        listener.handleEvent(eventType, notification);
                    }
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("Handling notification to listener : " + l);

                    l.handleSSOEvent(((SSOEventNotification) notification).getEvent());
                }
            }

        } catch (Exception e) {
            logger.error("Can't handle notification " + notification + ": \n" + e.getMessage(), e);
        }
    }
}

From source file:de.iew.spring.integration.SpringIntegrationJmxTest.java

@Test
public void testJmxSpringIntegration() throws Exception {
    // Testfix erstellen

    // Test durchfhren
    Map<String, Object> headers = new Hashtable<String, Object>();
    GenericMessage<String> message = new GenericMessage<String>("Foo Bar", headers);
    this.messageChannel.send(message);

    // Test auswerten
    /// Etwas warten, bis die Notifications verschickt wurden
    Thread.sleep(3000);/*from w  ww.java  2s .  c  om*/

    Assert.assertEquals(1, this.springIntegrationTestNotificationListener.getNotifications().size());

    Notification notification = this.springIntegrationTestNotificationListener.getNotifications().get(0);

    Assert.assertEquals(String.class.getName(), notification.getType());
    Assert.assertEquals("Foo Bar", notification.getMessage());
}

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 ww w  . ja v  a  2  s  .  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);
            }
        }
    }
}