Search in sources :

Example 1 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class GaugeMonitor method buildAlarmNotification.

@Override
synchronized MonitorNotification buildAlarmNotification(ObjectName object, String attribute, Comparable<?> value) {
    final GaugeMonitorObservedObject o = (GaugeMonitorObservedObject) getObservedObject(object);
    if (o == null)
        return null;
    // Notify the listeners if the updated derived
    // gauge value is valid.
    //
    final MonitorNotification alarm;
    if (o.getDerivedGaugeValid())
        alarm = updateNotifications(o);
    else
        alarm = null;
    return alarm;
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 2 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project wildfly-swarm by wildfly-swarm.

the class JMXIntegrationTest method testMonitorMBeanAttribute.

@Test
public void testMonitorMBeanAttribute() throws Exception {
    Context context = new InitialContext();
    CamelContextRegistry contextRegistry = (CamelContextRegistry) context.lookup("java:jboss/camel/CamelContextRegistry");
    CamelContext sysctx = contextRegistry.getCamelContext("camel-1");
    Assert.assertEquals(ServiceStatus.Started, sysctx.getStatus());
    final String routeName = sysctx.getRoutes().get(0).getId();
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jmx:platform?format=raw&objectDomain=org.apache.camel&key.context=camel-1&key.type=routes&key.name=\"" + routeName + "\"" + "&monitorType=counter&observedAttribute=ExchangesTotal&granularityPeriod=500").to("direct:end");
        }
    });
    camelctx.start();
    try {
        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        MonitorNotification notifcation = consumer.receiveBody("direct:end", MonitorNotification.class);
        Assert.assertEquals("ExchangesTotal", notifcation.getObservedAttribute());
    } finally {
        camelctx.stop();
    }
}
Also used : InitialContext(javax.naming.InitialContext) CamelContext(org.apache.camel.CamelContext) Context(javax.naming.Context) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ConsumerTemplate(org.apache.camel.ConsumerTemplate) MonitorNotification(javax.management.monitor.MonitorNotification) RouteBuilder(org.apache.camel.builder.RouteBuilder) InitialContext(javax.naming.InitialContext) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project Payara by payara.

the class MonitorNotificationStringifier method stringify.

@Override
public String stringify(Object o) {
    final MonitorNotification notif = (MonitorNotification) o;
    final StringBuilder b = super._stringify(notif);
    append(b, "");
    append(b, "Observed object: " + notif.getObservedObject());
    append(b, "Observed attribute: " + notif.getObservedAttribute());
    append(b, "Trigger: " + notif.getTrigger());
    append(b, "Gauge: " + notif.getDerivedGauge());
    return (b.toString());
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 4 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project camel by apache.

the class NotificationXmlFormatter method format.

public String format(Notification aNotification) throws NotificationFormatException {
    ObjectHelper.notNull(jaxbContext, "jaxbContext");
    NotificationEventType jaxb;
    boolean wrap = false;
    if (aNotification instanceof AttributeChangeNotification) {
        AttributeChangeNotification ac = (AttributeChangeNotification) aNotification;
        jaxb = mObjectFactory.createAttributeChangeNotification().withAttributeName(ac.getAttributeName()).withAttributeType(ac.getAttributeType()).withNewValue(ac.getNewValue() == null ? null : String.valueOf(ac.getNewValue())).withOldValue(ac.getOldValue() == null ? null : String.valueOf(ac.getOldValue()));
    } else if (aNotification instanceof JMXConnectionNotification) {
        jaxb = mObjectFactory.createJMXConnectionNotification().withConnectionId(((JMXConnectionNotification) aNotification).getConnectionId());
    } else if (aNotification instanceof MBeanServerNotification) {
        jaxb = mObjectFactory.createMBeanServerNotification().withMBeanName(String.valueOf(((MBeanServerNotification) aNotification).getMBeanName()));
    } else if (aNotification instanceof MonitorNotification) {
        MonitorNotification mn = (MonitorNotification) aNotification;
        jaxb = mObjectFactory.createMonitorNotification().withDerivedGauge(String.valueOf(mn.getDerivedGauge())).withObservedAttribute(mn.getObservedAttribute()).withObservedObject(String.valueOf(mn.getObservedObject())).withTrigger(String.valueOf(mn.getTrigger()));
    } else if (aNotification instanceof RelationNotification) {
        RelationNotification rn = (RelationNotification) aNotification;
        jaxb = mObjectFactory.createRelationNotification().withObjectName(String.valueOf(rn.getObjectName())).withRelationId(rn.getRelationId()).withRelationTypeName(rn.getRelationTypeName()).withRoleName(rn.getRoleName());
        if (rn.getNewRoleValue() != null) {
            ObjectNamesType ont = toObjectNamesType(rn.getNewRoleValue());
            ((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withNewRoleValue(ont);
        }
        if (rn.getOldRoleValue() != null) {
            ObjectNamesType ont = toObjectNamesType(rn.getOldRoleValue());
            ((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withOldRoleValue(ont);
        }
        if (rn.getMBeansToUnregister() != null) {
            ObjectNamesType ont = toObjectNamesType(rn.getMBeansToUnregister());
            ((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withMBeansToUnregister(ont);
        }
    } else if (aNotification instanceof TimerNotification) {
        jaxb = mObjectFactory.createTimerNotification().withNotificationId(((TimerNotification) aNotification).getNotificationID());
    } else {
        jaxb = mObjectFactory.createNotificationEventType();
        wrap = true;
    }
    // add all of the common properties
    jaxb.withMessage(aNotification.getMessage()).withSequence(aNotification.getSequenceNumber()).withSource(String.valueOf(aNotification.getSource())).withTimestamp(aNotification.getTimeStamp()).withType(aNotification.getType());
    if (aNotification.getUserData() != null) {
        jaxb.withUserData(String.valueOf(aNotification.getUserData()));
    }
    try {
        DatatypeFactory df = getDatatypeFactory();
        Date date = new Date(aNotification.getTimeStamp());
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        jaxb.withDateTime(df.newXMLGregorianCalendar(gc));
        Object bean = wrap ? mObjectFactory.createNotificationEvent(jaxb) : jaxb;
        StringWriter sw = new StringWriter();
        // must create a new marshaller as its not thread safe
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(bean, sw);
        return sw.toString();
    } catch (JAXBException e) {
        throw new NotificationFormatException(e);
    } catch (DatatypeConfigurationException e) {
        throw new NotificationFormatException(e);
    }
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification) Marshaller(javax.xml.bind.Marshaller) AttributeChangeNotification(javax.management.AttributeChangeNotification) DatatypeFactory(javax.xml.datatype.DatatypeFactory) MBeanServerNotification(javax.management.MBeanServerNotification) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) RelationNotification(javax.management.relation.RelationNotification) TimerNotification(javax.management.timer.TimerNotification) Date(java.util.Date) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) StringWriter(java.io.StringWriter) NotificationEventType(org.apache.camel.component.jmx.jaxb.NotificationEventType) ObjectNamesType(org.apache.camel.component.jmx.jaxb.ObjectNamesType) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification)

Example 5 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class AttributeArbitraryDataTypeTest method handleNotification.

// Notification handler
public void handleNotification(Notification notification, Object handback) {
    MonitorNotification n = (MonitorNotification) notification;
    echo("\tInside handleNotification...");
    String type = n.getType();
    try {
        if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
            echo("\t\t" + n.getObservedAttribute() + " has reached or exceeded the threshold");
            echo("\t\tDerived Gauge = " + n.getDerivedGauge());
            echo("\t\tTrigger = " + n.getTrigger());
            synchronized (this) {
                counterMessageReceived = true;
                notifyAll();
            }
        } else if (type.equals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED)) {
            echo("\t\t" + n.getObservedAttribute() + " has reached or exceeded the high threshold");
            echo("\t\tDerived Gauge = " + n.getDerivedGauge());
            echo("\t\tTrigger = " + n.getTrigger());
            synchronized (this) {
                gaugeMessageReceived = true;
                notifyAll();
            }
        } else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED)) {
            echo("\t\t" + n.getObservedAttribute() + " matches the string-to-compare value");
            echo("\t\tDerived Gauge = " + n.getDerivedGauge());
            echo("\t\tTrigger = " + n.getTrigger());
            synchronized (this) {
                stringMessageReceived = true;
                notifyAll();
            }
        } else {
            echo("\t\tSkipping notification of type: " + type);
        }
    } catch (Exception e) {
        echo("\tError in handleNotification!");
        e.printStackTrace(System.out);
    }
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification) OpenDataException(javax.management.openmbean.OpenDataException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

MonitorNotification (javax.management.monitor.MonitorNotification)12 AttributeNotFoundException (javax.management.AttributeNotFoundException)2 CamelContext (org.apache.camel.CamelContext)2 ConsumerTemplate (org.apache.camel.ConsumerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 IntrospectionException (java.beans.IntrospectionException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 AttributeChangeNotification (javax.management.AttributeChangeNotification)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanException (javax.management.MBeanException)1 MBeanServerNotification (javax.management.MBeanServerNotification)1 ObjectName (javax.management.ObjectName)1 ReflectionException (javax.management.ReflectionException)1 OpenDataException (javax.management.openmbean.OpenDataException)1