public MeasurementCollectorRunner(MeasurementManager measurementManager) {
this.measurementManager = measurementManager;
}
public MeasurementReport call() {
MeasurementReport report = null;
try {
this.measurementManager.getLock().readLock().lock();
report = this.measurementManager.getActiveReport();
long start = System.currentTimeMillis();
InventoryManager im = this.measurementManager.getInventoryManager();
Set<ScheduledMeasurementInfo> requests = this.measurementManager.getNextScheduledSet();
if (requests != null) {
ScheduledMeasurementInfo next = requests.iterator().next();
if ((System.currentTimeMillis() - 30000L) > next.getNextCollection()) {
this.measurementManager.incrementLateCollections(requests.size());
if (log.isDebugEnabled()) {
log.debug("Measurement collection is falling behind... Missed requested time by ["
+ (System.currentTimeMillis() - requests.iterator().next().getNextCollection()) + "ms]");
if (!scheduleHistory.isEmpty()) {
log.debug("The most recent measurement requests prior to this detected delay: "
+ scheduleHistory);
}
}
// BZ 834019 - reschedule these requests for the future, and away from the set of requests on this schedule
this.measurementManager.rescheduleLateCollections(requests);
return report;
}
Integer resourceId = next.getResourceId();
ResourceContainer container = im.getResourceContainer(resourceId);
if (container.getResourceComponentState() != ResourceContainer.ResourceComponentState.STARTED
|| container.getAvailability() == null
|| container.getAvailability().getAvailabilityType() == AvailabilityType.DOWN) {
// Don't collect metrics for resources that are down
if (log.isDebugEnabled()) {
log.debug("Measurements not collected for inactive resource component: "
+ container.getResource());
}
} else {
MeasurementFacet measurementComponent = ComponentUtil
.getComponent(resourceId, MeasurementFacet.class, FacetLockType.READ,
MeasurementManager.FACET_METHOD_TIMEOUT, true, true, true);
if (log.isDebugEnabled()) {
scheduleHistory.addRequests(requests);
}
getValues(measurementComponent, report, requests, container.getResource());
}
this.measurementManager.reschedule(requests);
report.incrementCollectionTime(System.currentTimeMillis() - start);
}
} catch (Throwable t) {
log.error("Failed to run measurement collection", t);
} finally {
this.measurementManager.getLock().readLock().unlock();