public void start() throws Exception {
log.info("Reading resource: \"" + this.monitoredObjectsResName + "\"");
// Organise the handle to the subscription definition resource
InputStreamReader in = null;
try {
in = new InputStreamReader(
this.getClass().getResourceAsStream(this.monitoredObjectsResName));
}
catch (Exception e) {
log.error("Accessing resource \"" + this.monitoredObjectsResName + "\"", e);
throw e;
}
// Parse and read-in the resource file
MonitoredObjList monitoredObjList = null;
try {
monitoredObjList = MonitoredObjList.unmarshal(in);
}
catch (Exception e) {
log.error("Parsing resource \"" + this.monitoredObjectsResName + "\"", e);
throw e;
}
log.info("\"" + this.monitoredObjectsResName + "\" " +
(monitoredObjList.isValid() ? "valid" : "invalid") +
". Read " + monitoredObjList.getMonitoredObjCount() +
" monitored objects");
log.info("Executing resource: \"" + this.monitoredObjectsResName + "\"");
// Organise enough space to store the subscribed object names
this.monitoredObjectsCache =
new ArrayList(monitoredObjList.getMonitoredObjCount());
// Iterate over the read monitoredObjects and act upon them
for (int i = 0; i < monitoredObjList.getMonitoredObjCount(); i++) {
// Get monitored object
MonitoredObj s = monitoredObjList.getMonitoredObj(i);
// Get target object name
String targetName = s.getObjectName();
if (log.isDebugEnabled())
log.debug("Object " + i + " target: \"" + targetName + "\"");
// Get event types that are of interest and fill in the notification
// filter
RegExpNotificationFilterSupport filter =
new RegExpNotificationFilterSupport();
for (int j = 0; j < s.getNotificationTypeCount(); j++) {
String eventType = s.getNotificationType(j);
try {
filter.enableType(eventType);
if (log.isDebugEnabled())
log.debug("Event type " + (j+1) + ": \"" + eventType + "\"");
}
catch (REException e) {
log.warn("Error compiling monitored object #" + i +
": Event type \"" + eventType + "\"", e);
}
}
try {
// Subscribe the notification collector to the monitored object
ObjectName targetObjectName = new ObjectName(targetName);
server.addNotificationListener(
targetObjectName,
listener,
filter,
listener.toString());
// Record the object that has been subscribed to
this.monitoredObjectsCache.add(targetObjectName);
}
catch (Exception e) {
log.warn("Error executing monitored object directive #" + i, e);
}
}
log.info("Subscription manager done");
}
Performs service start-up: subscribes the notification collector to all
specified monitored objects. Implicit assumptions regarding
entities from which notification subscriptions are requested:
1. They implement the NotificationBroadcaster interface
2. They are MBeans
* |