Fixed delay is easier to reconcile with sleeps than fixed rate.

This commit is contained in:
akwizgran
2020-08-04 10:52:53 +01:00
parent ac80a90ef3
commit f1bde4e75c
5 changed files with 5 additions and 27 deletions

View File

@@ -95,16 +95,6 @@ class AndroidTaskScheduler implements TaskScheduler, Service, AlarmListener {
return s; return s;
} }
@Override
public Future<?> scheduleAtFixedRate(Runnable task, long delay,
long interval, TimeUnit unit) {
Runnable wrapped = () -> {
scheduleAtFixedRate(task, interval, interval, unit);
task.run();
};
return schedule(wrapped, delay, unit);
}
@Override @Override
public Future<?> scheduleWithFixedDelay(Runnable task, long delay, public Future<?> scheduleWithFixedDelay(Runnable task, long delay,
long interval, TimeUnit unit) { long interval, TimeUnit unit) {

View File

@@ -20,12 +20,6 @@ public interface TaskScheduler {
*/ */
Future<?> schedule(Runnable task, long delay, TimeUnit unit); Future<?> schedule(Runnable task, long delay, TimeUnit unit);
/**
* See {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)}.
*/
Future<?> scheduleAtFixedRate(Runnable task, long delay, long interval,
TimeUnit unit);
/** /**
* See {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)}. * See {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)}.
*/ */

View File

@@ -143,7 +143,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
} catch (DbException e) { } catch (DbException e) {
throw new ServiceException(e); throw new ServiceException(e);
} }
scheduler.scheduleAtFixedRate(this::poll, POLLING_INTERVAL_MS, scheduler.scheduleWithFixedDelay(this::poll, POLLING_INTERVAL_MS,
POLLING_INTERVAL_MS, MILLISECONDS); POLLING_INTERVAL_MS, MILLISECONDS);
} }

View File

@@ -28,12 +28,6 @@ class TaskSchedulerImpl implements TaskScheduler {
return delegate.schedule(task, delay, unit); return delegate.schedule(task, delay, unit);
} }
@Override
public Future<?> scheduleAtFixedRate(Runnable task, long delay,
long interval, TimeUnit unit) {
return delegate.scheduleAtFixedRate(task, delay, interval, unit);
}
@Override @Override
public Future<?> scheduleWithFixedDelay(Runnable task, long delay, public Future<?> scheduleWithFixedDelay(Runnable task, long delay,
long interval, TimeUnit unit) { long interval, TimeUnit unit) {

View File

@@ -122,7 +122,7 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
PendingContactStateChangedEvent.class, e -> PendingContactStateChangedEvent.class, e ->
e.getPendingContactState() == OFFLINE))); e.getPendingContactState() == OFFLINE)));
// Capture the poll task // Capture the poll task
oneOf(scheduler).scheduleAtFixedRate(with(any(Runnable.class)), oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS)); with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class, will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
@@ -158,7 +158,7 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
PendingContactStateChangedEvent.class, e -> PendingContactStateChangedEvent.class, e ->
e.getPendingContactState() == FAILED))); e.getPendingContactState() == FAILED)));
// Schedule the poll task // Schedule the poll task
oneOf(scheduler).scheduleAtFixedRate(with(any(Runnable.class)), oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS)); with(MILLISECONDS));
}}); }});
@@ -467,7 +467,7 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
oneOf(db).getPendingContacts(txn); oneOf(db).getPendingContacts(txn);
will(returnValue(emptyList())); will(returnValue(emptyList()));
// Capture the poll task // Capture the poll task
oneOf(scheduler).scheduleAtFixedRate(with(any(Runnable.class)), oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS)); with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class, will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
@@ -544,7 +544,7 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
PendingContactStateChangedEvent.class, e -> PendingContactStateChangedEvent.class, e ->
e.getPendingContactState() == OFFLINE))); e.getPendingContactState() == OFFLINE)));
// Capture the poll task // Capture the poll task
oneOf(scheduler).scheduleAtFixedRate(with(any(Runnable.class)), oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS)); with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class, will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,