Use the TimeUnit parameter in async monitor

This commit is contained in:
Ignasi Barrera 2012-10-24 18:16:06 +02:00
parent 4e35658940
commit 25bd57379d
2 changed files with 15 additions and 15 deletions

View File

@ -131,7 +131,7 @@ public class BaseMonitoringService implements MonitoringService {
if (objects != null && objects.length > 0) { if (objects != null && objects.length > 0) {
for (T object : objects) { for (T object : objects) {
AsyncMonitor<T> monitor = new AsyncMonitor<T>(object, completeCondition); AsyncMonitor<T> monitor = new AsyncMonitor<T>(object, completeCondition);
monitor.startMonitoring(maxWait); monitor.startMonitoring(maxWait, timeUnit);
} }
} }
} }
@ -208,9 +208,9 @@ public class BaseMonitoringService implements MonitoringService {
* @param maxWait * @param maxWait
* The timeout. * The timeout.
*/ */
public void startMonitoring(final Long maxWait) { public void startMonitoring(final Long maxWait, TimeUnit timeUnit) {
future = scheduler.scheduleWithFixedDelay(this, 0L, pollingDelay, TimeUnit.MILLISECONDS); future = scheduler.scheduleWithFixedDelay(this, 0L, pollingDelay, TimeUnit.MILLISECONDS);
timeout = maxWait == null ? null : System.currentTimeMillis() + maxWait; timeout = maxWait == null ? null : System.currentTimeMillis() + timeUnit.toMillis(maxWait);
logger.debug("started monitor job for %s with %s timeout", monitoredObject, logger.debug("started monitor job for %s with %s timeout", monitoredObject,
timeout == null ? "no" : String.valueOf(timeout)); timeout == null ? "no" : String.valueOf(timeout));
} }

View File

@ -69,7 +69,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -95,7 +95,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(100L); monitor.startMonitoring(100L, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNotNull(monitor.getTimeout()); assertNotNull(monitor.getTimeout());
@ -122,7 +122,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
assertFalse(monitor.isTimeout()); assertFalse(monitor.isTimeout());
@ -148,7 +148,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(60000L); monitor.startMonitoring(60000L, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNotNull(monitor.getTimeout()); assertNotNull(monitor.getTimeout());
assertFalse(monitor.isTimeout()); assertFalse(monitor.isTimeout());
@ -174,7 +174,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(1L); monitor.startMonitoring(1L, TimeUnit.MILLISECONDS);
Thread.sleep(2L); Thread.sleep(2L);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNotNull(monitor.getTimeout()); assertNotNull(monitor.getTimeout());
@ -203,7 +203,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -233,7 +233,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -264,7 +264,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -297,7 +297,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -333,7 +333,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -367,7 +367,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(null); monitor.startMonitoring(null, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
@ -403,7 +403,7 @@ public class AsyncMonitorTest {
assertNull(monitor.getFuture()); assertNull(monitor.getFuture());
assertNull(monitor.getTimeout()); assertNull(monitor.getTimeout());
monitor.startMonitoring(1L); monitor.startMonitoring(1L, TimeUnit.MILLISECONDS);
assertNotNull(monitor.getFuture()); assertNotNull(monitor.getFuture());
assertNotNull(monitor.getTimeout()); assertNotNull(monitor.getTimeout());