package com.novoda.downloadmanager;

import java.util.Timer;
import java.util.TimerTask;

class CallbackThrottleByTime implements CallbackThrottle {

    private final long periodInMillis;

    private static final long DELAY = 0;

    private DownloadBatchStatus downloadBatchStatus;
    private Timer timer;
    private TimerTask timerTask;
    private DownloadBatchCallback callback;

    CallbackThrottleByTime(long periodInMillis) {
        this.periodInMillis = periodInMillis;
    }

    @Override
    public void setCallback(final DownloadBatchCallback callback) {
        this.callback = callback;
        timerTask = new TimerTask() {
            @Override
            public void run() {
                callback.onUpdate(downloadBatchStatus);
            }
        };
    }

    @Override
    public void update(DownloadBatchStatus downloadBatchStatus) {
        if (timerTask == null) {
            return;
        }

        this.downloadBatchStatus = downloadBatchStatus;
        startUpdateIfNecessary();
    }

    private void startUpdateIfNecessary() {
        if (timer == null) {
            timer = new Timer();
            timer.scheduleAtFixedRate(timerTask, DELAY, periodInMillis);
        }
    }

    @Override
    public void stopUpdates() {
        if (callback != null) {
            callback.onUpdate(downloadBatchStatus);
        }

        if (timer != null) {
            timer.cancel();
            timer = null;
        }
    }
}

@@ -147,48 +147,8 @@
  %7B%0A%0A
-    private final long periodInMillis;%0A%0A
     
@@ -178,16 +178,26 @@
 ng DELAY
+_IN_MILLIS
  = 0;%0A%0A 
@@ -306,16 +306,55 @@
 erTask;%0A
+    private final long periodInMillis;%0A
     priv
@@ -1190,16 +1190,26 @@
 k, DELAY
+_IN_MILLIS
 , period

Add time unit to DELAY.