use of javax.management.timer.TimerNotification in project camel by apache.
the class SimpleBean method triggerTimerNotification.
public void triggerTimerNotification() {
TimerNotification n = new TimerNotification("timer.notification", this, mSequence++, mTimestamp, "timer-notification", 100);
sendNotification(n);
}
use of javax.management.timer.TimerNotification 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);
}
}
Aggregations