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;
}
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();
}
}
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());
}
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);
}
}
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);
}
}
Aggregations