modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
| 7 +++-
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/measurement/MeasurementCollectorRunnable.java
| 15 ++++++++--
modules/core/plugin-container/src/test/java/org/rhq/core/pc/CollectorThreadPoolTest.java
| 13 ++++----
3 files changed, 24 insertions(+), 11 deletions(-)
New commits:
commit 5f142aeb194d9c2f4c7a3a7313a01aa6105d9876
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Jun 26 15:42:25 2012 -0400
[BZ 783603] fix the test that was failing. also add an additional configurable
"initialDelay" setting so you can tell the runnable if it should delay
performing the initial collection and if so how long that delay should be
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
index dfc9b06..7af868d 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
@@ -524,11 +524,14 @@ public class ResourceContext<T extends
ResourceComponent<?>> {
/**
* Under certain circumstances, a resource component may want to perform asynchronous
measurement reporting.
+ * Call this to obtain a runnable object that can be used to collect measurements
asynchronously.
*
* @see #createAvailabilityCollectorRunnable(AvailabilityFacet, long)
*/
- public MeasurementCollectorRunnable
createMeasurementCollectorRunnable(MeasurementFacet facet, long interval) {
- return new MeasurementCollectorRunnable(facet, interval,
Thread.currentThread().getContextClassLoader(), this.collectionThreadPool);
+ public MeasurementCollectorRunnable
createMeasurementCollectorRunnable(MeasurementFacet facet, long initialDelay,
+ long interval) {
+ return new MeasurementCollectorRunnable(facet, initialDelay, interval,
Thread.currentThread()
+ .getContextClassLoader(), this.collectionThreadPool);
}
/**
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/measurement/MeasurementCollectorRunnable.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/measurement/MeasurementCollectorRunnable.java
index 79a8531..19bcc9c 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/measurement/MeasurementCollectorRunnable.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/measurement/MeasurementCollectorRunnable.java
@@ -74,6 +74,13 @@ public class MeasurementCollectorRunnable implements Runnable {
private final long interval;
/**
+ * The time, in milliseconds, that this collector wait before performing the first,
initial collection.
+ * Once this initial delay expires, and the initial collection is performed, the
{@link #interval} period
+ * must then expire before the next collection is performed.
+ */
+ private final long initialDelay;
+
+ /**
* The last known measurements for the resource that this collector is monitoring.
*/
private MeasurementReport lastReport = new MeasurementReport();
@@ -93,14 +100,15 @@ public class MeasurementCollectorRunnable implements Runnable {
* Creates a collector instance that will perform measurement reporting for a
particular managed resource.
*
* The interval is the time, in milliseconds, this collector will wait between
reports.
- * A typically value should be something around 30 minutes.
+ * A typically value should be something around 30 minutes, but its minium allowed
value is 60 seconds.
*
* @param measured the object that is used to periodically check the managed resource
(must not be <code>null</code>)
+ * @param interval the initial delay, in millis, before the first collection is
performed.
* @param interval the interval, in millis, between measurement collections
* @param contextClassloader the context classloader that will be used when
collection measurements
* @param threadPool the thread pool to be used to submit this runnable when it needs
to start
*/
- public MeasurementCollectorRunnable(MeasurementFacet measured, long interval,
+ public MeasurementCollectorRunnable(MeasurementFacet measured, long initialDelay,
long interval,
ClassLoader contextClassloader, ScheduledExecutorService threadPool) {
if (measured == null) {
@@ -122,6 +130,7 @@ public class MeasurementCollectorRunnable implements Runnable {
this.measured = measured;
this.contextClassloader = contextClassloader;
+ this.initialDelay = initialDelay;
this.interval = interval;
this.threadPool = threadPool;
this.lastReport = new MeasurementReport();
@@ -148,7 +157,7 @@ public class MeasurementCollectorRunnable implements Runnable {
boolean isStarted = this.started.getAndSet(true);
if (!isStarted) {
task.cancel(true);
- task = threadPool.scheduleWithFixedDelay(this, 0, interval,
TimeUnit.MILLISECONDS);
+ task = threadPool.scheduleWithFixedDelay(this, initialDelay, interval,
TimeUnit.MILLISECONDS);
log.debug("measurement collector started: " + this.facetId);
}
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/CollectorThreadPoolTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/CollectorThreadPoolTest.java
index 91e699e..dc00bee 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/CollectorThreadPoolTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/CollectorThreadPoolTest.java
@@ -25,18 +25,17 @@ package org.rhq.core.pc;
import java.util.HashSet;
import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementDataTrait;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pc.CollectorThreadPool;
import org.rhq.core.pluginapi.availability.AvailabilityCollectorRunnable;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
import org.rhq.core.pluginapi.measurement.MeasurementCollectorRunnable;
@@ -92,9 +91,9 @@ public class CollectorThreadPoolTest {
public void testMeasurement() throws Exception {
log("testMeasurement");
TestMeasumentFacet component = new TestMeasumentFacet();
- MeasurementCollectorRunnable runnable = new
MeasurementCollectorRunnable(component, 500L, null,
+ // 0L means do the initial collection immediately with no delay - so our test can
run fast
+ MeasurementCollectorRunnable runnable = new
MeasurementCollectorRunnable(component, 0L, 500L, null,
this.threadPool.getExecutor());
- runnable.start();
Set<MeasurementScheduleRequest> metrics = new HashSet();
metrics.add(new MeasurementScheduleRequest(0, "name", 0, true,
DataType.TRAIT));
MeasurementReport report = new MeasurementReport();
@@ -102,8 +101,10 @@ public class CollectorThreadPoolTest {
assert 0 == report.getCollectionTime();
assert report.getTraitData().isEmpty();
+ runnable.start();
+
log("sleeping");
- Thread.sleep(1000L);
+ Thread.sleep(1000L); // just give it some time to do its thing
report = new MeasurementReport();
runnable.getLastValues(report, metrics);