Search in sources :

Example 1 with RelationNotification

use of javax.management.relation.RelationNotification in project camel by apache.

the class SimpleBean method triggerRelationNotification.

public void triggerRelationNotification() throws Exception {
    List<ObjectName> list = new ArrayList<ObjectName>();
    for (int i = 1; i <= 3; i++) {
        list.add(new ObjectName("TestDomain", "name", "mbean-" + i));
    }
    RelationNotification n = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, new ObjectName("TestDomain", "name", "source"), mSequence++, mTimestamp, "relation message", "relation-id", "relation.type", new ObjectName("TestDomain", "name", "foo"), list);
    sendNotification(n);
}
Also used : ArrayList(java.util.ArrayList) RelationNotification(javax.management.relation.RelationNotification) ObjectName(javax.management.ObjectName)

Example 2 with RelationNotification

use of javax.management.relation.RelationNotification 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 3 with RelationNotification

use of javax.management.relation.RelationNotification in project jdk8u_jdk by JetBrains.

the class RelationNotificationSourceTest method main.

public static void main(String[] args) throws Exception {
    ObjectName name1 = new ObjectName("a:n=1");
    ObjectName name2 = new ObjectName("a:n=2");
    ObjectName name = new ObjectName("a:b=c");
    Notification n1 = new RelationNotification(RELATION_BASIC_REMOVAL, name, 1234L, System.currentTimeMillis(), "message", "id", "typeName", name1, Collections.singletonList(name2));
    if (!name.equals(n1.getSource()))
        throw new Exception("FAILED: source is " + n1.getSource());
    Notification n2 = new RelationNotification(RELATION_BASIC_UPDATE, name, 1234L, System.currentTimeMillis(), "message", "id", "typeName", name1, "role", Collections.singletonList(name2), Collections.singletonList(name2));
    if (!name.equals(n2.getSource()))
        throw new Exception("FAILED: source is " + n2.getSource());
    System.out.println("TEST PASSED");
}
Also used : RelationNotification(javax.management.relation.RelationNotification) RelationNotification(javax.management.relation.RelationNotification)

Aggregations

RelationNotification (javax.management.relation.RelationNotification)3 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 AttributeChangeNotification (javax.management.AttributeChangeNotification)1 MBeanServerNotification (javax.management.MBeanServerNotification)1 ObjectName (javax.management.ObjectName)1 MonitorNotification (javax.management.monitor.MonitorNotification)1 JMXConnectionNotification (javax.management.remote.JMXConnectionNotification)1 TimerNotification (javax.management.timer.TimerNotification)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 NotificationEventType (org.apache.camel.component.jmx.jaxb.NotificationEventType)1 ObjectNamesType (org.apache.camel.component.jmx.jaxb.ObjectNamesType)1